[Haskell-cafe] Let it be

michael rice nowgate at yahoo.com
Thu Oct 8 11:43:12 EDT 2009


>From Learn You a Haskell ("Let it be" section):

   1. cylinder :: (RealFloat a) => a -> a -> a  
   2. cylinder r h = 
   3.     let sideArea = 2 * pi * r * h  
   4.         topArea = pi * r ^2  
   5.     in  sideArea + 2 * topArea
===================



What's the proper indentation for LET so these problems (below) don't arise? I
thought LET and IN should be aligned in the same column. Also, isn't a
LET expression an "expression."



Michael

==============

This works:

import System.Random
main = do
  gen <- getStdGen
  let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen)
    in putStrLn $ "Number is " ++ show randNumber

==============

This works:

import System.Random
main = do
  gen <- getStdGen
  let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen)
  putStrLn $ "Number is " ++ show randNumber

==============

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





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


More information about the Haskell-Cafe mailing list