Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-27 Thread Henning Thielemann
On Mon, 27 Jun 2005, Daniel Fischer wrote: Am Sonntag, 26. Juni 2005 21:02 schrieben Sie: On Sun, 26 Jun 2005, Daniel Fischer wrote: m x y = if x==0 then 0 else x*y Plain foldr m 1 does fine, in fact much better than foldl' (*) 1 . upTo (== 0), both in

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-26 Thread Cale Gibbard
Oops, somehow that reply by Scott Turner (which coincidentally contained the same example) hadn't appeared for me yet :) Anyway, seconded :) On 26/06/05, Cale Gibbard [EMAIL PROTECTED] wrote: Well, the case of the built-in numeric types is somewhat different, but most functions automatically

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-26 Thread Udo Stenzel
Scott Turner wrote: It's still possible to use fold and get short circuiting with good memory usage. upTo pred = foldr (\a - \xs - if pred a then [a] else a:xs) [] prodList = foldl' (*) 1 . upTo (== 0) It might be considered cheating, but AFAICT the test for ==0 needs to be separated

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-26 Thread Daniel Fischer
Am Sonntag, 26. Juni 2005 06:06 schrieb Scott Turner: On 2005 June 25 Saturday 17:49, [EMAIL PROTECTED] wrote: Simplified: prodList xs = foldl (*) 1 xs But my original at least made some provision for short circuiting the whole operation if the list contained a 0. As far as I can

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-26 Thread Henning Thielemann
On Sun, 26 Jun 2005, Daniel Fischer wrote: m x y = if x==0 then 0 else x*y Plain foldr m 1 does fine, in fact much better than foldl' (*) 1 . upTo (== 0), both in hugs and ghc, regarding speed and memory usage. E.g. foldr m 1 [a,b,c] means m a (m b (m c 1))) That is, it is

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-25 Thread kynn
Some simplifications might help you here... prodList [] = 1 prodList (0:xs) = 0 prodList (x:xs) = x * prodList xs Simplified: prodList xs = foldl (*) 1 xs But my original at least made some provision for short circuiting the whole operation if the list contained a 0. As

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-25 Thread Cale Gibbard
Well, the case of the built-in numeric types is somewhat different, but most functions automatically short circuit, since Haskell uses lazy evaluation. For instance, it's perfectly okay to define myAnd = foldr () True Note that this terminates on infinite lists which contain False as a value:

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-23 Thread Sebastian Sylvan
On 6/23/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: getList = do putStrLn Give me a number (or 0 to stop): numString - getLine let num = read numString if num == 0 then return [] else return (num:getList) This will give you an error as well. 'num' is of type

[Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-22 Thread kynn
--text follows this line-- I'm trying to learn Haskell from YAHT. My attempt at a solution of Exercise 3.10 is failing with a Type does not match error. The exercise is to write a function that will read numbers (one per line) from the command line, until the number 0 is entered. At this

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-22 Thread Bernard Pope
On Thu, 2005-06-23 at 00:17 -0400, [EMAIL PROTECTED] wrote: printFact [] = return printFact (x:xs) = do -- triggers error message putStrLn (x ++ factorial is ++ fact x) printFact xs return If anyone can explain to me how to fix this error I'd appreciate it. You forgot to return a

Re: [Haskell-cafe] Noob error: Type b - c b Does not match IO a

2005-06-22 Thread kynn
From: Bernard Pope [EMAIL PROTECTED] Cc: haskell-cafe@haskell.org On Thu, 2005-06-23 at 00:17 -0400, [EMAIL PROTECTED] wrote: You forgot to return a value. ... Much appreciated! kj ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org