[Haskell-beginners] Help with RWH exercises wanted

Alan Cameron alan.cameron at iname.com
Thu Feb 12 10:19:40 EST 2009


I am baffled by what the correct solution to the exercises in Recursive type
section of Chapter 3 should be.
<Quote>
1. Write the converse of fromList for the List type: a function that takes a
List a and generates a [a].
 
2. Define a tree type that has only one constructor, like our Java example.
Instead of the Empty constructor, use the Maybe type to refer to a node's
children. 
</Quote> 

fromList is defined in listADT.hs thus

-- file: ch03/ListADT.hs
fromList (x:xs) = Cons x (fromList xs)
fromList []     = Nil

Tree is defined in Tree.hs thus

-- file: ch03/Tree.hs
data Tree a = Node a (Tree a) (Tree a)
            | Empty
              deriving (Show)

At this point in the book I fail to find any previous examples which might
lead me to my own solution and there are no "Answers to Exercises" as far as
I can see. I have a feeling that this might be a fundamental piece of
knowledge to assist me in further reading of the book.

Alan Cameron




More information about the Beginners mailing list