ordinary_recovery_declaration.bend
bendvy-ecs-core@0.1.0.4 · 77 lines · 13 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/recovery_use.bend as Use
3import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
4import bendvy-ecs-core@0.1.0.4/capabilities.bend as Cap
5import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_array_resource.bend as Frame
6
7
8
9
10
11
12def Builder(~State:Type,~Recovery:Type,~Ops:Type -> Type) -> Type:
13 @-All:Type -> @-Rest:Type -> @-path:Product.Lens<All,Recovery,Rest> -> Unit -> Ops(Frame.Frame<State,All>)
14
15
16
17
18
19
20
21
22
23type Declaration<-S:Data,-State:Type,-Recovery:Type,-Ops:Type -> Type,-builder:Builder(~State,~Recovery,~Ops)> is Type:
24 Declaration{empty:Unit -> Recovery,access:List<&2,String>}
25 Described{empty:Unit -> Recovery,access:List<&2,String>,description:Use.Description}
26
27
28
29def empty(~S:Data,~State:Type,~Recovery:Type,~Ops:Type -> Type,~builder:Builder(~State,~Recovery,~Ops),value:Declaration<S,State,Recovery,Ops,builder>) -> Unit -> Recovery:
30 match value:
31 case Declaration{empty,_}:empty
32 case Described{empty,_,_}:empty
33
34
35
36def access(~S:Data,~State:Type,~Recovery:Type,~Ops:Type -> Type,~builder:Builder(~State,~Recovery,~Ops),value:Declaration<S,State,Recovery,Ops,builder>) -> List<&2,String>:
37 match value:
38 case Declaration{_,access}:access
39 case Described{_,access,_}:access
40
41
42
43
44def description(~S:Data,~State:Type,~Recovery:Type,~Ops:Type -> Type,~builder:Builder(~State,~Recovery,~Ops),value:Declaration<S,State,Recovery,Ops,builder>) -> Use.Description:
45 match value:
46 case Declaration{_,_}:Use.none()
47 case Described{_,_,description}:description
48
49
50
51def PairOps(~L:Type -> Type,~R:Type -> Type,H:Type) -> Type:Cap.Bundle<L(H),R(H)>
52def pair_empty(~L:Type,~R:Type,~left:Unit -> L,~right:Unit -> R,unit:Unit) -> Product.Owner<L,R>:Product.Owner{left(Unit{}),right(unit)}
53def pair_grant(~S:Data,~State:Type,~L:Type,~R:Type,~LOps:Type -> Type,~ROps:Type -> Type,~left:Builder(~State,~L,~LOps),~right:Builder(~State,~R,~ROps),~All:Type,~Rest:Type,~path:Product.Lens<All,Product.Owner<L,R>,Rest>,unit:Unit) -> Cap.Bundle<LOps(Frame.Frame<State,All>),ROps(Frame.Frame<State,All>)>:
54 Cap.Bundle{left(All,Rest & R,Product.compose(~All,~Product.Owner<L,R>,~Rest,~L,~R,~path,~Product.lens(~L,~R,~Product.Left{})),Unit{}),right(All,Rest & L,Product.compose(~All,~Product.Owner<L,R>,~Rest,~R,~L,~path,~Product.lens(~L,~R,~Product.Right{})),unit)}
55
56
57
58
59
60
61
62
63
64
65
66def both(~S:Data,~State:Type,~L:Type,~R:Type,~LOps:Type -> Type,~ROps:Type -> Type,~leftBuilder:Builder(~State,~L,~LOps),~rightBuilder:Builder(~State,~R,~ROps),~left:Declaration<S,State,L,LOps,leftBuilder>,~right:Declaration<S,State,R,ROps,rightBuilder>) -> Declaration<S,State,Product.Owner<L,R>,PairOps(~LOps,~ROps),pair_grant(~S,~State,~L,~R,~LOps,~ROps,~leftBuilder,~rightBuilder)>:
67 Described{pair_empty(~L,~R,~empty(~S,~State,~L,~LOps,~leftBuilder,left),~empty(~S,~State,~R,~ROps,~rightBuilder,right)),List.append(&2,String,access(~S,~State,~L,~LOps,~leftBuilder,left),access(~S,~State,~R,~ROps,~rightBuilder,right)),Use.pair(description(~S,~State,~L,~LOps,~leftBuilder,left),description(~S,~State,~R,~ROps,~rightBuilder,right))}
68def identity_take(~R:Type,value:R) -> Unit & R:(Unit{},value)
69def identity_put(~R:Type,unit:Unit,value:R) -> R:value
70
71
72def identity(~R:Type) -> Product.Lens<R,R,Unit>:Product.Lens{identity_take(~R),identity_put(~R)}
73
74
75
76
77def root_grant(~S:Data,~State:Type,~Recovery:Type,~Ops:Type -> Type,~builder:Builder(~State,~Recovery,~Ops)) -> Ops(Frame.Frame<State,Recovery>):builder(Recovery,Unit,identity(~Recovery),Unit{})