5 Jun
2003
5 Jun
'03
5:43 a.m.
Rather than using fmap, why not use gmap in GHC. Using an appropriate generic traversal scheme, say listify, all the code you write is the following expression:
listify (const True) mytree :: [Int]
if you are looking for all the Ints in mytree = Fork (Leaf 42) (Fork (Leaf 88) (Leaf 37)) So this would give you [42,88,37].
What happens if the tree contains additional integers to record, say, balancing information. The information a functor provides is vital here. Take as the simplest example newtype Weighted a = WithWeight (Int, a) Without the functor definition there is no way to distinguish the two Ints in Weighted Int. Cheers, Ralf