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