wiki:ExistingRecords

Version 2 (modified by john@…, 8 years ago) (diff)

--

This 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.

  • reallow punning, Foo {x,y,z} would be interpreted as Foo {x = x, y = y, z = z} in both declaration and pattern matching contexts.
  • update syntax should not bottom out when fields are undefined. as in
data Foo = Foo { x :: String, y :: Int } | Bar { x :: String }

foo = Bar { x = "hello }

baz = foo { y = 3 }

should 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.

this would make the update syntax actually useful

  • label-based pattern matching

the function:

  f val { x = "foo" } = 4

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 @ pattern)

 g _ { y = 3 } = 4

would match only the Bar constructor since it is the only one with a y field.

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

  • first class update and setting syntax (more advanced, needs better syntax)

A syntax for updating and setting fields should be allowed.

some possibilites are

foo { x = }

would be equivalant to (\v -> foo { x = v })

foo { x \ }

would be equivalant to 

(\f -> foo { x = case foo of _ {x} -> foo { x = f x }; _ -> foo })