We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a45e639 commit 716e9f9Copy full SHA for 716e9f9
examples/Tree.purs.hs
@@ -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