As seen in #122, I'm working on adding support for system calls to Feldspar.
There are some issues related to this that I would like to discuss.
Which monad?
I'm currently (ab)using the M
monad for system calls which is not so good given that M
is for mutable data structures and that it has a run function. A better solution seems to be to define a new Sys
monad as a newtype wrapper. The core language would use the same monad for both Sys
and M
, but the interfaces would be different:
- Sys calls are only allowed in
Sys
runMutable
only works for M
The only problem I see with this is that one would have to redefine the mutable data structures for the Sys
monad, since we need references and arrays also at the system level.
Another option might be to just have a single monad, and have a static analysis that checks for sys calls under runMutable
.
Semantics
foreignCall
requires a semantic function to be provided. But I think it will be hard to model all sys calls as Haskell functions. So I suggest that we simply leave the semantics undefined for sys calls (when there is no sensible semantics to give).
Here is my motivation: Sys calls will be used to implement various system abstractions in Feldspar. These abstractions should be implemented as shallow or deep EDSLs on top of Feldspar, but their implementation should not rely on sys calls. Instead, we will provide one or more compilation functions that translate the EDSL to Feldspar programs with sys calls. But when evaluating the EDSL, we should not use the compilation function but rather a specialized evaluator for the EDSL (that calls Feldspar's eval
).
As an example, the implementation of Stream
does not use sys calls, but one can imagine a compilation function that translates a stream into a loop in the Sys
monad that uses sys calls write out the output stream.