Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created October 25, 2019 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/5917646e3bd39766bf10e10b9c59f82c to your computer and use it in GitHub Desktop.
Save tonymorris/5917646e3bd39766bf10e10b9c59f82c to your computer and use it in GitHub Desktop.
import Data.Foldable
data X' =
A
| B
| C
| Z
deriving (Eq, Show)
data X =
Val X' | Add X X
deriving (Eq, Show)
list (Val x) = [x]
list (Add x1 x2) = list x1 ++ list x2
o = Add
a = Val A
b = Val B
c = Val C
z = Val Z
l = foldl' o z [a, b, c]
r = foldr o c [z, a, b]
l' = list l
r' = list r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment