@@ -7,7 +7,7 @@ using Distributed
77# -----------------------
88
99# standard pure - fallback to TypeClass.pure
10- ExtensibleEffects. eff_pure (T, a ) = TypeClasses. pure (T, a )
10+ ExtensibleEffects. eff_pure (T, value ) = TypeClasses. pure (T, value )
1111
1212# standard eff_flatmap - fallback to map, flip_types, and flatten
1313function ExtensibleEffects. eff_flatmap (continuation, a)
1919
2020# NoEffect
2121# --------
22- ExtensibleEffects. eff_applies (handler:: Type{<:NoEffect} , value :: NoEffect ) = true
23- ExtensibleEffects. eff_pure (handler:: Type{<:NoEffect} , a ) = a
24- ExtensibleEffects. eff_flatmap (continuation, a :: NoEffect ) = continuation (a . value)
22+ ExtensibleEffects. eff_applies (handler:: Type{<:NoEffect} , effectful :: NoEffect ) = true
23+ ExtensibleEffects. eff_pure (handler:: Type{<:NoEffect} , value ) = value
24+ ExtensibleEffects. eff_flatmap (continuation, effectful :: NoEffect ) = continuation (effectful . value)
2525
2626# Identity
2727# --------
2828# we choose to Identity{T} instead of plain T to be in accordance with behaviour of syntax_flatmap
29- ExtensibleEffects. eff_applies (handler:: Type{<:Identity} , value :: Identity ) = true
30- ExtensibleEffects. eff_pure (handler:: Type{<:Identity} , a ) = Identity (a )
29+ ExtensibleEffects. eff_applies (handler:: Type{<:Identity} , effectful :: Identity ) = true
30+ ExtensibleEffects. eff_pure (handler:: Type{<:Identity} , value ) = Identity (value )
3131# Extra handling of Const so that order of executing Const or Identity handler does not matter
3232# This is especially important for ExtensibleEffects.autorun, as here it might be "random" whether we first see
3333# an Identity or a Const
34- ExtensibleEffects. eff_pure (handler:: Type{<:Identity} , a :: Const ) = a
35- ExtensibleEffects. eff_flatmap (continuation, a :: Identity ) = continuation (a . value)
34+ ExtensibleEffects. eff_pure (handler:: Type{<:Identity} , value :: Const ) = value
35+ ExtensibleEffects. eff_flatmap (continuation, effectful :: Identity ) = continuation (effectful . value)
3636
3737# Const
3838# -----
39- ExtensibleEffects. eff_applies (handler:: Type{<:Const} , value :: Const ) = true
39+ ExtensibleEffects. eff_applies (handler:: Type{<:Const} , effectful :: Const ) = true
4040# usually Const does not have a pure, however within Eff, it is totally fine,
4141# as continuations on Const never get evaluated anyways,
4242# (and eff_pure is only called at the very end, when literal values are reached)
43- ExtensibleEffects. eff_pure (handler:: Type{<:Const} , a ) = a
44- ExtensibleEffects. eff_flatmap (continuation, a :: Const ) = a
43+ ExtensibleEffects. eff_pure (handler:: Type{<:Const} , value ) = value
44+ ExtensibleEffects. eff_flatmap (continuation, effectful :: Const ) = effectful
4545
4646# Either
4747# ------
4848# with this you can use Option/Try/Either as explicit handlers within `@runhandlers` calls
49- ExtensibleEffects. eff_applies (handler:: Type{<:Either} , value :: Either ) = true
49+ ExtensibleEffects. eff_applies (handler:: Type{<:Either} , effectful :: Either ) = true
5050# eff_flatmap follows completely from Const and Identity
51- ExtensibleEffects. eff_pure (handler:: Type{<:Either} , a ) = ExtensibleEffects. eff_pure (Identity, a ) # Const would never reach this
51+ ExtensibleEffects. eff_pure (handler:: Type{<:Either} , value ) = ExtensibleEffects. eff_pure (Identity, value ) # Const would never reach this
5252
5353
5454# Iterable
5555# --------
56- ExtensibleEffects. eff_applies (handler:: Type{<:Iterable} , value :: Iterable ) = true
56+ ExtensibleEffects. eff_applies (handler:: Type{<:Iterable} , effectful :: Iterable ) = true
5757# everything else follows from the generic implementations of eff_autohandler, eff_pure and eff_flatmap
5858
5959
6060# AbstractVector
6161# --------------
62- ExtensibleEffects. eff_applies (handler:: Type{T} , value :: T ) where {T<: AbstractArray } = true
62+ ExtensibleEffects. eff_applies (handler:: Type{T} , effectful :: T ) where {T<: AbstractArray } = true
6363# eff_flatmap, eff_pure follow the generic implementation
6464
6565
6666# Future/Task
6767# -----------
68- ExtensibleEffects. eff_applies (handler:: Type{<:Task} , value :: Task ) = true
69- ExtensibleEffects. eff_applies (handler:: Type{<:Future} , value :: Future ) = true
68+ ExtensibleEffects. eff_applies (handler:: Type{<:Task} , effectful :: Task ) = true
69+ ExtensibleEffects. eff_applies (handler:: Type{<:Future} , effectful :: Future ) = true
7070# we directly interprete Task and Future
7171# finally surround interpreted expression by `@async`/`@spawnnat :any` to get back the Task/Future context
72- ExtensibleEffects. eff_pure (handler:: Type{<:Union{Task, Future}} , a ) = a
73- function ExtensibleEffects. eff_flatmap (continuation, a :: Union{Task, Future} )
74- continuation (fetch (a ))
72+ ExtensibleEffects. eff_pure (handler:: Type{<:Union{Task, Future}} , value ) = value
73+ function ExtensibleEffects. eff_flatmap (continuation, effectful :: Union{Task, Future} )
74+ continuation (fetch (effectful ))
7575end
7676
7777
7878# Writer
7979# ------
80- ExtensibleEffects. eff_applies (handler:: Type{<:Writer} , value :: Writer ) = true
80+ ExtensibleEffects. eff_applies (handler:: Type{<:Writer} , effectful :: Writer ) = true
8181function ExtensibleEffects. eff_flatmap (continuation, a:: Writer )
8282 eff_of_writer = continuation (a. value)
8383 map (eff_of_writer) do b
@@ -94,7 +94,7 @@ struct WriterHandler{Acc}
9494 pure_acc:: Acc
9595end
9696WriterHandler () = WriterHandler (neutral) # same default pure-accumulator which is also used in TypeClasses
97- ExtensibleEffects. eff_applies (handler:: WriterHandler{Acc} , value :: Writer{Acc} ) where Acc = true
97+ ExtensibleEffects. eff_applies (handler:: WriterHandler{Acc} , effectful :: Writer{Acc} ) where Acc = true
9898ExtensibleEffects. eff_pure (handler:: WriterHandler , value) = Writer (handler. pure_acc, value)
9999# autohandler and eff_flatmap are the same
100100
@@ -112,12 +112,12 @@ struct CallableHandler{Args, Kwargs}
112112 kwargs:: Kwargs
113113 CallableHandler (args... ; kwargs... ) = new {typeof(args), typeof(kwargs)} (args, kwargs)
114114end
115- ExtensibleEffects. eff_applies (handler:: CallableHandler , value :: Callable ) = true
115+ ExtensibleEffects. eff_applies (handler:: CallableHandler , effectful :: Callable ) = true
116116# we interpret callable by adding an extra Functor from the top outside, so that internally we can interpret each call
117117# by just getting args and kwargs from the context
118- ExtensibleEffects. eff_pure (handler:: CallableHandler , a ) = a
119- function ExtensibleEffects. eff_flatmap (handler:: CallableHandler , continuation, a :: Callable )
120- continuation (a (handler. args... ; handler. kwargs... ))
118+ ExtensibleEffects. eff_pure (handler:: CallableHandler , value ) = value
119+ function ExtensibleEffects. eff_flatmap (handler:: CallableHandler , continuation, effectful :: Callable )
120+ continuation (effectful (handler. args... ; handler. kwargs... ))
121121end
122122
123123"""
@@ -160,10 +160,10 @@ struct ContextManagerHandler{F}
160160 ContextManagerHandler (cont) = new {Core.Typeof(cont)} (cont)
161161end
162162
163- ExtensibleEffects. eff_applies (handler:: ContextManagerHandler , value :: ContextManager ) = true
164- ExtensibleEffects. eff_pure (handler:: ContextManagerHandler , a ) = handler. cont (a )
165- function ExtensibleEffects. eff_flatmap (:: ContextManagerHandler , continuation, c :: ContextManager )
166- result = c (continuation)
163+ ExtensibleEffects. eff_applies (handler:: ContextManagerHandler , effectful :: ContextManager ) = true
164+ ExtensibleEffects. eff_pure (handler:: ContextManagerHandler , value ) = handler. cont (value )
165+ function ExtensibleEffects. eff_flatmap (:: ContextManagerHandler , continuation, effectful :: ContextManager )
166+ result = effectful (continuation)
167167 @assert (result. effectful isa NoEffect,
168168 " ContextManager should be run after all other effects," *
169169 " however found result `$(result) ` of type $(typeof (result)) " )
@@ -267,22 +267,22 @@ function ContextManagerCombinedHandler(other_handler, func::Union{Type, Function
267267 ContextManagerCombinedHandler {Core.Typeof(other_handler), Core.Typeof(func)} (other_handler, ContextManagerHandler (func))
268268end
269269
270- function ExtensibleEffects. eff_applies (handler:: ContextManagerCombinedHandler , value )
271- eff_applies (handler. other_handler, value ) || eff_applies (handler. contextmanager_handler, value )
270+ function ExtensibleEffects. eff_applies (handler:: ContextManagerCombinedHandler , effectful )
271+ eff_applies (handler. other_handler, effectful ) || eff_applies (handler. contextmanager_handler, effectful )
272272end
273273
274- function ExtensibleEffects. eff_pure (handler:: ContextManagerCombinedHandler , a )
275- b = ExtensibleEffects. eff_pure (handler. contextmanager_handler, a )
276- ExtensibleEffects. eff_pure (handler. other_handler, b )
274+ function ExtensibleEffects. eff_pure (handler:: ContextManagerCombinedHandler , value )
275+ value′ = ExtensibleEffects. eff_pure (handler. contextmanager_handler, value )
276+ ExtensibleEffects. eff_pure (handler. other_handler, value′ )
277277end
278- function ExtensibleEffects. eff_flatmap (handler:: ContextManagerCombinedHandler , continuation, a )
279- if eff_applies (handler. other_handler, a )
280- ExtensibleEffects. eff_flatmap (handler. other_handler, continuation, a )
281- elseif eff_applies (handler. contextmanager_handler, a )
282- ExtensibleEffects. eff_flatmap (handler. contextmanager_handler, continuation, a )
278+ function ExtensibleEffects. eff_flatmap (handler:: ContextManagerCombinedHandler , continuation, effectful )
279+ if eff_applies (handler. other_handler, effectful )
280+ ExtensibleEffects. eff_flatmap (handler. other_handler, continuation, effectful )
281+ elseif eff_applies (handler. contextmanager_handler, effectful )
282+ ExtensibleEffects. eff_flatmap (handler. contextmanager_handler, continuation, effectful )
283283 else
284284 error (" ContextManagerCombinedHandler should only be eff_flatmap on values which can either be handled " *
285- " by ContextManagerHandler or by other_handler = `$(handler. other_handler) `. However got value `$a `" )
285+ " by ContextManagerHandler or by other_handler = `$(handler. other_handler) `. However got effectful `$effectful `" )
286286 end
287287end
288288
@@ -298,7 +298,7 @@ Handler for running State. Gives the initial state.
298298struct StateHandler{T}
299299 state:: T
300300end
301- ExtensibleEffects. eff_applies (handler:: StateHandler , value :: State ) = true
301+ ExtensibleEffects. eff_applies (handler:: StateHandler , effectful :: State ) = true
302302ExtensibleEffects. eff_pure (handler:: StateHandler , value) = (value, handler. state)
303303
304304# The updating of the state cannot be described by plain `eff_flatmap`.
0 commit comments