0 | module Derive.TraversableB
2 | import Language.Reflection.Util
3 | import Derive.BarbieInfo
11 | btravTpe : (k : TTImp) -> TTImp -> TTImp
14 | {0 e : Type -> Type}
15 | -> {0 f,g : ~(k) -> Type}
16 | -> {auto _ : Applicative e
}
17 | -> ((0 a : ~(k)) -> f a
-> e
(g a
))
23 | btravClaim : Visibility -> (fun : Name) -> (p : BarbieInfo) -> Decl
24 | btravClaim vis fun p =
25 | simpleClaim vis fun $
piAll (btravTpe p.kind p.applied) p.implicits
30 | travImplClaim : Visibility -> (impl : Name) -> (p : BarbieInfo) -> Decl
31 | travImplClaim vis impl p =
32 | let tpe := piAll `(TraversableB
~(p.kind) ~(p.applied)) p.implicits
33 | in implClaimVis vis impl tpe
40 | travImplDef : (fun, impl : Name) -> Decl
41 | travImplDef fun impl =
42 | def impl [patClause (var impl) `(MkTraversableB
~(var fun))]
44 | rhs : Name -> SnocList TTImp -> TTImp
45 | rhs nm [<] = `(Prelude.pure
~(var nm))
46 | rhs nm (sx :< x) = `(Prelude.(<*>)
~(rhs nm sx) ~(x))
48 | parameters (farg : Name)
50 | arg : BoundArg 1 Regular -> TTImp
52 | if hasFArg farg g.type
53 | then `(fun
_ ~(var x))
54 | else `(pure
~(var x))
57 | travClauses : (fun : Name) -> TypeInfo -> List Clause
58 | travClauses fun ti = map clause ti.cons
61 | clause : Con ti.arty ti.args -> Clause
63 | accumArgs regular (\x => `(~(var fun) fun
~(x))) (rhs c.name) arg c
66 | travDef : Name -> TypeInfo -> Decl
67 | travDef fun ti = def fun (travClauses fun ti)
76 | TraversableBVis : Visibility -> List Name -> ParamTypeInfo -> Res (List TopLevel)
77 | TraversableBVis vis nms p = case barbieArgs p.info.args of
79 | let fun := funName p "btrav"
80 | impl := implName p "TraversableB"
81 | farg := barbieArg prf
84 | [ TL (btravClaim vis fun bti) (travDef (barbieArg prf) fun p.info)
85 | , TL (travImplClaim vis impl bti) (travImplDef fun impl)
87 | Nothing => Left $
"Not a barbie type"
91 | TraversableB : List Name -> ParamTypeInfo -> Res (List TopLevel)
92 | TraversableB = TraversableBVis Public