3 | import Language.Reflection.Util
14 | ordClaim : Visibility -> (fun : Name) -> (p : ParamTypeInfo) -> Decl
15 | ordClaim vis fun p =
16 | let arg := p.applied
17 | tpe := piAll `(~(arg) -> ~(arg) -> Ordering
) (allImplicits p "Ord")
18 | in simpleClaim vis fun tpe
23 | ordImplClaim : Visibility -> (impl : Name) -> (p : ParamTypeInfo) -> Decl
24 | ordImplClaim v impl p = implClaimVis v impl (implType "Ord" p)
31 | ordImplDef : (fun, impl : Name) -> Decl
32 | ordImplDef fun impl =
33 | def impl [patClause (var impl) (var "mkOrd" `app` var fun)]
35 | ordEnumDef : (impl, ci : Name) -> Decl
37 | def i [patClause (var i) `(mkOrd $
\x,y => compare
(~(var c) x
) (~(var c) y
))]
42 | rhs : SnocList TTImp -> TTImp
44 | rhs (sx :< x) = foldr (\e,acc => `(case ~(e) of {EQ
=> ~(acc); o
=> o}
)) x sx
48 | catchAll : (ci : Name) -> (fun : Name) -> TypeInfo -> List Clause
49 | catchAll ci fun ti =
51 | in if length ti.cons > 1
52 | then [patClause `(~(var fun) x y
) `(compare
(~(civ) x
) (~(civ) y
))]
55 | parameters (nms : List Name)
56 | arg : BoundArg 2 Regular -> TTImp
57 | arg (BA g [x,y] _) = assertIfRec nms g.type `(compare
~(var x) ~(var y))
64 | ordClauses : (ci, fun : Name) -> (t : TypeInfo) -> List Clause
65 | ordClauses ci fun ti = map clause ti.cons ++ catchAll ci fun ti
68 | clause : Con ti.arty ti.args -> Clause
69 | clause = accumArgs2 regular (\x,y => `(~(var fun) ~(x) ~(y))) rhs arg
74 | ordDef : (ci, fun : Name) -> TypeInfo -> Decl
75 | ordDef ci fun ti = def fun (ordClauses ci fun ti)
83 | OrdVis : Visibility -> List Name -> ParamTypeInfo -> Res (List TopLevel)
84 | OrdVis vis nms p = case isEnum p.info of
86 | let impl := implName p "Ord"
87 | ci := conIndexName p
88 | in Right [ TL (ordImplClaim vis impl p) (ordEnumDef impl ci) ]
90 | let ci := conIndexName p
91 | pre := if length p.cons > 1 then ConIndexVis vis nms p else Right []
92 | fun := funName p "ord"
93 | impl := implName p "Ord"
97 | [ TL (ordClaim vis fun p) (ordDef nms ci fun p.info)
98 | , TL (ordImplClaim vis impl p) (ordImplDef fun impl)
104 | Ord : List Name -> ParamTypeInfo -> Res (List TopLevel)
105 | Ord = OrdVis Public