[Haskell-beginners] Struct-like syntax issues

Sergey Mironov ierton at gmail.com
Sun Mar 14 09:54:05 EDT 2010


Hi. I have definitions like

data MyData = MyData {
  a :: A,
  b :: B,
  c :: C,
  d :: D,
  ...
  z :: Z
  }

makeMyData :: A -> B -> MyData
makeMyData a' b' = MyData {
  a = a',
  b = b',
  c = default_c,
  ...
  z = default_z
  }

The goal is to use it like

myData1 = set_x x' . set_m m' . set_c c' $ makeMyData my_a my_b
myData2 = set_z z' . $ makeMyData my_a my_b


But. Writing set_* functions is a problem - MyData is loong and things like

set_d :: D -> MyData -> MyData
set_d val struct = struct{d=val}

will form that boilerplate.  Is there any _right_ way of doing it?

myData3 = (makeMyData my_a my_b) {x=x', z=z'}  approach is not working..

-- 
Thanks,
Sergey


More information about the Beginners mailing list