How to use two let's on the same line?
Asked Answered
I

2

6

I'm using Hugs interpreter and I want to execute the following code (by Haskell 2010 language report):

let x = 1
z = x+y
in z+1

Is it possible only creating a .hs file and loading? Can I do it by command line directly?

Isolated answered 7/11, 2015 at 13:35 Comment(6)
Indent the z =... line so that the z lines up under the x. Use spaces, tabs can cause problems in Haskell.Irvinirvine
doesn't ` let x = 1 in let z = x+y in z + 1` or let x=1; z=x+y in z + 1 work? (I can only test in ghci and basically have no clue about hugs - sorry)Giaimo
Hugs hasn't been maintained in years. Only a handful of people still use it. Why do you?Carbone
@Carsten booth works. Thanks!Isolated
@Isolated I added it as an answer - I hope you don't mindGiaimo
@Carbone it's probably the FP101xGate thing ;)Giaimo
G
4

Even if you cannot enter multi-line statements into hugs in this case it is possible to do it all in one line.

You can use two let ... in ... like this:

let x = 1 in let z = x+y in z + 1

or you can use ; for multiple definitions like this:

let x=1; z=x+y in z + 1
Giaimo answered 8/11, 2015 at 7:41 Comment(0)
C
4

(Sorry - didn't realize your question was about hugs not ghci.)

You can use :{ in ghci to enter a multiline expression:

shell$ ghci
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
Prelude> :{
Prelude|   let z = 1
Prelude|       w = 3
Prelude|   in z + w
Prelude| :}
4
Prelude>
Cosmonautics answered 7/11, 2015 at 14:26 Comment(1)
Why is it sad for hugs to declare lets? (:{)Schutt
G
4

Even if you cannot enter multi-line statements into hugs in this case it is possible to do it all in one line.

You can use two let ... in ... like this:

let x = 1 in let z = x+y in z + 1

or you can use ; for multiple definitions like this:

let x=1; z=x+y in z + 1
Giaimo answered 8/11, 2015 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.