[Haskell] Extensible records: Static duck typing
Barney Hilken
b.hilken at ntlworld.com
Tue Feb 5 08:41:46 EST 2008
> new record (x = 3,y = 4)
> subtraction \r -> ( x = 3 | r - x)
> replacement \r -> (x := 3 | r) (equivalent to the above)
> type (x::Int,y::Char)
>
> degenerate cases:
> empty record (|)
> subtracting a label (| r - x)
>
> a record can always be determined by the presence of a '|' within
> parenthesis.
One of the advantages of the systems with richer polymorphism and more
predicates is that they need less syntax. It is possible (once you
have solved the permutation/scoping problem) to use constructors as
labels, and define all the basic operators on records as standard
Haskell functions. With this approach you can even treat labels as
"first-class citizens" and write polymorphic record zip:
labelZip :: ({n :: a} `Disjoint` {m :: b}) => n -> m -> [a] -> [b] ->
[{n :: a, m :: b}]
labelZip n m = zipWith (\x y -> {n := x, m := y})
But no-one knows whether this extra expressive power has an
unacceptable cost in terms of extra complexity, because no-one has
implemented and used these systems seriously.
Barney.
More information about the Haskell
mailing list