X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=aafe421c67cac1d260e837af53225d76e8c0259c;hb=7d7d29b6fd7967099856b6f7e0bf7ee2e7a212ea;hp=dee62f469352e2cc6995d9fcf8e0f7eb6c9127a7;hpb=177b31ca6ebe01f8011926e30c4ac7ee32791753;p=ghc-hetmet.git diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index dee62f4..aafe421 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -1990,15 +1990,28 @@ main = do display (inc (inc counterB)) -- prints "##" -At the moment, record update syntax is only supported for Haskell 98 data types, -so the following function does not work: - +Record update syntax is supported for existentials (and GADTs): --- This is invalid; use explicit NewCounter instead for now setTag :: Counter a -> a -> Counter a setTag obj t = obj{ tag = t } +The rule for record update is this: +the types of the updated fields may +mention only the universally-quantified type variables +of the data constructor. For GADTs, the field may mention only types +that appear as a simple type-variable argument in the constructor's result +type. For example: + +data T a where { T1 { f1::a, f2::(a,b) } :: T a } -- b is existential +upd1 t x = t { f1=x } -- OK: upd1 :: T a -> b -> T b +upd2 t x = t { f2=x } -- BAD (f2's type mentions b, which is + -- existentially quantified) +data G a b where { G1 { g1::a, g2::c } :: G a [c] } +upd3 g x = g { g1=x } -- OK: upd3 :: G a b -> c -> G c b +upd4 g x = g { g2=x } -- BAD (f2's type mentions c, which is not a simple + -- type-variable argument in G1's result type) +