Why doesn't this work? (Haskell - A Long string of Let - in's)

Page 1 of 1

4 Replies - 649 Views - Last Post: 14 October 2016 - 05:09 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=397981&amp;s=465a72a6b16000bedddb74b250e91d5f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 otyca

Reputation: 0
• Posts: 9
• Joined: 17-January 15

Why doesn't this work? (Haskell - A Long string of Let - in's)

Posted 13 October 2016 - 10:10 PM

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

Is This A Good Question/Topic? 0

Replies To: Why doesn't this work? (Haskell - A Long string of Let - in's)

#2 otyca

Reputation: 0
• Posts: 9
• Joined: 17-January 15

Re: Why doesn't this work? (Haskell - A Long string of Let - in's)

Posted 13 October 2016 - 10:22 PM

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

I can't seem to fix my error in my original post (keeps reverting back my changes), but the incr(/> should be incr( and the indentation on the last line is a bit off. I'm sorry I would fix the error if I could figure out how to (but it seems as though it does allow me to).

otyca, on 13 October 2016 - 10:15 PM, said:

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

I can't seem to fix my error in my original post (keeps reverting back my changes), but the incr(/> should be incr( and the indentation on the last line is a bit off. I'm sorry I would fix the error if I could figure out how to (but it seems as though it does allow me to).

otyca, on 13 October 2016 - 10:15 PM, said:

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

Ah! Correcting this post is getting a bit frustrating!! Sorry, I meant to say the
incr(B)/>/>
should be
incr(B)/>
(not smiley faces)...

otyca, on 13 October 2016 - 10:19 PM, said:

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/>/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/>/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

I can't seem to fix my error in my original post (keeps reverting back my changes), but the incr(/>/> should be incr(/> and the indentation on the last line is a bit off. I'm sorry I would fix the error if I could figure out how to (but it seems as though it does allow me to).

otyca, on 13 October 2016 - 10:15 PM, said:

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/>/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/>/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

I can't seem to fix my error in my original post (keeps reverting back my changes), but the incr(/>/> should be incr(/> and the indentation on the last line is a bit off. I'm sorry I would fix the error if I could figure out how to (but it seems as though it does allow me to).

otyca, on 13 October 2016 - 10:15 PM, said:

(Update: Made a bit of typo in my original post)

otyca, on 13 October 2016 - 10:10 PM, said:

I'm just learning Haskell and Functional Programming and can't seem to figure out why this doesn't work... Can anyone advise?

let a = 0 in
b = incr(a) in
c = incr(B)/>/> in
d = incr(c) in
e = incr(d) in
f = incr(e) in
g = incr(f) in
h = incr(g) in
i = incr(h) in
incr(a) + incr(B)/>/> + incr(c) + incr(d) + incr(e) + incr(f) + incr(g) + incr(h) + incr(i)

#3 sepp2k

• D.I.C Lover

Reputation: 2627
• Posts: 4,181
• Joined: 21-June 11

Re: Why doesn't this work? (Haskell - A Long string of Let - in's)

Posted 14 October 2016 - 07:37 AM

Don't bother trying to fix it, it's a forum bug.

Anyway, when you say it doesn't work, it'd help a lot if you described how it doesn't work, by posting the error message for example.

The main problem that I see is that you keep using = after the in. The syntax of let is let <bindings> in <expression> where bindings contains one or more bindings of the form <variable> = <expression> (which all need to be indented at the same level). The important things to note here is that there's only one in per let and that no bindings appear after the in.

So if you want to nest multiple lets inside each other, you need to actually use let multiple times, like this:

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

But a more convenient way would be to put all in one let like this:

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

#4 otyca

Reputation: 0
• Posts: 9
• Joined: 17-January 15

Re: Why doesn't this work? (Haskell - A Long string of Let - in's)

Posted 14 October 2016 - 11:26 AM

Ahhh! I see, thank you so much! I had a hunch it was due to some sort of syntactical error, but I just couldn't figure out what (even after spending some time scouring the web). This makes a lot of sense now.

Thanks again!

sepp2k, on 14 October 2016 - 07:37 AM, said:

Don't bother trying to fix it, it's a forum bug.

Anyway, when you say it doesn't work, it'd help a lot if you described how it doesn't work, by posting the error message for example.

The main problem that I see is that you keep using = after the in. The syntax of let is let <bindings> in <expression> where bindings contains one or more bindings of the form <variable> = <expression> (which all need to be indented at the same level). The important things to note here is that there's only one in per let and that no bindings appear after the in.

So if you want to nest multiple lets inside each other, you need to actually use let multiple times, like this:

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

But a more convenient way would be to put all in one let like this:

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

#5 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

Re: Why doesn't this work? (Haskell - A Long string of Let - in's)

Posted 14 October 2016 - 05:09 PM

The bug occurs when you have a b and a brace together like b).

To circumvent the bug add a space between the b and the bracket.

inc(b );