No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- I'm aware of and prefer pointfree style, but I am trying to be as
-- explicit as possible here

-- Base
data Base = Base { -- fields
                   baseField_0  :: B_0
                 ...
                 , baseField_n  :: B_n
                   -- mutators
                 , baseMethod_0 :: Arguments_0 ... -> Base
                 ...
                 , baseMethod_m :: Arguments_m ... -> Base
                 }

-- Foo
data FooState = FooState { fooState_0 :: F_0
                         ...
                         , fooState_l :: F_l
                         }

mkFoo :: FooState -> Base
mkFoo fs = Base (mkFooField_0 fs)... (mkFooField_n fs)
                (mkFooMethod_0 fs) ... (mkFooMethod_m fs)

-- accessors for field i of Base
mkFooField_i :: FooState -> B_i
mkFooField_i fs = ...

-- mutator for method j of Base
-- here f_j is the meat of our method
mkFooMethod_j :: FooState -> (Arguments_j ... -> Base)
mkFooMethod_j fs =
  mkFoo $ (f_j :: FooState -> Arguments_j ... -> FooState) fs