Tuesday, 17 September 2013

Haskell: use Maybe but print an actual number rather than "Just ... "

Haskell: use Maybe but print an actual number rather than "Just ... "

So here is my program. I want to implement a maximum function on my own
for an assignment. The problem is that to me it seems weird to print the
number with the word "Just" in front of it... How would I fix this to
print just a number?
mymax :: Ord a=>[a]->Maybe a
mymax [] = Nothing
mymax [x] = Just x
mymax (x:y:xs) = if x < y then mymax(y:xs) else mymax(x:xs)

No comments:

Post a Comment