14 Replies - 6553 Views - Last Post: 11 February 2010 - 06:43 PM

#1 hellhound   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 07-March 09

haskell programming error

Post icon  Posted 23 July 2009 - 07:01 PM

hey guys i was wondering if you could tell me whats wrong with this peice of code. im new to haskell programming and still am having alot of problems with it.


bCSum :: Int -> Int
bCSum n = if n==0 then 1
	else n^3+bCSum (n-1)




the error i get it this:

Syntax error in declaration (unexpected `;', possibly due to bad layout)

thanks
Is This A Good Question/Topic? 0
  • +

Replies To: haskell programming error

#2 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: haskell programming error

Posted 23 July 2009 - 10:09 PM

no biggie, its just coz of the alighnment

bCSum :: Int -> Int
bCSum n = if n==0 then 1 else n^3+bCSum (n-1)



this should work now :)
Was This Post Helpful? 0
  • +
  • -

#3 hellhound   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 07-March 09

Re: haskell programming error

Posted 23 July 2009 - 11:11 PM

hmm seams to still give me the same error. heres the code that i have for that question and the one before it

--a:
aCSum :: Int -> Int
aCSum n 
	|n==0 =1
	|otherwise n^3+aCSum (n-1)

--b:

bCSum :: Int -> Int
bCSum n = if n==0 then 1 else n^3+bCSum (n-1)



Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: haskell programming error

Posted 24 July 2009 - 12:22 AM

you forgot an '=' after the otherwise
aCSum :: Int -> Int
aCSum n  |n==0 =1
		|otherwise = n^3+aCSum (n-1)


This post has been edited by mostyfriedman: 24 July 2009 - 12:22 AM

Was This Post Helpful? 0
  • +
  • -

#5 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 615
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: haskell programming error

Posted 25 July 2009 - 02:45 PM

View Postmostyfriedman, on 23 Jul, 2009 - 11:22 PM, said:

you forgot an '=' after the otherwise
aCSum :: Int -> Int
aCSum n  |n==0 =1
		|otherwise = n^3+aCSum (n-1)



You stole my question :(. It's so rare anyone asks a functional programming question, and you get it before I do. :\

D'oh well. The answers correct, but I'd also like to add that it's very bad practice to not use spaces in your code. Making everything run together is hard to read. I encourage you to use spaces!
Was This Post Helpful? 0
  • +
  • -

#6 hellhound   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 07-March 09

Re: haskell programming error

Posted 25 July 2009 - 04:16 PM

thanks guys and dont worry Raynes I'm sure I'll be posting a lot more questions for you to answer.....
Was This Post Helpful? 0
  • +
  • -

#7 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: haskell programming error

Posted 25 July 2009 - 09:20 PM

View PostRaynes, on 25 Jul, 2009 - 01:45 PM, said:

View Postmostyfriedman, on 23 Jul, 2009 - 11:22 PM, said:

you forgot an '=' after the otherwise
aCSum :: Int -> Int
aCSum n  |n==0 =1
		|otherwise = n^3+aCSum (n-1)



You stole my question :(. It's so rare anyone asks a functional programming question, and you get it before I do. :\

D'oh well. The answers correct, but I'd also like to add that it's very bad practice to not use spaces in your code. Making everything run together is hard to read. I encourage you to use spaces!



ohh sorry about that, k i'll leave the haskell questions to you :) i guess i'll stick to java
Was This Post Helpful? 0
  • +
  • -

#8 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 615
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: haskell programming error

Posted 26 July 2009 - 02:07 PM

View Postmostyfriedman, on 25 Jul, 2009 - 08:20 PM, said:

View PostRaynes, on 25 Jul, 2009 - 01:45 PM, said:

View Postmostyfriedman, on 23 Jul, 2009 - 11:22 PM, said:

you forgot an '=' after the otherwise
aCSum :: Int -> Int
aCSum n  |n==0 =1
		|otherwise = n^3+aCSum (n-1)



You stole my question :(. It's so rare anyone asks a functional programming question, and you get it before I do. :\

D'oh well. The answers correct, but I'd also like to add that it's very bad practice to not use spaces in your code. Making everything run together is hard to read. I encourage you to use spaces!



ohh sorry about that, k i'll leave the haskell questions to you :) i guess i'll stick to java


I was just joking silly. :P
Was This Post Helpful? 0
  • +
  • -

#9 Eman_321   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 24-January 10

Re: haskell programming error

Posted 24 January 2010 - 08:34 AM

View Posthellhound, on 23 Jul, 2009 - 06:01 PM, said:

hey guys i was wondering if you could tell me whats wrong with this peice of code. im new to haskell programming and still am having alot of problems with it.


bCSum :: Int -> Int
bCSum n = if n==0 then 1
	else n^3+bCSum (n-1)




the error i get it this:

Syntax error in declaration (unexpected `;', possibly due to bad layout)

thanks


You need use guards..im like you learning haskell and C..and i hate haskell..they sait is simple syntax but it is so complicated..You can't use if statement in haskell
bCSum :: Int -> Int
bCSum n 
   	|n==0 		=1	
   	|otherwise	= n^3+bCSum (n-1)


Was This Post Helpful? -1
  • +
  • -

#10 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 615
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: haskell programming error

Posted 24 January 2010 - 03:06 PM

View PostEman_321, on 24 Jan, 2010 - 07:34 AM, said:

View Posthellhound, on 23 Jul, 2009 - 06:01 PM, said:

hey guys i was wondering if you could tell me whats wrong with this peice of code. im new to haskell programming and still am having alot of problems with it.


bCSum :: Int -> Int
bCSum n = if n==0 then 1
	else n^3+bCSum (n-1)




the error i get it this:

Syntax error in declaration (unexpected `;', possibly due to bad layout)

thanks


You need use guards..im like you learning haskell and C..and i hate haskell..they sait is simple syntax but it is so complicated..You can't use if statement in haskell
bCSum :: Int -> Int
bCSum n 
   	|n==0 		=1	
   	|otherwise	= n^3+bCSum (n-1)



What are you even talking about? The syntax is painfully simple. Most of the syntax is simply more concise ways of doing other things. And you can't use an if statement in Haskell? That's news to me. Guards are simply syntactic sugar for if statements. What do you mean you can't use if statements? I have plenty of code that uses them, bro.

Don't hate Haskell just because it's different from every other language. C is an imperative language, and Haskell is a functional language. Functional programming is great in a lot of ways, and it isn't supposed to be like imperative or OO programming.

Don't learn a functional language and expect to be able to write Java in it.
Was This Post Helpful? 1
  • +
  • -

#11 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: haskell programming error

Posted 24 January 2010 - 03:13 PM

@Eman_321 You do realize that this thread is from July right? I'm pretty sure the OP has either found their answer or just moved on by now.
Was This Post Helpful? 0
  • +
  • -

#12 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 615
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: haskell programming error

Posted 24 January 2010 - 08:09 PM

View Posterik.price, on 24 Jan, 2010 - 02:13 PM, said:

@Eman_321 You do realize that this thread is from July right? I'm pretty sure the OP has either found their answer or just moved on by now.


I think his post was primarily just to complain about Haskell not being like every other language he's ever used.
Was This Post Helpful? 0
  • +
  • -

#13 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: haskell programming error

Posted 24 January 2010 - 08:21 PM

He joined at 10:13 today, posted at 10:37, and then logged out at 10:39. So, yeah, probably :P

edit: typo

This post has been edited by erik.price: 24 January 2010 - 08:21 PM

Was This Post Helpful? 0
  • +
  • -

#14 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: haskell programming error

Posted 27 January 2010 - 06:26 PM

Eman is probably a girl :D..its an Arabic name..
Was This Post Helpful? 0
  • +
  • -

#15 Guest_Twey*


Reputation:

Re: haskell programming error

Posted 11 February 2010 - 06:43 PM

For what it's worth, better separate equations than guards:

foo 0 = 1
foo n = n ^ 3 + foo (n - 1)



Or even a sequence:

foo = snd . (foos !!)
  where foos = iterate (\(n, o) -> (n + 1, o + succ n ^ 3)) (0, 1)

Was This Post Helpful? 0

Page 1 of 1