Changes between Version 13 and Version 14 of ExtensibleRecords


Ignore:
Timestamp:
Nov 12, 2007 10:45:20 PM (8 years ago)
Author:
guest
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExtensibleRecords

    v13 v14  
    8181Please put examples here, if possible using the above notation. The aim is to find out which features of the various systems are important in practice, so uncontrived examples which illustrate differences between the systems are wanted!
    8282
    83  1 An example to show the need for extra polymorphism in unpermuted records:
     83An example to show the need for extra polymorphism in unpermuted records:
    8484{{{
    85 type Point = {x :: Float, y :: Float}
     85type Point = {X :: Float, Y :: Float}
    8686
    8787norm :: Point -> Float
    88 norm p = sqrt (p.x * p.x + p.y * p.y)
     88norm p = sqrt (p.X * p.X + p.Y * p.Y)
    8989
    90 norm {y = 3.0, x = 4.0}    -- this is a type error
     90norm {Y = 3.0, X = 4.0}    -- this is a type error, because X and Y are in the wrong order
    9191
    92 norm' :: (Select x a Float, Select y a Float) => a -> Float
    93 norm' p = sqrt (p.x * p.x + p.y * p.y)
     92norm' :: (Select X a Float, Select Y a Float) => a -> Float
     93norm' p = sqrt (p.X * p.X + p.Y * p.Y)
    9494
    95 norm' {y = 3.0, x = 4.0}    -- this is OK
     95norm' {Y = 3.0, X = 4.0}    -- this is OK, because norm' is polymorphic
    9696}}}
    9797
     98The more complex systems support first class labels. Here is an example using the Type Families system:
     99{{{
     100labelZip :: ({n :: a} `Disjoint` {m :: b}) => n -> m -> [a] -> [b] -> [{n :: a, m :: b}]
     101labelZip n m = zipWith (\x y -> {n = x, m = y})
     102}}}
     103