execution_effects.bend

bendvy-ecs-core@0.1.0.3 · 28 lines · 12 definitions

1import Base
2
3def Pure(~F:Type -> Type) -> Type:
4  @-R:Type -> R -> F(R)
5def Bind(~F:Type -> Type) -> Type:
6  @-A:Type -> @-B:Type -> F(A) -> (A -> F(B)) -> F(B)
7def Mapping(~F:Type -> Type) -> Type:
8  @-A:Type -> @-B:Type -> F(A) -> (A -> B) -> F(B)
9
10type Effects<-F:Type -> Type> is Type:
11  Effects{pure:Pure(~F),bind:Bind(~F),map:Mapping(~F)}
12
13def pure(~F:Type -> Type,-R:Type,effects:Effects<F>,value:R) -> F(R):
14  match effects:
15    case Effects{pure,_,_}:pure(R,value)
16def bind(~F:Type -> Type,-A:Type,-B:Type,effects:Effects<F>,action:F(A),next:A -> F(B)) -> F(B):
17  match effects:
18    case Effects{_,bind,_}:bind(A,B,action,next)
19def map(~F:Type -> Type,-A:Type,-B:Type,effects:Effects<F>,action:F(A),next:A -> B) -> F(B):
20  match effects:
21    case Effects{_,_,map}:map(A,B,action,next)
22
23def Identity(R:Type) -> Type:R
24def identity_pure(-R:Type,value:R) -> R:value
25def identity_bind(-A:Type,-B:Type,value:A,next:A -> B) -> B:next(value)
26def identity_map(-A:Type,-B:Type,value:A,next:A -> B) -> B:next(value)
27def identity() -> Effects<Identity>:
28  Effects{identity_pure,identity_bind,identity_map}