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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With