Suppose I work with a stack computer code that can perform some simple operations (push, add, mul, dup, swap, pop, convert types) on ints and double.
Now the program I am writing takes a description in some other language and translates it into code for this stack machine. I also need to calculate the maximum stack size.
I suspect that you can use Haskell type checking to fix some errors, for example:
- popping out of an empty stack
- multiplication doubles using int multiplication
I thought I could declare, for example:
dup :: Stack (a :%: b) -> Stack (a :%: b :%: b) int2double :: Stack (a :%: SInt) -> Stack (a :%: SDouble)
etc. But then I do not know how to generate the code and calculate the size of the stack.
Is it possible to do so? And will it be easy / convenient / worth it?
types haskell correctness
mik01aj
source share