Changes between Version 9 and Version 10 of ExistingRecords


Ignore:
Timestamp:
Mar 5, 2006 5:15:14 PM (9 years ago)
Author:
ross@…
Comment:

formatting only

Legend:

Unmodified
Added
Removed
Modified
  • ExistingRecords

    v9 v10  
    88
    99== Update ==
    10 Update syntax should not bottom out when fields are undefined. as in
     10Update syntax should not bottom out when fields are undefined, e.g.
     11{{{
     12data Foo = Foo { x :: String, y :: Int } | Bar { x :: String }
    1113
    12    {{{
     14foo = Bar { x = "hello }
    1315
    14    data Foo = Foo { x :: String, y :: Int } | Bar { x :: String }
    15 
    16    foo = Bar { x = "hello }
    17 
    18    baz = foo { y = 3 }
    19 
    20    should not result in an error, but rather pass foo
    21    through unchanged. update should update the record
    22    if it exists, but pass the type through otherwise.
    23    This would make the update syntax actually useful
    24 
    25    }}}
     16baz = foo { y = 3 }
     17}}}
     18should not result in an error, but rather pass foo
     19through unchanged. update should update the record
     20if it exists, but pass the type through otherwise.
     21This would make the update syntax actually useful.
    2622
    2723== Label-based pattern-matching ==
    2824
    29    the function:
    30    {{{
    31      f val { x = "foo" } = 4
    32    }}}
    33    should match if passed a Foo or a Bar with x being equal to "foo" and val would be bound to its argument (like an @
     25The function:
     26{{{
     27f val { x = "foo" } = 4
     28}}}
     29should match if passed a Foo or a Bar with x being equal to "foo" and val would be bound to its argument (like an @
    3430pattern)
    35    {{{
    36     g _ { y = 3 } = 4
    37    }}}
    38    would match only the Bar constructor since it is the only one with a  y field.
     31{{{
     32g _ { y = 3 } = 4
     33}}}
     34would match only the Bar constructor since it is the only one with a  y field.
    3935
    40    This would mitigate the problems caused by accessors being partial functions since you can use a simple case statement to get the effect of an accesor that returns its result in a Maybe.
     36This would mitigate the problems caused by accessors being partial functions since you can use a simple case statement to get the effect of an accesor that returns its result in a Maybe.
    4137
    42    Note from Simon.  I hate that the above defn of 'f' has just one argument (val {x="foo")),
    43    whereas it looks as if it has two.  (This is a problem with existing Haskell.)  It looks
    44    like 'f' has an argument 'val' and another arguement that is a free-standing record,
    45    something we really want in the end anyhow.  Not sure how to fix this.  val@{x="foo")?
     38Note from Simon.  I hate that the above defn of 'f' has just one argument (val {x="foo")),
     39whereas it looks as if it has two.  (This is a problem with existing Haskell.)  It looks
     40like 'f' has an argument 'val' and another arguement that is a free-standing record,
     41something we really want in the end anyhow.  Not sure how to fix this.  `val@{x="foo")`?
    4642
    4743== First-class syntax ==
    4844First class update and setting syntax (more advanced, needs better syntax).
    4945A syntax for updating and setting fields should be allowed.  Some possibilites are
    50 
    51    {{{
    52 
    53    foo { x = }
    54 
    55    would be equivalent to (\v -> foo { x = v })
    56 
    57    foo { x \ }
    58 
    59    would be equivalent to
    60 
    61    (\f -> foo { x = case foo of _ {x} -> foo { x = f x }; _ -> foo })
    62 
    63    }}}
     46{{{
     47foo { x = }
     48}}}
     49would be equivalent to `(\v -> foo { x = v })`
     50{{{
     51foo { x \ }
     52}}}
     53would be equivalent to
     54{{{
     55(\f -> foo { x = case foo of _ {x} -> foo { x = f x }; _ -> foo })
     56}}}
    6457
    6558== Polymorphic record update ==
    6659
    67    Given a record like:
    68    {{{
    69    data Foo a = Foo { bar :: a }
    70    }}}
    71    it would be nice to be able to update it like:
    72    {{{
    73    f = Foo { bar = 'a' }
    74    g = f { bar = False }
    75    }}}
    76    Note the change in the type of the stored field.  At the moment, such a record update must be written using the
    77    data constructor, not the update syntax.
    78 
     60Given a record like:
     61{{{
     62data Foo a = Foo { bar :: a }
     63}}}
     64it would be nice to be able to update it like:
     65{{{
     66f = Foo { bar = 'a' }
     67g = f { bar = False }
     68}}}
     69Note the change in the type of the stored field.
     70At the moment, such a record update must be written using the data constructor, not the update syntax.
    7971
    8072== 'Open' statement ==
    8173
    82 having the ability to 'open' a record bringing all its values into scope would be useful for techniques such as first class modules when combined with PolymorphicComponents. a proposal is
    83 
     74Having the ability to 'open' a record bringing all its values into scope would be useful for techniques such as first class modules when combined with PolymorphicComponents. a proposal is
    8475{{{
    85 
    8676data Record = Record { foo :: Int, bar :: String }
    8777
     
    9080   open x
    9181   ans = ...
    92 
     82}}}
    9383will desugar to
    94 
     84{{{
    9585f x = ... where
    9686   Record { foo = foo } = x
    9787   Record { bar = bar } = x
    9888   ans = ...
    99 
    10089}}}
    101 
    102 open x would be allowed at the top level, in a let binding, or in a where binding.
     90`open x` would be allowed at the top level, in a let binding, or in a where binding.
    10391
    10492== Abstraction ==