Last active
August 29, 2015 14:15
-
-
Save markflorisson/76c39530d238dd2b627c to your computer and use it in GitHub Desktop.
Staging without quotation
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
import Control.Applicative | |
-- NOTE: in a lazy language we only need 'data Expr a = Expr a' | |
data Expr a = Expr (() -> a) | |
instance Functor Expr where | |
fmap f e = Expr $ λ() -> f (eval e) | |
instance Applicative Expr where | |
pure x = Expr $ λ() -> x | |
f <*> x = Expr $ λ() -> (eval f) (eval x) | |
eval :: Expr a -> a | |
eval (Expr e) = e () | |
main = do | |
putStrLn $ show $ eval $ (+) <$> pure 3 <*> pure 4 | |
putStrLn $ show $ eval $ pure (λx -> x + x) <*> pure 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment