Trying to return tuple

87 views Asked by At

So I'm trying to make game of nim while playing against the computer in haskell as part of an assignment, but I'm struggling with the computer part. what i wish to do is return a tuple containing the heap number(row) and number to remove. So far I've got this:

ai board [] = []
ai board (x:xs) = 
    do
       let target = foldr (^) board
       if target < x then do
          let num = x-target   
          return (x, num)
       else
          ai board xs

which raises this error:

Oblig3.hs:75:1: error:
    * Non type-variable argument in the constraint: Ord (t b -> b)
      (Use FlexibleContexts to permit this)
    * When checking the inferred type
        ai :: forall (t :: * -> *) b.
              (Ord (t b -> b), Foldable t, Integral b, Num (t b -> b)) =>
              b -> [t b -> b] -> [(t b -> b, t b -> b)]
   |
75 | ai board [] = []

PS board is a list of ints showing how many elements is left in the heap and the computer algorithm is based on the one found on Nim's wikipedia

1

There are 1 answers

0
Joseph Sible-Reinstate Monica On BEST ANSWER

foldr takes 3 arguments, but in target = foldr (^) board, you're only giving it 2. You can't then compare it with if target < x because it's not a number yet, but still a function waiting for one more argument.