Reputation:
How to fix the permutation error on a list of functions?
> :m + Data.List
> permutations [(+1),(-2),(*3)]
No instance for (Num a0) arising from a use of `+'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Num Double -- Defined in `GHC.Float'
instance Num Float -- Defined in `GHC.Float'
instance Integral a => Num (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus three others
In the expression: (+ 1)
In the first argument of `permutations', namely
`[(+ 1), (- 2), (* 3)]'
In the expression: permutations [(+ 1), (- 2), (* 3)]
Upvotes: 1
Views: 376
Reputation: 53891
In Haskell the type of 1
is
1 :: Num a => a
So Haskell can't decide what a
to choose in your case. You can fix this with a simple type signature
perms :: Num a => [[a -> a]]
perms = permutations [(+1),(subtract 2),(*3)]
Upvotes: 3