-
ContextI'm not a Haskell expert, but I heard that Haskell has different monads for working with stateful mutation:
Both options seem like reasonable ways of representing state-mutating operations, but (2) seems likely to have some performance benefits? QuestionDoes Koka (and its writer/state effects) support in-place mutation? What are the performance implications? Unlike Haskell, Koka has first-class effects - from Koka's documentation, it seems like the state effect is just a composition of other effects. Not supporting special-case effects seems ideal for composition with other effects and control flow.
Koka does seem to have many neat representational and implementation optimizations though (e.g. inlining |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
There are several In-place mutation strategies in Koka. Not sure whether one of the followings is what you wanted:
|
Beta Was this translation helpful? Give feedback.
-
Hi @dan-zheng ; good questions! Here are some answers:
|
Beta Was this translation helpful? Give feedback.
-
@dan-zheng Also, the following example may be useful.
@daanx , it seems that in |
Beta Was this translation helpful? Give feedback.
Hi @dan-zheng ; good questions! Here are some answers:
var
gives local variables whose lifetime is limited to their lexical scope. These are "builtin" and do in-place updating for efficiency. However, the semantics ofvar
is specified as using a regular state-effect handler (using a monadic approach) -- this makes them in practice a bit less efficient than C local variables as they are currently heap allocated (but this could be avoided though with a more sophisticated implementation I think). This is needed for giving the right semantics under multiple resumptions. I put "builtin" in quotes as the actual implementation is done in thestd/core/types
andstd/core/hnd
modules u…