Skip to content

Instantly share code, notes, and snippets.

@5outh
Last active November 25, 2016 18:23
Show Gist options
  • Save 5outh/5490833 to your computer and use it in GitHub Desktop.
Save 5outh/5490833 to your computer and use it in GitHub Desktop.
mapVar and plugIn functions
mapVar :: (Char -> Expr a) => Expr a -> Expr a
mapVar f (Var d) = f d
mapVar _ (Const a) = Const a
mapVar f (a :+: b) = (mapVar f a) :+: (mapVar f b)
mapVar f (a :*: b) = (mapVar f a) :*: (mapVar f b)
mapVar f (a :^: b) = (mapVar f a) :^: (mapVar f b)
mapVar f (a :/: b) = (mapVar f a) :/: (mapVar f b)
plugIn :: Char -> a -> Expr a -> Expr a
plugIn c val = mapVar (\x -> if x == c then Const val else Var x)
@TimoWilken
Copy link

Shouldn't the type signature of mapVar be (Char -> Expr a) -> Expr a -> Expr a instead of (Char -> Expr a) => Expr a -> Expr a?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment