Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Error: Non type-variable argument in the constraint: Num (a -> a -> a -> a)

I'm new to Haskell and am trying to run the following example code from my book:

entire file:

-- my name

splitAt1   ::  [a] -> ([a], [a])
splitAt1 xs = (take 2 xs, drop 2 xs) 

I'm testing by running the line:

splitAt1 [1 2 3 4]

The idea is that the input array is split into two arrays at the index 2. However, I am getting the following error:

Non type-variable argument
  in the constraint: Num (a -> a -> a -> a)
(Use FlexibleContexts to permit this)
When checking that ‘it’ has the inferred type
  it :: forall a a1 a2 a3.
        (Num a1, Num a2, Num a3, Num (a1 -> a2 -> a3 -> a)) =>
        ([a], [a])

Could anyone help me decode the error message and perhaps what is wrong with the code?

like image 775
jblakeley Avatar asked Nov 04 '15 06:11

jblakeley


1 Answers

The function is fine, it's your argument that's off.

Try splitAt1 [1,2,3,4] instead of splitAt1 [1 2 3 4] and it should work.

like image 168
Ben Kugler Avatar answered Oct 18 '22 03:10

Ben Kugler