[Haskell-cafe] Maybe and partial functions
Dougal Stanton
ithika at gmail.com
Mon Mar 12 05:43:34 EDT 2007
The Maybe construction is very useful for explicitly handling
circumstances where the function cannot produce a sensible answer.
But how far should this notion be taken? When you're writing a function
which you realise may not produce what you want, in what circumstances
would you use a Maybe, and when would you just throw an error?
I'm wondering both in terms of good engineering practise and also for
correctness. Should elementary partial functions like
> 5 `div` 0
or
> 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?
Cheers,
D.
--
Dougal Stanton
More information about the Haskell-Cafe
mailing list