Re: [Haskell-cafe] Maybe and partial functions

2007-03-13 Thread Steve Downey
This isn't just a question about Haskell. It applies to any language with an exception mechanism, including C++ and Java. Even C (segv is an exception mechanism...) The question is really how to communicate failure to the caller, in a way the caller can not ignore, without unduely inconvienencing

[Haskell-cafe] Maybe and partial functions

2007-03-13 Thread oleg
Neil Mitchell wrote: > I suggest you try rewriting this program to be complete: > > http://darcs.haskell.org/nofib/imaginary/digits-of-e2/Main.lhs > > (if you do, please post the result to the list) As Gen Zhang noted, the problem seems to be quite straightforward: just express in types the fact

Re: [Haskell-cafe] Maybe and partial functions

2007-03-12 Thread Albert Y. C. Lai
Dougal Stanton wrote: 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 wo

Re: [Haskell-cafe] Maybe and partial functions

2007-03-12 Thread Gen Zhang
On Mon, 12 Mar 2007 11:37:43 + "Neil Mitchell" <[EMAIL PROTECTED]> wrote: > 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: > > ht

Re: [Haskell-cafe] Maybe and partial functions

2007-03-12 Thread Neil Mitchell
Hi > 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: http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#sa

[Haskell-cafe] Maybe and partial functions

2007-03-12 Thread Dougal Stanton
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