Syntax module providing the computation do-notation macro.
Usage
use Skuld.Syntax
# Now you have access to:
# - comp (inline computation block)
# - defcomp, defcompp (function definitions)Example
use Skuld.Syntax
alias Skuld.Effects.State
comp do
x <- State.get()
y = x + 1
_ <- State.put(y)
y
endDefining Functions
defcomp increment() do
x <- State.get()
_ <- State.put(x + 1)
x + 1
end
defcompp private_helper() do
ctx <- Reader.ask()
ctx.value
endQuery Syntax
For query, defquery, and defqueryp macros, use use Skuld.Query
(provided by the skuld_query package).
Syntax Reference
x <- effect()- bind the result of an effectful computationx = expr- pure variable binding (unchanged)- Last expression is auto-lifted if not already a computation
Auto-Lifting
Non-computation values are automatically wrapped in Comp.pure/1. This means:
- Final expressions don't need wrapping:
x + 1works as final line ifwithoutelseworks:_ <- if cond, do: effect()(nil auto-lifted)- Any plain value in a bind position is treated as a pure computation
See Also
Skuld.Comp.CompBlock- macro implementation detailsSkuld.Comp- core computation primitivesSkuld.Query- query do-notation macros (inskuld_querypackage)