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

2010-08-10 Thread wren ng thornton
michael rice wrote: 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 statemen

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

2010-08-10 Thread michael rice
So all the Xs would be in scope at s6. Important point. Thanks, Michael --- On Tue, 8/10/10, Alex Stangl wrote: From: Alex Stangl Subject: Re: [Haskell-cafe] Couple of questions about *let* within *do* To: "michael rice" Cc: "Tillmann Rendel" , haskell-cafe@haske

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

2010-08-10 Thread Alex Stangl
On Tue, Aug 10, 2010 at 11:01:28AM -0700, michael rice wrote: > Hi all, > > Then, > > do s1 > s2 > let x1 = e1 > x2 = e2 > s3 > s4 > let x3 = e3 > x4 = e4 > s5 > s6 > > becomes > > do s1 > s2 > let x1 = e1 > x2 = e2 in

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

2010-08-10 Thread michael rice
do s5    s6? Michael --- On Tue, 8/10/10, Tillmann Rendel wrote: From: Tillmann Rendel Subject: Re: [Haskell-cafe] Couple of questions about *let* within *do* To: "michael rice" Cc: haskell-cafe@haskell.org Date: Tuesday, August 10, 2010, 1:35 PM michael rice wrote: > OK,

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

2010-08-10 Thread Felipe Lessa
On Tue, Aug 10, 2010 at 2:40 PM, Bill Atkins wrote: > They're not really statements, they're just named expressions and are still > subject to lazy evaluation. > > In: > >  let x = putStrLn "Name" >> getLine >  putStrLn "Welcome" >  x Yes, 'putStrLn "name" >> getLine' is an expression. However,

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

2010-08-10 Thread Bill Atkins
The let's aren't really statements, they're just named expressions and are still subject to lazy evaluation. In: let x = putStrLn "Name" >> getLine putStrLn "Welcome" x The program will print: Welcome Name? and then prompt for input, even though the let comes first. And if you never ran

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

2010-08-10 Thread Daniel Fischer
On Tuesday 10 August 2010 19:12:57, michael rice wrote: > OK, then there's also an implicit *in* after the *let* in this code. Yes. do let x = foo bar baz is desugared to let x = foo in (bar >> baz) > Must the implicit (or explicit) *in* actually use the calculated > value(s)? No, and i

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

2010-08-10 Thread Tillmann Rendel
michael rice wrote: OK, then there's also an implicit *in* after the *let* in this code. If you want to understand let statements in terms of let ... in ... expressions, you can do the following transformation: do s1 s2 let x1 = e1 x2 = e2 s3 s4 becomes do

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

2010-08-10 Thread michael rice
t in the *do*? main = do   gen <- getStdGen   let code = genCode gen   putStrLn $ "Code is " ++ show code   putStrLn "..." Michael --- On Tue, 8/10/10, Job Vranish wrote: From: Job Vranish Subject: Re: [Haskell-cafe] Couple of questions about *let* within *do* To: &

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

2010-08-10 Thread Job Vranish
Yes, and yes :) For example: import Data.Char main = do let prompt s = do putStrLn s getLine firstName <- prompt "What's your first name?" lastName <- prompt "What's your last name?" let bigFirstName = map toUpper firstName bigLastName = map toUpper lastName putStrLn

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

2010-08-10 Thread Felipe Lessa
On Tue, Aug 10, 2010 at 1:40 PM, michael rice wrote: > 1) Is there an implicit *in* before the last line above? The (let ... in ...) construct is an expression, while the (let ...) inside 'do' is a statement. The (do ...) itself is an expression. See the report: http://www.haskell.org/onlinerep

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

2010-08-10 Thread michael rice
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