0
votes

im currently looking into haskell. I know that i have to make datatypes an instance of Eq in order to compare them. But Int should already be comparable right ? So i dnt know how to handle the following Error:

• No instance for (Eq (Int -> Int)) arising from a use of ‘==’ (maybe you haven't applied a function to enough arguments?)

My Code is as follows:

myRandomList = [1,2,3,4,5,6,7,8,9,10]


myFilterList :: [Int] -> [Int]
myFilterList [] = []
myFilterList (x:xs)
        | mod x == 0 = x : myFilterList xs
        | otherwise = myFilterList xs


myDotFunc = map (+ 1) . myFilterList . myRandomList  

Ps: Im not even sure, if my code would work without this error, please remember that i just started haskell :)

1
Well mod x is not a number, you need to provide an extra argument.Willem Van Onsem
Doesn't it say more about location?max630
Moreover myRandomList is not a function, myDotFunc should probably be myDotFunc = map (+1) . myFilterList instead.Regis Kuckaertz
Why is this being downvoted? It's not a bad question.AJF

1 Answers

2
votes

You've only given mod one argument, in this line:

        | mod x == 0 = x : myFilterList xs
--        ^^^^^ HERE

So it looks like you're trying to compare functions. You might notice that GHC tells you this in the error:

No instance for (Eq (Int -> Int)) arising from a use of ‘==’ (maybe you haven't applied a function to enough arguments?)

I should be mod x y, where y is the modulo (the 'divider'). I don't know what you want y to be, though, So I can't correct your code.