Expression problem
I finished with the syntactic sugar mentioned yesterday. From last week's list, only the profiling and comprehension problem are remaining.
I started looking into the comprehension problem. I still have to think about it, because the first solution I had found is not type safe. I have the impression that to solve it I will need a 'case' operator without the 'otherwise' clause, that I don't have right now. To understand why, please read on.
To start with, here is the current algorithm:
This function evaluates an expression with only the 'constant' case (represented as variants like <#c=value>):def ^eval = fun ^exp -> case exp of <#c=^c> in c | _ in 0;
This function extends the eval function to supports the 'plus' case in expressions (represented as variants like <#p={#l=expression1,#r=expression2}>), that is adds a 'row':defrec ^eval2 = fun ^exp -> case exp of <#p={#l=^l,#r=^r}> in (eval2(l))+(eval2(r)) | ^e in eval(e);
This function adds print string capabilities to the expression, that is adds a 'column':defrec ^show2 = fun ^exp -> case exp of <#p={#l=^l,#r=^r}> in "("&show2(l)&"+"&show2(r)&")" or <#c=^c> in string_of_int(c) | _ in "";
The problem is that expressions like 'eval(<#p={#l=<#c=5>,#r=4}>);' are not detected as wrong by the typer (because eval produces a completely incorrect dummy value in case the variant is not of the right type instead of forbidding it). If eval would forbid anything else than the constant value for the variant, I believe everything would be great and working. I will think about this in more detail (and implement the case without otherwise if it makes sense to do so) tomorrow.