Search code examples
rascal

What is the imperative model of Rascal?


Rascal feels both functional and imperative. It support assignments. But it is also claimed to be pure. So I guess features like assignments are simulated. Then what is the imperative model of Rascal, the Haskell way via monads or the Clean way via uniqueness?


Solution

  • Rascal is only pure in the sense that its data instances are immutable and in the sense that everything (function parameter passing, assignment, calling Java methods) is pass-by-value. There is no aliasing possible (*).

    Even with globals, or comparably closures that capture stack locations, all assignments are by value but they are real assignments. I.o.w. there are no monads, no uniqueness typing, just plain and direct side-effects, but no aliasing and no mutation.

    What makes side-effects into Java code in Rascal "safe" is that sending/receiving data is always via (de)serializing an immutable value, i.e. you really can not get a reference to stateful data into Rascal via Java (unless you start encoding pointers with int or loc :-)

    (*) you can create a form of aliasing using closures, but you do have to jump through a few high hoops first to do such a thing.