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" wrote: > Brandon Allbery wrote: > >>> > case () of > >>> > ()

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) = p

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 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. -- brandon s allbery

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 > On Fri, Dec 9, 2011 at 04:16, Yves Parès wrote: > >> Why do you people hate 'if'

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 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 the indentation beh

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 > On Thu, Dec 8, 2011 at 15:52, Tom Murphy wrote: > >> On Wed, Dec 7, 2011 at 11:46 PM, Brandon Allbery wrote: >> >>> > case () of >>> > () | s == reverse s -> putStrLn "palindrome" >>> > _ -> putStrLn "nope

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 wrote: > On Wed, Dec 7, 2011 at 11:46 PM, Brandon Allbery wrote: > >> > case () of >> > () | s == reverse s -> putStrLn "palindrome" >> > _ -> putStrLn "nope" >> > > > This is kind of a hack of case, though. I think what the OP was lo

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 wrote: > On Wed, Dec 7, 2011 at 23:24, Alexej Segeda > wrote: > >> case s of >>(s == reverse s)-> putStrLn (s ++ " is a >> palindrome") >>otherwise -> putStrLn (s ++ " is not a >

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 bu

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 wrote: > case s of >(s == reverse s)-> putStrLn (s ++ " is a > palindrome") >otherwise -> putStrLn (s ++ " is not a > palindrome") > case does pattern matching, not Boolean expression

[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 not

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 (

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 () col

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.

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 basi

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

[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 ca

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

2005-04-25 Thread Scott Turner
On 2005 April 25 Monday 02:16, Michael Vanier wrote: > -- Generate an infinite list of coin flips. > coinFlips :: IO [Coin] > coinFlips = sequence cfs > where cfs = (coinFlip : cfs) > -- > > [...] My understanding is th

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

2005-04-25 Thread Sebastian Sylvan
On 4/25/05, Michael Vanier <[EMAIL PROTECTED]> 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 =

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 =

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

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

2005-04-24 Thread 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 deriving (Eq, Show) -- Generate a random coin flip. coinFlip :