[Haskell-cafe] Re: working Edison, a couple of collection modules,
and typing troubles
Samuel Bronson
naesten at gmail.com
Thu May 26 20:27:06 EDT 2005
On 26/05/05, oleg at pobox.com <oleg at pobox.com> wrote:
>
> Samuel Bronson wrote:
>
> > I was trying my hand at writing some collection classes myself and I
> > can't figure out a good typing for map that will let me make Map an
> > instance of my Collection class...
> > I don't much like the head of Mapping.
>
> How about the following:
>
> > class Collection (d k e) (k, e) => Mapping d k e where
> > -- * Query
> > lookup :: (Monad m) => k -> d k e -> m e
> >
> > instance Ord k => Collection (M.Map k e) (k, e) where
> > null = M.null
> > empty = M.empty
> > <elided>
> >
> > instance Ord k => Mapping M.Map k e where
> > lookup = M.lookup
>
> A higher-ranked type constructor gets rid of functional
> dependencies. The drawback of course is trying to use something like
> Integer as a mapping from Int to Bool. We have to declare a wrapper
This also doesn't seem like it would work very well with making an
instance for IntMap.
I guess I can't have everything.
What do you suggest that I do for map? What sort of class should it be
in? I'd like it to be able to do (a -> b) -> [a] -> [b] and such... I
had been thinking of having ((k, e) -> (k', e')) -> Map k e -> Map k'
e', but now it occurs to me that changing key types doesn't make any
sense.
More information about the Haskell-Cafe
mailing list