access to fields in nested records

Hal Daume III hdaume at ISI.EDU
Wed Nov 5 07:58:19 EST 2003


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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
> 

-- 
 Hal Daume III                                   | hdaume at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume



More information about the Haskell mailing list