Polymorphic lists...

Ralf Laemmel ralf at cwi.nl
Wed Mar 10 21:32:39 EST 2004


MR K P SCHUPKE wrote:

>Hi Oleg, I like the polymorphic list indexed by Ints... there
>do seem to be a couple of differences between this and the list
>indexed by natural numbers.
>  
>
>...
>  
>
Agreed with these differences.
Another difference: it is initially a heterogeneous set
rather than list! (Because the instance TH a (a, x)
is for "found", and the overlapping instance
TH a (b,c) is for proceeding with the rest of the set
if a and b are not the same.) Of course, you could readily
store lists of a's rather than a's, and always use [a] as
access type rather than a. This deviation looks as follows:

instance (Show a) => TH a ([a],x) where
    ...
    alter x (xs,y) = (x:xs,y)

So a heteregeneous list would be modelled as a type-indexed
set of homogeneous lists. That's pretty close. Still cool and simple.

Ralf




More information about the Glasgow-haskell-users mailing list