[clean-list] Newbie Question
Wilfried Esken
wesken@gmx.de
Wed, 18 Sep 2002 23:56:06 +0200
Hello,
I tried to learn CLEAN and therefore I read the exercises in the Clean Book.
First I made a function MaxofList which should return the maximum value of a
list.
I tried it this way:
maxi :: a a -> a | <, == a
maxi a b
| a <= b = b
| otherwise = a
MaxofList [] = 0
MaxofList [x] = x
MaxofList [x,y] = maxi x y
MaxofList [first:rest] =
maxi a b
where a = first
b = MaxofList rest
This works fine for a list of integers, but I want to have a function like
MaxofList :: [a] -> a
This doesn't work because of
MaxofList [] = 0,
the compiler derives type Int for the function.
What is the solution for having a generell typed function in this case?
Thank you,
Willi