[Haskell-cafe] Couple of questions about *let* within *do*

michael rice nowgate at yahoo.com
Tue Aug 10 13:12:57 EDT 2010

OK, then there's also an implicit *in* after the *let* in this code. Must the implicit (or explicit) *in* actually use the calculated value(s)?

And, the monad can "continue on" after the *let* (with or without the *in*) as below, i.e., the *let* needn't be the last statement in the *do*?

main = do
  gen <- getStdGen
  let code = genCode gen
  putStrLn $ "Code is " ++ show code
  putStrLn "..."


--- On Tue, 8/10/10, Job Vranish <job.vranish at gmail.com> wrote:

From: Job Vranish <job.vranish at gmail.com>
Subject: Re: [Haskell-cafe] Couple of questions about *let* within *do*
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Tuesday, August 10, 2010, 12:52 PM

Yes, and yes :)

For example:

import Data.Char  

main = do
  let prompt s = do
      putStrLn s
  firstName <- prompt "What's your first name?"
  lastName <- prompt "What's your last name?"

  let bigFirstName = map toUpper firstName  
      bigLastName = map toUpper lastName  
  putStrLn $ "hey " ++ bigFirstName ++ " " ++ bigLastName ++ ", how are you?"

- Job

On Tue, Aug 10, 2010 at 12:40 PM, michael rice <nowgate at yahoo.com> wrote:

From: Learn You a Haskell


Remember let bindings? If you don't, refresh your memory on them by reading this section. They have to be in the form of let bindings in expression, where bindings are names to be given to expressions and expression is the expression that is to be evaluated that sees them. We also said that in list comprehensions, the in part isn't needed. Well, you can use them in do blocks pretty much like you use them in list comprehensions. Check this out:

  import Data.Char  
    main = do  
      putStrLn "What's your first name?"  
      firstName <- getLine  
      putStrLn "What's your last name?"  
 lastName <- getLine  
      let bigFirstName = map toUpper firstName  
          bigLastName = map toUpper lastName  
      putStrLn $ "hey " ++ bigFirstName ++ " " ++ bigLastName ++ ", how are you?"



1) Is there an implicit *in* before the last line above?

2) Within a do "in" the IO monad (or any other monad), can a *let* do something like this?

      let x = do   -- in a different monad



Haskell-Cafe mailing list

Haskell-Cafe at haskell.org


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

More information about the Haskell-Cafe mailing list