Last active
November 25, 2016 18:23
-
-
Save 5outh/5490833 to your computer and use it in GitHub Desktop.
mapVar and plugIn functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't the type signature of
mapVar
be(Char -> Expr a) -> Expr a -> Expr a
instead of(Char -> Expr a) => Expr a -> Expr a
?