0 | module Derive.FunctorB
2 | import Language.Reflection.Util
3 | import Derive.BarbieInfo
11 | bmapTpe : (k : TTImp) -> TTImp -> TTImp
14 | {0 f,g : ~(k) -> Type}
15 | -> ((0 a : ~(k)) -> f a
-> g a
)
21 | bmapClaim : Visibility -> (fun : Name) -> (p : BarbieInfo) -> Decl
22 | bmapClaim vis fun p =
23 | simpleClaim vis fun $
piAll (bmapTpe p.kind p.applied) p.implicits
28 | functorImplClaim : Visibility -> (impl : Name) -> (p : BarbieInfo) -> Decl
29 | functorImplClaim vis impl p =
30 | let tpe := piAll `(FunctorB
~(p.kind) ~(p.applied)) p.implicits
31 | in implClaimVis vis impl tpe
38 | functorImplDef : (fun, impl : Name) -> Decl
39 | functorImplDef fun impl =
40 | def impl [patClause (var impl) (var "MkFunctorB" `app` var fun)]
42 | parameters (farg : Name)
44 | arg : BoundArg 1 Regular -> TTImp
46 | if hasFArg farg g.type then `(fun
_ ~(var x)) else var x
49 | functorClauses : (fun : Name) -> TypeInfo -> List Clause
50 | functorClauses fun ti = map clause ti.cons
52 | clause : Con ti.arty ti.args -> Clause
53 | clause = mapArgs regular (\x => `(~(var fun) fun
~(x))) arg
56 | functorDef : Name -> TypeInfo -> Decl
57 | functorDef fun ti = def fun (functorClauses fun ti)
66 | FunctorBVis : Visibility -> List Name -> ParamTypeInfo -> Res (List TopLevel)
67 | FunctorBVis vis nms p = case barbieArgs p.info.args of
69 | let fun := funName p "bmap"
70 | impl := implName p "FunctorB"
71 | farg := barbieArg prf
74 | [ TL (bmapClaim vis fun bti) (functorDef (barbieArg prf) fun p.info)
75 | , TL (functorImplClaim vis impl bti) (functorImplDef fun impl)
77 | Nothing => Left $
"Not a barbie type"
81 | FunctorB : List Name -> ParamTypeInfo -> Res (List TopLevel)
82 | FunctorB = FunctorBVis Public