Re: [Haskell-cafe] Error Monad and strings
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 it was written that way. Data.Map.lookup used to call "fail" when it could not find a key, but that got changed. If you don't want to catch these errors in your monad, you can write your own monad (or monad transformer). For example: newtype ErrorCode = ErrorCode Int deriving Show newtype ErrorCodeT m a = ErrorCodeT { runErrorCodeT :: m (Either ErrorCode a) } instance Monad m => Monad (ErrorCodeT m) where return = ErrorCodeT . return . Right a >>= b = ErrorCodeT $ do m <- runErrorCodeT a case m of Left err -> return $ Left err Right x -> runErrorCodeT $ b x fail = ErrorCodeT . fail failWithCode :: Monad m => Int -> ErrorCodeT m a failWithCode = ErrorCodeT . return . Left . ErrorCode There's probabaly a library somewhere which does this already. On 2010 July 27, at 16:08, Gerald Gutierrez wrote: I see. So strings must be supported in the case of a bug which cannot be caught at compile time? In other words, if I get an error with a string, I'm pretty much guaranteed it is a bug, i.e. a pattern match error as the "fail" documentation says. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Error Monad and strings
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 } :: Either String Int Left "Pattern match failure in do expression at :1:5-8" Note that in the "Either String" monad, "failStr" is equal to "Left". On 2010 July 27, at 15:32, 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 documentation, so why the need to always support strings via noMsg/strMsg ? What uses these? And if in my code, I will never throw an error with a string, am I supposed to implement these functions and then ignore them? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is it so different between 6.12.1 and 6.10.4_1 ?
I think Miljenovic was asking about this (I removed explicit braces): fac n = let f = foldr (*) 1 [1..n] in f Which is strictly equivalent to: fac n = foldr (*) 1 [1..n] Translated into C, this is kind of like doing this: int add(int x, int y) { int sum = x + y; return sum; } instead of this: int add(int x, int y) { return x + y; } I find it very cumbersome (though not *difficult*) and painful to use a C style of programming with Haskell, so I am not sure what you mean when you ask why Haskell supports C style. Are you talking about mutable state, syntax, or something else? --Dietrich On 2010 March 27, at 4:28, zaxis wrote: Of course, you are wrong ! C is VERY important for almost every programmer in the world! Why cannot C programmer use haskell ? And Why does haskell support C code style ? Ivan Miljenovic wrote: zaxis writes: Why do you bother with the interior definition of f in there? Because i want to try a C code style not layout style without `do` syntax sugar . Haskell /= C, so stop trying to code as if it is. If you like C so much, then use C. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28051693.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem with Haskell Platform website
There's a problem with the Haskell Platform website. I'm posting the message here because I gave up looking for contact information for the site, maybe someone here can forward the message or tell me who to forward it to? The specific page is http://hackage.haskell.org/platform/mac.html Being one of the few who still use the PPC architecture, I expect to have to build my own packages from source. Imagine my surprise when the Haskell platform uses the "Universal Binary" logo on the Mac download. Nowhere on the Mac download page does it specify an architecture. However, the binary is i386 only and not PPC. So I just wasted time downloading something I can't install on my computer. This page shows the "Universal Binary" logo: http://hackage.haskell.org/platform/ Here is Apple's "Universal Binary" page, which describes what the logo means: http://www.apple.com/universal/ It would be nice to get rid of the "Universal Binary" logo and to mark the packages as i386. --Dietrich Epp ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe