Changes between Version 1 and Version 2 of ExistingRecords


Ignore:
Timestamp:
Nov 29, 2005 3:23:00 AM (10 years ago)
Author:
john@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExistingRecords

    v1 v2  
    11This page is used to discuss _minor_ tweaks to the existing record system if it is decided that it will be left in basically unchanged. radical or brand new record systems should be discussed elsewhere.
    22
     3 * reallow punning, Foo {x,y,z} would be interpreted as Foo {x = x, y = y, z = z} in both declaration and pattern matching contexts.
     4
     5 * update syntax should not bottom out when fields are undefined. as in
     6
     7{{{
     8
     9data Foo = Foo { x :: String, y :: Int } | Bar { x :: String }
     10
     11foo = Bar { x = "hello }
     12
     13baz = foo { y = 3 }
     14
     15should not result in an error, but rather pass foo through unchanged. update should update the record if it exists, but pass the type through otherwise.
     16
     17this would make the update syntax actually useful
     18
     19}}}
     20
     21
     22 * label-based pattern matching
     23
     24
     25
     26the function:
     27{{{
     28  f val { x = "foo" } = 4
     29}}}
     30should match if passed a Foo or a Bar with x being equal to "foo" and val would be bound to its argument (like an @ pattern)
     31{{{
     32 g _ { y = 3 } = 4
     33}}}
     34would match only the Bar constructor since it is the only one with a  y field.
     35
     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
     37
     38  * first class update and setting syntax (more advanced, needs better syntax)
     39
     40A syntax for updating and setting fields should be allowed.
     41
     42some possibilites are
     43
     44{{{
     45
     46foo { x = }
     47
     48would be equivalant to (\v -> foo { x = v })
     49
     50foo { x \ }
     51
     52would be equivalant to
     53
     54(\f -> foo { x = case foo of _ {x} -> foo { x = f x }; _ -> foo })
     55
     56
     57}}}
     58
     59
     60