access to fields in nested records

Tim Docker timd at macquarie.com.au
Thu Nov 6 02:55:41 EST 2003


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)}



More information about the Haskell mailing list