Skip to content

Instantly share code, notes, and snippets.

@markflorisson
Last active August 29, 2015 14:15
Show Gist options
  • Save markflorisson/76c39530d238dd2b627c to your computer and use it in GitHub Desktop.
Save markflorisson/76c39530d238dd2b627c to your computer and use it in GitHub Desktop.
Staging without quotation
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