RE: access to fields in nested records
One thing that bugs me about the named record syntax, is that with a datatype: data T = T { t_f1 :: X, t_f2 :: X }; the function t_f1 has the type of an "accessor", ie t_f1 :: T -> X but there doesn't any tidy way to get at the "mutator" function t_f1' :: X -> T -> T without actually having to write the following t_f1' x t = t{t_f1=x} Or is there? Actually mutators of the general form t_f1' :: (X->X) -> T -> T t_f1_ f t = t{t_f1=f (t_f1 t)}
DRiFT will let you do that, by deriving get_ and set_ methods, but other than that, no. THere was discussion about a year ago (I think) about this, with proposed syntax for something, but it never really got off the ground. You can probably google for it with my name and some other keywords -- it will likely turn up. - Hal On Thu, 6 Nov 2003, Tim Docker wrote:
One thing that bugs me about the named record syntax, is that with a datatype:
data T = T { t_f1 :: X, t_f2 :: X };
the function t_f1 has the type of an "accessor", ie
t_f1 :: T -> X
but there doesn't any tidy way to get at the "mutator" function
t_f1' :: X -> T -> T
without actually having to write the following
t_f1' x t = t{t_f1=x}
Or is there?
Actually mutators of the general form
t_f1' :: (X->X) -> T -> T t_f1_ f t = t{t_f1=f (t_f1 t)}
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
DRiFT will let you do that, by deriving get_ and set_ methods, but other than that, no. THere was discussion about a year ago (I think) about this, with proposed syntax for something, but it never really got off the ground. You can probably google for it with my name and some other keywords -- it will likely turn up.
Assuming you are referring to the discussing that I think you are referring to, I have a half-written write-up of the idea at the following URL: http://www.cl.cam.ac.uk/users/rje33/records.ps This is probably a bit more intelligible than the mailing list messages. I haven't made an attempt to implement this stuff -- I'm too busy frantically finishing my PhD. -Rob
- Hal
On Thu, 6 Nov 2003, Tim Docker wrote:
One thing that bugs me about the named record syntax, is that with a datatype:
data T = T { t_f1 :: X, t_f2 :: X };
the function t_f1 has the type of an "accessor", ie
t_f1 :: T -> X
but there doesn't any tidy way to get at the "mutator" function
t_f1' :: X -> T -> T
without actually having to write the following
t_f1' x t = t{t_f1=x}
Or is there?
Actually mutators of the general form
t_f1' :: (X->X) -> T -> T t_f1_ f t = t{t_f1=f (t_f1 t)}
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (3)
-
Hal Daume III -
Robert Ennals -
Tim Docker