Proposal: Add &&& and *** to Data.Tuple
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Thu Sep 20 10:31:41 EDT 2007
Ian Lynagh <igloo at earth.li> writes:
> On Mon, Sep 17, 2007 at 07:47:33PM +0100, Jon Fairbairn wrote:
>> This seems to be a recurrent problem, and I keep wondering
>> whether there might not be a general solution along the
>> lines of declaring that an instance of a class at a
>> particular type subsumes the functions declared with those
>> names at the specialised type.
>
> An interesting idea; I'm not sure, but I think it might help us have
> code in the logical place in the base library without import loops.
>
> The only ugliness I see is that if I have
>
> module I where
> x :: Int
> x = 5
>
> module B where
> x :: Bool
> x = True
>
> module C where
> import I
> import B
>
> class C a where
> x :: a
>
> instance C Int where
> x subsumes I.x
>
> instance C Bool where
> x subsumes B.x
>
> then importing I and B but not C could lead to confusion and ambiguity.
I don't see how, or at least, I don't see how my suggestion
would make the situation worse -- if you import I and B,
you'd get the same problem as you currently do in the
absence of this subsumption mechanism. Indeed, importing C
with its subsuming instances is a solution to this
particular problem.
A slightly knottier case is if
module D where
x :: Int
x = 4
and someone attempts to import A, D and C -- but I think it
would be straightforeardly rejected, requiring x to be
hidden (or imported qualified) from D.
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Libraries
mailing list