So I have this class:
class Collection c where
empty :: c key value
singleton :: key -> value -> c key value
insert :: Ord key => key -> value -> c key value -> c key value
looKup :: Ord key => key -> c key value -> Maybe value
delete :: Ord key => key -> c key value -> c key value
keys :: c key value -> [key]
keys x = map fst $ toList x
values :: c key value -> [value]
values c = map snd $ toList c
toList :: c key value -> [(key, value)]
fromList :: Ord key => [(key,value)] -> c key value
fromList [] = empty
fromList ((k, v):xs) = insert k v (fromList xs)
Why is this
instance Collection (PairList k v) where
a bad instantion of the class and this:
instance Collection PairList where
is a good one ?
I know that when making maybe an instance of Eq, this is how haskell does it:
instance Eq (Maybe m) where
Just x == Just y = x == y
Nothing == Nothing = True
_ == _ = False
So instantiations accept parameters... So why is the first one like so ?
instance Functor Maybeis correct rather thaninstance Functor (Maybe a)?*is I believe deprecated in some sense and we're supposed to call itTypenow. But you'll definitely see people refer to*often enough, including in @chepner's answer, so it's useful to know that that means the same thing.)