I want to define the following Mapping class:
{-# LANGUAGE MultiParamTypeClasses #-} class Mapping kvm where empty :: mv insert :: k -> v -> mv -> mv search :: k -> mv -> Maybe v delete :: k -> mv -> mv
One Mapping Instance - Data.Map.Map
{-# LANGUAGE ..., FlexibleInstances #-} instance Ord k => Mapping kv (Map.Map k) where empty = Map.empty search = Map.lookup insert = Map.insert delete = Map.delete
And now I want to create the type Trie :: * -> * -> * -> * , for example
{-
So far so good, now I also want to define Trie insert and empty and that I get into problems.
I will discuss empty because it is simpler and insert needs it anyway .. If I try this:
instance Mapping k (Trie mkv) m => Mapping [k] v (Trie mk) where empty = Trie { trValue = Nothing, trChildren = empty } ...
and this makes me get the following error:
Could not deduce (Mapping k (Trie m k1 v) (m k1)) from the context (Mapping [k1] v (Trie m k1), Mapping k1 (Trie m k1 v) (m k1)) arising from a use of `empty' at test.hs:27:49-53 Possible fix: add (Mapping k (Trie m k1 v) (m k1)) to the context of the instance declaration or add an instance declaration for (Mapping k (Trie m k1 v) (m k1)) In the `trChildren' field of a record In the expression: Trie {trValue = Nothing, trChildren = empty} In the definition of `empty': empty = Trie {trValue = Nothing, trChildren = empty}
I tried and tried to solve it, but could not.
Does anyone know how to make it work? Is it possible?
haskell typeclass
yairchu
source share