No instance for (Num [Integer]) arising from the literal ‘1’

plus1 :: [Integer] ->  [Integer] -> [Integer] 
plus1 (x:xs) remain  
    | (x==0) && (remain==1) = [1] ++ (plus1 xs (remain-1) )
    | (x==1) && (remain==1) = [0] ++ (plus1 xs remain)
    | (x==0) && (remain==0) = [0] ++ (plus1 xs 0)
    | (x==1) && (remain==0) = [1] ++ (plus1 xs 0)
    |  otherwise = []

• No instance for (Num [Integer]) arising from the literal ‘1’

• In the second argument of ‘(==)’, namely ‘1’

In the second argument of ‘(&&)’, namely ‘(remain == 1)’

In the expression: (x == 0) && (remain == 1)

1 answer

  • answered 2017-11-12 20:33 Adam Smith

    your type signature says that remain should be :: [Integer] but you are comparing it with == to 1 with is Integer. Perhaps your type signature was intended to be plus1 :: [Integer] -> Integer -> [Integer]