2 | import Language.Reflection.Util
13 | pmClaim : Visibility -> (fun : Name) -> (p : ParamTypeInfo) -> Decl
15 | let arg := p.applied
16 | tpe := piAll `(~(arg) -> ~(arg) -> ~(arg)) (allImplicits p "Num")
17 | in simpleClaim vis fun tpe
22 | fromIntClaim : Visibility -> (fun : Name) -> (p : ParamTypeInfo) -> Decl
23 | fromIntClaim vis fun p =
24 | let arg := p.applied
25 | tpe := piAll `(Integer -> ~(arg)) (allImplicits p "Num")
26 | in simpleClaim vis fun tpe
31 | numImplClaim : Visibility -> (impl : Name) -> (p : ParamTypeInfo) -> Decl
32 | numImplClaim v impl p = implClaimVis v impl (implType "Num" p)
38 | numImplDef : (p, m, fi, impl : Name) -> Decl
39 | numImplDef p m fi impl =
40 | def impl [patClause (var impl) (appNames "MkNum" [p,m,fi])]
42 | plus : BoundArg 2 Explicit -> TTImp
43 | plus (BA arg [x,y] _) = `(~(var x) +
~(var y))
45 | mult : BoundArg 2 Explicit -> TTImp
46 | mult (BA arg [x,y] _) = `(~(var x) *
~(var y))
48 | fromInt : BoundArg 0 Explicit -> TTImp
49 | fromInt _ = `(fromInteger n
)
52 | plusDef : Name -> Con n vs -> Decl
54 | let clause := mapArgs2 explicit (\x,y => `(~(var fun) ~(x) ~(y))) plus c
58 | multDef : Name -> Con n vs -> Decl
60 | let clause := mapArgs2 explicit (\x,y => `(~(var fun) ~(x) ~(y))) mult c
64 | fromIntDef : Name -> Con n vs -> Decl
66 | def f [patClause `(~(var f) n
) (injArgs explicit fromInt c)]
75 | NumVis : Visibility -> List Name -> ParamTypeInfo -> Res (List TopLevel)
76 | NumVis vis nms p = case p.info.cons of
78 | let mult := funName p "mult"
79 | plus := funName p "plus"
80 | fromInt := funName p "fromInt"
81 | impl := implName p "Num"
83 | [ TL (pmClaim vis plus p) (plusDef plus c)
84 | , TL (pmClaim vis mult p) (multDef mult c)
85 | , TL (fromIntClaim vis fromInt p) (fromIntDef fromInt c)
86 | , TL (numImplClaim vis impl p) (numImplDef plus mult fromInt impl)
88 | _ => failRecord "Num"
92 | Num : List Name -> ParamTypeInfo -> Res (List TopLevel)
97 | FromIntegerVis : Visibility -> List Name -> ParamTypeInfo -> Res (List TopLevel)
98 | FromIntegerVis vis nms p = case p.info.cons of
100 | let fun := the Name "fromInteger"
101 | in Right [ TL (fromIntClaim vis fun p) (fromIntDef fun c) ]
102 | _ => failRecord "fromInteger"
107 | FromInteger : List Name -> ParamTypeInfo -> Res (List TopLevel)
108 | FromInteger = FromIntegerVis Public