Re: [Haskell-cafe] Error Monad and strings

2010-08-03 Thread John Meacham
On Tue, Jul 27, 2010 at 04:08:39PM -0700, Gerald Gutierrez wrote: Reading the Control.Monad.Error documentation, I see that the Error class has noMsg and strMsg as its only two functions. Now, I understand that you can define your own Error instances such as in example 1 of the

Re: [Haskell-cafe] Error Monad and strings

2010-07-28 Thread Evan Laforge
I've always thought that being able to write: catMaybes :: [Maybe a] - [a] catMaybes xs = [ x | Just x - xs ] is really cool, which relies on: fail _ = [] being in the Monad instance for List. Really? I thought that's just a feature of list comprehensions. List comps are not monads,

[Haskell-cafe] Error Monad and strings

2010-07-27 Thread Gerald Gutierrez
Reading the Control.Monad.Error documentation, I see that the Error class has noMsg and strMsg as its only two functions. Now, I understand that you can define your own Error instances such as in example 1 of the documentation, so why the need to always support strings via noMsg/strMsg ? What

Re: [Haskell-cafe] Error Monad and strings

2010-07-27 Thread Gregory Crosswhite
It is for the very annoying reason that in order for Error to be a monad it has to implement the fail method, which means it has to know how to turn an arbitrary string into a value of your error type. Cheers, Greg On 07/27/10 15:32, Gerald Gutierrez wrote: Reading the Control.Monad.Error

Re: [Haskell-cafe] Error Monad and strings

2010-07-27 Thread Dietrich Epp
The strMsg method is used to implement the fail method in the resulting method, and calls to fail might be inserted into your code even if you don't explicitly call it. An example in GHCi: Prelude :m + Control.Monad.Error Prelude Control.Monad.Error do { Just x - return Nothing ; return x

Re: [Haskell-cafe] Error Monad and strings

2010-07-27 Thread Gerald Gutierrez
On Tue, Jul 27, 2010 at 3:57 PM, Dietrich Epp d...@zdome.net wrote: The strMsg method is used to implement the fail method in the resulting method, and calls to fail might be inserted into your code even if you don't explicitly call it. An example in GHCi: Prelude :m + Control.Monad.Error

Re: [Haskell-cafe] Error Monad and strings

2010-07-27 Thread Dietrich Epp
I'll say yes, a pattern match failure is a bug. This is one of the great debates in the language: whether all pattern matching code should be guaranteed complete at compile time or not. However, any function you call which returns a result in your monad could theoretically call fail if

Re: [Haskell-cafe] Error Monad and strings

2010-07-27 Thread Antoine Latter
On Tue, Jul 27, 2010 at 6:29 PM, Dietrich Epp d...@zdome.net wrote: I'll say yes, a pattern match failure is a bug.  This is one of the great debates in the language: whether all pattern matching code should be guaranteed complete at compile time or not.  However, any function you call which