[Haskell-cafe] Maybe and partial functions
ndmitchell at gmail.com
Mon Mar 12 07:37:43 EDT 2007
> > head 
> return Nothing? I guess it's a bit of a silly suggestion, but it helps
> to highlight why we use Maybe in the first place. So --- where's the
> cutoff point in your code?
If that is what you want, then see my Safe library:
headMay :: [a] -> Maybe a
(note this function already exists and is called listToMaybe)
However, I think that partial functions are just great, although a lot
of people disagree with me.
There are some tools being developed to check things like head :
Catch also checks division by zero, explicit patterns etc. To see the
world of pain you would be in if you go down the "make everything
total" route, I suggest you try rewriting this program to be complete:
(if you do, please post the result to the list)
If you ignore getArgs and read (which are incomplete in the above
example), then Catch is able to prove all the remaining things
complete, without annotations or code modifications.
You might also want to try redoing that example in the type style,
discussed here: http://www.haskell.org/haskellwiki/Non-empty_list
More information about the Haskell-Cafe