On Oct 8, 2009, at 11:53 , Brandon S. Allbery KF8NH wrote:
The problem here is that the "do" construct parses things a bit differently; if you're at the same indentation level, it inserts a (>>) on the assumption that the next line is an independent expression, so you need to indent the "in" a bit more to avoid it.
I should probably clarify that what is actually inserted is a semicolon as noted by Ross Mellgren, and the next level of translation then replaces it with the (>>) operator.
Note however that this usage is common enough that "do" provides a shorthand: you can simply omit the "in", and "let" will be parsed as if it were a statement:> main = do > gen <- getStdGen > let (randNumber, newGen) = randomR (1,6) gen :: (Int,StdGen) > putStrLn $ "Number is " ++ show randNumber
I should also mention that there are still constructs where this indentation quirk can bite you, notably:
> if foo > then bar > else baz works outside of a "do" construct, but inside one you need extra spaces: > do > if foo > then bar > else bazotherwise, you again get semicolons inserted before the "then" and "else" and subsequently replaced with (>>).
-- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
PGP.sig
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe