-1

I want to get 2 integers from an input like pascal 2 1. This input should be 2, because the list starts with x and y = 0. Also pos must be <= row and i don't want to use guards. My code looks like this:

pascal :: Int -> Int -> Int
pascal row pos
        if row == 0 || pos == 0 then "1" 
        else if row > pos then error "Invalid input." 
        else (pascal (row-1) (pos-1)) + (pascal (row-1) (pos))

Error code:

Unexpected if expression in function application:
if row == 0 || pos == 0 then
        "1"
    else
        if row > pos then
            error "Invalid input."
        else
            (pascal (row - 1) (pos - 1)) + (pascal (row - 1) (pos))
You could write it with parentheses
Or perhaps you meant to enable BlockArguments?
Plex
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 16 '21 at 11:17
  • Hi Plex, what is your question? It looks like you got an compile error and you don't understand why. You should state your question explicitly. – Martin Böschen Nov 16 '21 at 11:18

1 Answers1

0
pascal :: Int -> Int -> Int
pascal row pos = 
        if row == 0 || pos == 0 then 1 
        else if row > pos then error "Invalid input." 
        else (pascal (row-1) (pos-1)) + (pascal (row-1) (pos))

To get rid of that error you just need to add an =, which you probably just forgot. But this is really bad style in Haskell. This code begs for guards.

user1984
  • 5,990
  • 2
  • 13
  • 32