@@ -15,10 +15,10 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
1515
1616 /** For the processed model, return generated code artifacts for solution. */
1717 def generatedCode (): Seq [HaskellWithPath ] = {
18- getModel.inChronologicalOrder.map(m => generateEvolution(m)) :+
19- generateDataTypes(flat)
20- }
2118
19+ helperClasses() ++
20+ getModel.inChronologicalOrder.map(m => generateEvolution(m))
21+ }
2222
2323 /** Combined string from the types. */
2424 def extTypeDeclaration (m: Model ): String = {
@@ -32,18 +32,11 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
3232 /** Combined string from the types. */
3333 def extDeclaration (m: Model ): String = {
3434 " Ext_" + m.name.capitalize
35- // onlyTypes(m) + "Ext"
3635 }
3736
3837 /** Exp defined solely by types. */
3938 def expDeclaration (m: Model ): String = {
40-
4139 domain.baseTypeRep.name + " _" + m.name.capitalize
42- // if (m.last.isEmpty) {
43- // domain.baseTypeRep.name
44- // } else {
45- // onlyTypes(m) + domain.baseTypeRep.name
46- // }
4740 }
4841
4942 /**
@@ -55,6 +48,7 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
5548 */
5649 def generateOp (m: Model , op: Operation ) : Haskell = {
5750 val mcaps = m.name.capitalize // haskell needs data to be capitalized!
51+
5852 val baseDomain = domain.baseTypeRep.name
5953 val name = op.name
6054
@@ -67,23 +61,31 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
6761 case u : Unary => s " $name${expDeclaration(m)} helpWith "
6862 case _ => s " $name${expDeclaration(m)} _ "
6963 }
70- val rest0 = s " ( ${exp.name.capitalize} ${standardArgs(exp).getCode}) = " + logic(exp)(op).mkString(" \n " )
71-
72- // be sure to append "_Mi" to the end of every Exp
73- val rest = rest0.replace(" helpWith " , s " _ $mcaps helpWith " )
7464
75- val modifiedRest = if (! m.last.isEmpty) {
65+ val modifiedRest = { // if (!m.last.isEmpty)
7666 // must embed 'help' properly, if needed
7767 val code = logic(exp)(op).mkString(" \n " )
7868 if (code.contains(" helpWith " )) {
79- s """ ( ${exp.name.capitalize} ${standardArgs(exp).getCode}) =
80- # let help = $name${expDeclaration(m)} helpWith in
81- # ${code.replace(" helpWith " , " help " )}""" .stripMargin('#' )
69+ val prior = m.last.name.capitalize
70+
71+ // old: let help = $name${expDeclaration(m.last)} ($name${expDeclaration(m)} helpWith) in
72+
73+
74+ if (! m.last.isEmpty) {
75+ val invoke = m.inChronologicalOrder.reverse.tail.foldLeft(s " ( ${op.name}${expDeclaration(m)} helpWith) " )((former,tail) =>
76+ s " ( ${op.name}${expDeclaration(tail)} $former) " )
77+
78+ s """ ( ${exp.name.capitalize} ${standardArgs(exp).getCode}) =
79+ # let help = $invoke in
80+ # ${code.replace(s " $name${domain.baseTypeRep.name} helpWith " , " help " )}""" .stripMargin('#' )
81+ } else {
82+ s """ ( ${exp.name.capitalize} ${standardArgs(exp).getCode}) =
83+ # let help = $name${expDeclaration(m)} helpWith in
84+ # ${code.replace(s " $name${domain.baseTypeRep.name} helpWith " , " help " )}""" .stripMargin('#' )
85+ }
8286 } else {
83- rest
87+ s " ( ${exp.name.capitalize} ${standardArgs(exp).getCode} ) = " + logic(exp)(op).mkString( " \n " )
8488 }
85- } else {
86- rest
8789 }
8890 head + modifiedRest
8991 }).mkString(" \n " )
@@ -106,12 +108,20 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
106108 header
107109 }
108110
109- // only the evolution that defines this opration needs this declaration
110- val baseDeclaration = if (m.ops.contains(op)) {
111- s " $name${domain.baseTypeRep.name} = $name${expDeclaration(m)} -- define for future extensions "
112- } else {
113- " "
114- }
111+ // if we define new operations, we must expand as provided
112+ val invocation = { // if (m.ops.nonEmpty) {
113+ // FIX HERE
114+ val invoke = m.inChronologicalOrder.reverse.tail.foldLeft(s " ( ${op.name}${expDeclaration(m)} helpWith ${op.name.capitalize}$mcaps) " )((former,tail) =>
115+ s " ( ${op.name}${expDeclaration(tail)} $former) " )
116+
117+ s """ # ${op.name}$baseDomain$mcaps :: ${expDeclaration(m.base())} $mcaps -> ${typeConverter(op.returnType.get)}
118+ # ${op.name}$baseDomain$mcaps e = $invoke e
119+ # """ .stripMargin('#' )
120+ } // else {
121+ // s"""#${op.name}$baseDomain$mcaps :: ${expDeclaration(m)} $mcaps -> ${typeConverter(op.returnType.get)}
122+ // #${op.name}$baseDomain$mcaps e = ${op.name}${expDeclaration(m)} helpWith${op.name.capitalize}$mcaps e
123+ // #""".stripMargin('#')
124+ // }
115125
116126 new Haskell (s """
117127 #-- | Evaluates expression.
@@ -121,19 +131,20 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
121131 # -> ${expDeclaration(m)} f
122132 # -- ^ The expression to evaluate
123133 # -> $returnType
134+ #
124135 # $inner
125136 # $name${expDeclaration(m)} helpWith ( ${extDeclaration(m)} inner) = helpWith inner
126- # $baseDeclaration
127- #-- | Helps with extensions $mcaps
128- #helpWith ${op.name.capitalize}$mcaps :: $previous -> ${typeConverter(op.returnType.get)}
129- #helpWith ${op.name.capitalize}$mcaps = absurd
130137 #
131138 #-- | Evaluates an $mcaps expression
132139 #-- | Calls ${op.name}$baseDomain with the $mcaps helper
133- # ${op.name}$baseDomain$mcaps :: ${expDeclaration(m)} $mcaps -> ${typeConverter(op.returnType.get)}
134- # ${op.name}$baseDomain$mcaps e = ${op.name}${expDeclaration(m)} helpWith ${op.name.capitalize}$mcaps e
140+ # $invocation
141+ #
142+ #-- | Helps with extensions $mcaps
143+ #helpWith ${op.name.capitalize}$mcaps :: Void -> ${typeConverter(op.returnType.get)}
144+ #helpWith ${op.name.capitalize}$mcaps = absurd
145+ #
135146 # """ .stripMargin('#' ))
136- }
147+ } // Void had been $previous
137148
138149 def generateData (m: Model ): Haskell = {
139150 val mcaps = m.name.capitalize // haskell needs data to be capitalized!
@@ -147,6 +158,11 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
147158 }
148159 ).mkString(" \n | " )
149160
161+ val priorOps : String = if (m.ops.nonEmpty) {
162+ m.inChronologicalOrder.reverse.tail.reverse.flatMap(priorM => {
163+ m.ops.map(op => s " -- ${priorM.name.capitalize} part for ${op.name}\n " + generateOp(priorM, op) + s " -- DONE ${priorM.name.capitalize} part \n " )}).mkString(" \n " )
164+ } else { " " }
165+
150166 val ops : String = m.ops.map(op => generateOp(m, op)).mkString(" \n " )
151167
152168 var pastExtensions : String = " "
@@ -179,6 +195,7 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
179195 #-- | of Exp used for this evolution.
180196 #type family ${extTypeDeclaration(m)} f
181197 #
198+ # $priorOps
182199 # $ops
183200 #
184201 #-- Evolution $mcaps
@@ -189,6 +206,7 @@ trait GrowGenerator extends HaskellGenerator with StandardHaskellBinaryMethod wi
189206 # $pastExtensions
190207 #type instance ${extTypeDeclaration(m)} $mcaps = Void
191208 #
209+ #
192210 # $pastOps
193211 # """ .stripMargin('#' )) // HACK: Issue with "|"
194212 }
0 commit comments