Reputation: 23
trying to remove an element from an abstract data type I made called Map in Haskell, I am using equality to see what key matches up in order to remove the element from the Map
data Map k v = Map {pairs::[(k, v)]} deriving (Show)
removeElement :: Eq k -> Map k v -> Map k v
removeElement key (Map pairs) = Map [x |x <- pairs,not(fst x == key)]
gives me the error :
main.hs:33:18: error:
* Expected a type, but `Eq k' has kind `Constraint'
* In the type signature:
removeElement :: Eq k -> Map k v -> Map k v
|
33 | removeElement :: Eq k -> Map k v -> Map k v
| ^^^^
<interactive>:3:1: error:
* Variable not in scope: main
* Perhaps you meant `min' (imported from Prelude)
from my understanding once establishing the Eq k, I don't have to anywhere else and I can't really comprehend what the compiler is trying to tell me, would appreciate help.
Upvotes: 2
Views: 58
Reputation: 39356
In Haskell, Eq
is not a type but is a typeclass. For typeclasses, you should use =>
rather than ->
.
You also need to add in a k
to stand for the argument you are calling key
:
removeElement :: Eq k => k -> Map k v -> Map k v
removeElement key (Map pairs) = Map [x |x <- pairs,not(fst x == key)]
Note that there is no argument that corresponds to Eq k
.
The compiler message, "Expected a type, but 'Eq k' has kind 'Constraint'", is basically saying that Eq k
is not a type, but you're trying to use it like a type.
Upvotes: 6