Created
February 15, 2014 21:51
-
-
Save patrickt/9025675 to your computer and use it in GitHub Desktop.
This file contains 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
-- given a function f from a's to b's, `apply f` is a function that turns Expr a's into Expr b's | |
-- by mapping its argument over each subexpression of type a. | |
apply :: (a -> b) -> Expr a -> Expr b | |
-- The Constant constructor has no eligible subexpressions, so apply does nothing. | |
apply f (Constant ident) = (Constant ident) | |
-- Indexes have two children of type a; apply f to both of them. | |
apply f (Index x y) = Index (f x) (f y) | |
-- Calls have a list of arguments, so we map `apply f` over it | |
apply f (Call name args) = Call (f name) (map f args) | |
-- et cetera, et cetera |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment