Skip to content

Instantly share code, notes, and snippets.

@5outh
Last active December 16, 2015 20:10
Show Gist options
  • Save 5outh/5490816 to your computer and use it in GitHub Desktop.
Save 5outh/5490816 to your computer and use it in GitHub Desktop.
negate function for Exprs
negate' :: (Num a) => Expr a -> Expr a
negate' (Var c) = (Const (-1)) :*: (Var c)
negate' (Const a) = Const (-a)
negate' (a :+: b) = (negate' a) :+: (negate' b)
negate' (a :*: b) = (negate' a) :*: b
negate' (a :^: b) = Const (-1) :*: a :^: b
negate' (a :/: b) = (negate' a) :/: b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment