Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-11 Thread Yitzchak Gale
Brandon Allbery wrote: case () of   () | s == reverse s - putStrLn palindrome   _                   - putStrLn nope Tom Murphy wrote: This is kind of a hack of case, though. I think what the OP was looking for is  isPalindrome word   | (word == reverse word) = putStrLn (word ++ is a

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-11 Thread Tom Murphy
To clarify, by hack I meant that it seemed like a workaround specifically to keep case in the OP's code, when it seemed like they were looking for the functionality of guards. amindfv / Tom On Dec 11, 2011 1:39 PM, Yitzchak Gale g...@sefer.org wrote: Brandon Allbery wrote: case () of ()

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-09 Thread Yves Parès
Why do you people hate 'if' statements? 2011/12/9 Brandon Allbery allber...@gmail.com On Thu, Dec 8, 2011 at 15:52, Tom Murphy amin...@gmail.com wrote: On Wed, Dec 7, 2011 at 11:46 PM, Brandon Allbery allber...@gmail.comwrote: case () of () | s == reverse s - putStrLn palindrome _

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-09 Thread Brandon Allbery
On Fri, Dec 9, 2011 at 04:16, Yves Parès limestr...@gmail.com wrote: Why do you people hate 'if' statements? It's more that the language spec does; if statements, along with a number of other things, desugar to case which is the fundamental conditional construct. (And more personally, I find

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-09 Thread Yves Parès
I agree with all that, but in *this *special case, I think that case something of True - False - is less nice and obvious than if something then else 2011/12/9 Brandon Allbery allber...@gmail.com On Fri, Dec 9, 2011 at 04:16, Yves Parès limestr...@gmail.com

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-09 Thread Brandon Allbery
On Fri, Dec 9, 2011 at 05:16, Yves Parès limestr...@gmail.com wrote: I agree with all that, but in *this *special case, I think that I should also note that the OP mentioned using if, but was surprised/confused by the behavior of case, which is why that's what we've been focusing on. --

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-08 Thread Paul R
Alexej The interesting thing is, that if I change the case ... of Alexej statement to an if ... then ... else statement, this magically Alexej starts to work. Since I no longer am enrolled (I have to take Alexej the course next year), I can't ask a teacher, but my curiosity Alexej still bugs me.

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-08 Thread Tom Murphy
On Wed, Dec 7, 2011 at 11:46 PM, Brandon Allbery allber...@gmail.comwrote: On Wed, Dec 7, 2011 at 23:24, Alexej Segeda aloscha_den_st...@hotmail.com wrote: case s of (s == reverse s)- putStrLn (s ++ is a palindrome) otherwise

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-08 Thread Brandon Allbery
On Thu, Dec 8, 2011 at 15:52, Tom Murphy amin...@gmail.com wrote: On Wed, Dec 7, 2011 at 11:46 PM, Brandon Allbery allber...@gmail.comwrote: case () of () | s == reverse s - putStrLn palindrome _ - putStrLn nope This is kind of a hack of case, though. I think

[Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-07 Thread Alexej Segeda
Hi! A couple of months ago, I wrote an exam in an introductory Haskell course and failed, all because of an assignment that I was convinced would work, but for some reason, it didn't. The assignment was to write a function that would take a line, then determine whether it's a palindrome or

Re: [Haskell-cafe] Why doesn't this work? (palindrome :: IO)

2011-12-07 Thread Brandon Allbery
On Wed, Dec 7, 2011 at 23:24, Alexej Segeda aloscha_den_st...@hotmail.comwrote: case s of (s == reverse s)- putStrLn (s ++ is a palindrome) otherwise - putStrLn (s ++ is not a palindrome) case does pattern matching, not

[Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Andrew Coppin
colour_grid :: (Particle - IO ()) - Grid ph - IO () colour_grid fn g = sequence_ $ runST $ do ps - grid_coords g mapM (\pix - do particle - read_grid g pix return $ fn particle ) ps When I attempt to run this, GHCi just gives me a very cryptic type checker error. I can't

Re: [Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Alfonso Acosta
I haven't tried to run the code, but my first bet is that, due to the rank-2 polymorphism of ST, you should use parenthesis instead of $ in the case of runST. On Sun, Aug 24, 2008 at 3:25 PM, Andrew Coppin [EMAIL PROTECTED] wrote: colour_grid :: (Particle - IO ()) - Grid ph - IO () colour_grid

Re: [Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Yitzchak Gale
Alfonso Acosta wrote: I haven't tried to run the code, but my first bet is that, due to the rank-2 polymorphism of ST, you should use parenthesis instead of $ in the case of runST. Perhaps if Andrew is using an old compiler. That is no longer a problem in recent versions of GHC. A more basic

Re: [Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Daniel Fischer
Am Sonntag, 24. August 2008 17:21 schrieb Yitzchak Gale: Alfonso Acosta wrote: I haven't tried to run the code, but my first bet is that, due to the rank-2 polymorphism of ST, you should use parenthesis instead of $ in the case of runST. Perhaps if Andrew is using an old compiler. That

Re: [Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Emil Axelsson
BTW, this is a case where it may be more convenient to use forM: forM ps $ \pix - do particle - read_grid g pix return $ fn particle (untested...) forM is just another way of saying (flip mapM). / Emil Andrew Coppin skrev: colour_grid :: (Particle - IO ()) - Grid ph - IO ()

Re: [Haskell-cafe] Why doesn't this work?

2008-08-24 Thread Yitzchak Gale
I wrote: A more basic issue is that fn is in the IO monad, but its use inside the mapM will need it to be in the ST monad. Daniel Fischer wrote: No, return (fn particle) :: ST s (IO ()) , so that's fine. Ah, true. But I doubt that Andrew really meant to do the calculation in ST s (IO ()).

Re: [Haskell-cafe] Why doesn't this work?

2005-04-25 Thread Daniel Fischer
Am Montag, 25. April 2005 08:16 schrieb Michael Vanier: I've been trying to generate an infinite list of random coin flips in GHC 6.4, and I've come across some strange behavior: -- import System.Random data Coin = H | T

Re: [Haskell-cafe] Why doesn't this work?

2005-04-25 Thread Duncan Coutts
On Sun, 2005-04-24 at 23:16 -0700, Michael Vanier wrote: I've been trying to generate an infinite list of random coin flips in GHC 6.4, and I've come across some strange behavior: -- import System.Random data Coin = H | T