I'm working on camlp4 extension for haskell-like do notation in Ocaml, and trying to figure out how GHC compiles recursive do-bindings (enabled with -XDoRec).
I wonder if it possible for monadic fixpoint combinator to exist in strict language (like Ocaml/F#/SML/...)?
If yes, how can it look like? Would it be very useful?
相关问题
- F#: Storing and mapping a list of functions
- Understanding do notation for simple Reader monad:
- Making Custom Instances of PersistBackend
- Haskell: What is the differrence between `Num [a]
- applying a list to an entered function to check fo
相关文章
- Is it possible to write pattern-matched functions
- Haskell underscore vs. explicit variable
- Top-level expression evaluation at compile time
- FSharp.Data.JsonProvider - Getting json from types
- Stuck in the State Monad
- Signing an F# Assembly (Strong name component)
- Learning F#: What books using other programming la
- foldr vs foldr1 usage in Haskell
The F# computation expression syntax (related to Haskell
do
) supports recursion:This is supported because the computation builder has to support
Delay
operation in addition to other monadic (or MonadPlus) operations. The code is translated to something like:The type of
Delay
is, in general,(unit -> M<'T>) -> M<'T>
and the trick is that it wraps a computation with effects (or immediate recursive reference) into a delayed computation that is evaluated on demand.If you want to learn more about how the mechanism works in F#, then the following two papers are relevant:
The first one describes how the F# computation expression syntax is desugared (and how
Delay
is inserted - and in general, how F# combines delayed and eager computations with effects) and the second one describes how F# handleslet rec
declarations with values - like theones
value above.