Skip to content

Commit 716e9f9

Browse files
committed
Move over test from compiler repo
1 parent a45e639 commit 716e9f9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/Tree.purs.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Main where
2+
3+
import Prelude
4+
import Data.Foldable
5+
import Data.Monoid
6+
7+
data Tree a = Node a | Branch (Tree a) (Tree a)
8+
9+
instance foldableTree :: Foldable Tree where
10+
foldr f z (Node x) = x `f` z
11+
foldr f z (Branch l r) = foldr f (foldr f z r) l
12+
13+
foldl f z (Node x) = z `f` x
14+
foldl f z (Branch l r) = foldl f (foldl f z l) r
15+
16+
foldMap f (Node x) = f x
17+
foldMap f (Branch l r) = foldMap f l <> foldMap f r
18+
19+
main = Debug.Trace.print <<< sum $ Branch (Node 1) (Branch (Node 2) (Node 3))

0 commit comments

Comments
 (0)