4 Replies - 582 Views - Last Post: 14 October 2016 - 05:09 PM Rate Topic: -----

#1 otyca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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)

View Postotyca, 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(B)/> should be incr(B) 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).

View Postotyca, on 13 October 2016 - 10:15 PM, said:

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

View Postotyca, 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(B)/> should be incr(B) 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).

View Postotyca, on 13 October 2016 - 10:15 PM, said:

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

View Postotyca, 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)...

View Postotyca, on 13 October 2016 - 10:19 PM, said:

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

View Postotyca, 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(B)/>/> should be incr(B)/> 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).

View Postotyca, on 13 October 2016 - 10:15 PM, said:

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

View Postotyca, 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(B)/>/> should be incr(B)/> 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).

View Postotyca, on 13 October 2016 - 10:15 PM, said:

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

View Postotyca, 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) 


Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2517
  • View blog
  • Posts: 4,001
  • 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


Was This Post Helpful? 1
  • +
  • -

#4 otyca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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!


View Postsepp2k, 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


Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1852
  • View blog
  • Posts: 6,664
  • 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 );


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1