User avatar
pathetic piss kitten @kitten@elizabeth.cat
5mo
what was the way to count the number of nodes in this kind of structure?
3
0
0
0
User avatar
Daphne Preston-Kendal @dpk@chaos.social
5mo
@kitten

data Tree a = Leaf | Node (Tree a) a (Tree a) -- left, value, right

count (Node l _ r) = 1 + count l + count r
count Leaf = 0 -- or 1 if leaves count as a node
1
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
5mo
@dpk what language is this ​:blobCat_eyes:​
1
0
0
0

User avatar
Daphne Preston-Kendal @dpk@chaos.social
5mo
@kitten Haskell
0
0
1
0