[Haskell-cafe] Troubles with Exercise 4.9 from YAHT
michael at schmong.org
michael at schmong.org
Sat Jul 14 19:33:30 EDT 2007
from YAHT
Exercise 4.9 Write a function elements which returns the elements in a
BinaryTree
in a bottom-up, left-to-right manner (i.e., the ���rst element
returned in the left-most leaf,
followed by its parent���s value, followed by the other
child���s value, and so on). The re-
sult type should be a normal Haskell list.
here's the data type BinaryTree
data BinaryTree a
= Leaf a
| Branch (BinaryTree a) a (BinaryTree a)
Here's my first attempt
nodeCount :: BinaryTree a -> [b]
nodeCount = map putStrLn (show a)
a is out scope.
I started looking at what types putStrLn and map are.
First thing that occurs to me is that I can't use map unless I
pass it a list.
I'm not allow to use fold yet, that's the next assignment.
Any clues on how to proceed?
More information about the Haskell-Cafe
mailing list