0 | module Derive.BarbieInfo
2 | import Language.Reflection.Util
8 | data ToType : TTImp -> Type where
9 | IsToType : {k : TTImp} -> ToType (IPi f1 MW ExplicitArg n2 k (IType f3))
12 | toType : (t : TTImp) -> Maybe (ToType t)
13 | toType (IPi _ MW ExplicitArg _ k (IType _)) = Just IsToType
18 | data BarbieArgs : Vect n Arg -> Type where
22 | -> {auto prf : ToType t}
23 | -> BarbieArgs [MkArg c ExplicitArg (Just n) t]
24 | BAThere : BarbieArgs vs -> BarbieArgs (v :: vs)
27 | barbieArgs : (vs : Vect n Arg) -> Maybe (BarbieArgs vs)
28 | barbieArgs [MkArg c ExplicitArg (Just n) t] =
29 | let Just _ := toType t | Nothing => Nothing
31 | barbieArgs (x :: xs) = BAThere <$> barbieArgs xs
32 | barbieArgs [] = Nothing
36 | barbieArg : BarbieArgs vs -> Name
37 | barbieArg (BAHere {n}) = n
38 | barbieArg (BAThere x) = barbieArg x
42 | barbieKind : BarbieArgs vs -> TTImp
43 | barbieKind (BAHere @{IsToType {k}}) = k
44 | barbieKind (BAThere x) = barbieKind x
48 | record BarbieInfo where
50 | info : ParamTypeInfo
51 | prf : BarbieArgs info.info.args
54 | Named BarbieInfo where
55 | b.getName = b.info.getName
58 | hasFArg : (farg : Name) -> TTImp -> Bool
59 | hasFArg farg (IApp _ (IVar _ n) _) = farg == n
64 | (.explicitArgs) : BarbieInfo -> List Name
65 | (.explicitArgs) p = go Lin p.info.info.args p.prf p.info.info.argNames
69 | -> (vs : Vect k Arg)
73 | go snm [_] BAHere [_] = snm <>> []
74 | go snm (MkArg _ ExplicitArg _ _:: vs) (BAThere x) (n :: ns) =
75 | go (snm :< n) vs x ns
76 | go snm (v :: vs) (BAThere x) (n :: ns) = go snm vs x ns
81 | (.applied) : BarbieInfo -> TTImp
82 | (.applied) p = appNames p.getName p.explicitArgs
86 | public export %inline
87 | (.implicits) : BarbieInfo -> List Arg
88 | (.implicits) p = implicits p.explicitArgs
92 | public export %inline
93 | (.kind) : BarbieInfo -> TTImp
94 | (.kind) p = barbieKind p.prf