Created
December 24, 2018 23:24
-
-
Save atondwal/239c237a910625d444e6d960fb0c6277 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE TypeFamilies, DeriveFunctor #-} | |
module Expr where | |
import Data.Functor.Foldable | |
data ExprF a | |
= ConstF Double | |
| AddF a a | |
| SubF a a | |
| MulF a a | |
| DivF a a | |
| NegF a | |
deriving Functor | |
data Expr = Const Double | |
| Add Expr Expr | |
| Sub Expr Expr | |
| Mul Expr Expr | |
| Div Expr Expr | |
| Neg Expr | |
type instance Base Expr = ExprF | |
instance Recursive Expr where | |
project (Const d) = ConstF d | |
project (Add e1 e2) = AddF e1 e2 | |
project (Sub e1 e2) = SubF e1 e2 | |
project (Mul e1 e2) = MulF e1 e2 | |
project (Div e1 e2) = DivF e1 e2 | |
project (Neg e) = NegF e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment