[Haskell-cafe] Let it be

Ross Mellgren rmm-haskell at z.odi.ac
Thu Oct 8 13:07:41 EDT 2009


I don't know of any offhand that specifically call it out -- it's a  
natural consequence of the layout rule which is described in the  
Haskell Report. However, there is at least one ticket in Haskell' to  
fix it for if/then/else: http://hackage.haskell.org/trac/haskell-prime/ticket/23

-Ross

On Oct 8, 2009, at 1:03 PM, michael rice wrote:

> Thanks all,
>
> So, in a do expression
>
>  let x = 1
>      y = 2
>      etc.
>    in z = 1 + 2
>
>   if <bool expr>
>     then
>       etc.
>     else
>       etc.
>
> Is this deviation documented somewhere?
>
> Michael
>
> --- On Thu, 10/8/09, Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>  
> wrote:
>
> From: Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>
> Subject: Re: [Haskell-cafe] Let it be
> To: "michael rice" <nowgate at yahoo.com>
> Cc: "Brandon S. Allbery KF8NH" <allbery at ece.cmu.edu>, haskell-cafe at haskell.org
> Date: Thursday, October 8, 2009, 11:53 AM
>
> On Oct 8, 2009, at 11:43 , michael rice wrote:
>> This doesn't:
>>
>> import System.Random
>> main = do
>>   gen <- getStdGen
>>   let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen)
>>   in putStrLn $ "Number is " ++ show randNumber
>>
>> [michael at localhost ~]$ runhaskell zz.hs
>>
>> zz.hs:4:2:
>>     The last statement in a 'do' construct must be an expression
>
>
> 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.
>
> 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
>
> -- 
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university     
> KF8NH
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091008/e52c406b/attachment.html


More information about the Haskell-Cafe mailing list