Wanted: local data, class, instance declarations
Manuel M T Chakravarty
chak at cse.unsw.edu.au
Wed Feb 1 21:58:15 EST 2006
Unfortunately, local instance declarations threaten the coherence
property of type classes and principle types. See for example,
``Functional pearl: implicit configurations—or, type classes reflect the
values of types'', Sect 6.1, for a bit of discussion.
So, this extension would require a very carefully thought out proposal.
> in today's Haskell, all data and instance declarations are global,
> which sometimes leads to violations of the information hiding principle.
> E. g. if there is a function sort :: Ord a => [a] -> [a],
> and I want to sort a list of items w.r.t. a specified ordering,
> then I would want to write
> let instance Ord Item where ...
> xs :: [ Item ] ; xs = ...
> in sort xs
> but I don't want to make the instance Ord Item global
> because I might need a different instance in another place,
> or there already is a global instance but I don't want it.
> So, the local instance should override an outer or global one.
> Shouldn't be too difficult, the compiler just has to insert the proper
> dictionary (the "most local" one that's visible at the call site).
> With current all-global instances, a sort function of the given type is
> not very flexible, leading to supplementary functions (sortBy),
> see "Generalized functions" e. g. in
> This is exactly a work-around for not being able
> to make local dictionaries, right?
> Best regards,
More information about the Haskell-prime