I'm quite new to Haskell and therefore not very familiar with it.
The following method is to measure the size of a MultTree
.
A MultTree
includes Index
nodes that contain two Int
's and can have an arbitrary amount of children. Then there's also Data
nodes that contain one Int
and can have no children. So what the method should determine is, how long the longest 'branch' is.
My approach so far:
data MultTree a = Index a a [MultTree a] | Data a deriving Show
size :: MultTree a -> Int
size (Index a b []) = 1
size (Index a b [Index c d [e]]) = size (Index c d [e]) + 1
It does compile, but when trying to use it, I get "non-exhaustive patterns in function size"
. Even if I wouldn't get that error, I know it wouldn't work the way I wanted it to work.
But somehow I can't come up with a solution to the problem.
I would appreciate every kind of help.
Thank you already in advance!