Page 1 of 1

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

### #1 hellhound

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

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

• The Algorithmi

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

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

### #3 hellhound

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

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)

```

### #4 mostyfriedman

• The Algorithmi

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

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

### #5 Raynes

• D.I.C Lover

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

Posted 25 July 2009 - 02:45 PM

mostyfriedman, 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!

### #6 hellhound

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

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.....

### #7 mostyfriedman

• The Algorithmi

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

Posted 25 July 2009 - 09:20 PM

Raynes, on 25 Jul, 2009 - 01:45 PM, said:

mostyfriedman, 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

### #8 Raynes

• D.I.C Lover

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

Posted 26 July 2009 - 02:07 PM

mostyfriedman, on 25 Jul, 2009 - 08:20 PM, said:

Raynes, on 25 Jul, 2009 - 01:45 PM, said:

mostyfriedman, 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.

### #9 Eman_321

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

Posted 24 January 2010 - 08:34 AM

hellhound, 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)

```

### #10 Raynes

• D.I.C Lover

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

Posted 24 January 2010 - 03:06 PM

Eman_321, on 24 Jan, 2010 - 07:34 AM, said:

hellhound, 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.

### #11 erik.price

• D.I.C Lover

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

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.

### #12 Raynes

• D.I.C Lover

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

Posted 24 January 2010 - 08:09 PM

erik.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.

### #13 erik.price

• D.I.C Lover

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

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

edit: typo

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

### #14 mostyfriedman

• The Algorithmi

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

Posted 27 January 2010 - 06:26 PM

Eman is probably a girl ..its an Arabic name..

### #15 Guest_Twey*

Reputation:

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)
```