Skip to content

Instantly share code, notes, and snippets.

@atondwal
Created December 24, 2018 23:24
Show Gist options
  • Save atondwal/239c237a910625d444e6d960fb0c6277 to your computer and use it in GitHub Desktop.
Save atondwal/239c237a910625d444e6d960fb0c6277 to your computer and use it in GitHub Desktop.
{-# 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