0 | ||| Logic for generating all necessary claims
  1 | module Deriving.SpecialiseData.Codegen.Claims
  2 |
  3 | import Deriving.SpecialiseData.Common
  4 | import Deriving.SpecialiseData.Helpers
  5 | import Deriving.SpecialiseData.Task
  6 | import Deriving.SpecialiseData.TaskFormation
  7 | import Deriving.SpecialiseData.Unification
  8 | import Deriving.SpecialiseData.Utils.Quantifiers
  9 | import Deriving.SpecialiseData.Utils.TypeInfo
 10 | import Language.Reflection.Compat
 11 | import Language.Reflection.Expr
 12 |
 13 | ------------------------
 14 | --- CLAIM DERIVATION ---
 15 | ------------------------
 16 |
 17 | parameters (t : SpecTask)
 18 |   ||| Generate specialised to polimorphic type conversion function signature
 19 |   export
 20 |   mkMToPImplClaim : Decl
 21 |   mkMToPImplClaim = public' "mToPImpl" $ forallMTArgs t $ arg t.specInvocation .-> t.fullInvocation
 22 |
 23 |   ||| Generate specialised to polimorphic cast signature
 24 |   export
 25 |   mkMToPClaim : Decl
 26 |   mkMToPClaim = interfaceHint Public "mToP" $ forallMTArgs t $ `(Cast ~(t.specInvocation) ~(t.fullInvocation))
 27 |
 28 |   ||| Decidable equality signatures
 29 |   export
 30 |   mkDecEqImplClaim : Decl
 31 |   mkDecEqImplClaim =
 32 |     let tInv = t.specInvocation
 33 |     in public' "decEqImpl" $ forallMTArgs t $
 34 |       piAll
 35 |         `(Dec (Equal {a = ~tInv} {b = ~tInv} x1 x2))
 36 |         [ MkArg MW AutoImplicit Nothing `(DecEq ~(t.fullInvocation))
 37 |         , MkArg MW ExplicitArg (Just "x1") tInv
 38 |         , MkArg MW ExplicitArg (Just "x2") tInv
 39 |         ]
 40 |
 41 |   export
 42 |   mkDecEqClaim : Decl
 43 |   mkDecEqClaim = interfaceHint Public "decEq'" $ forallMTArgs t `(DecEq ~(t.fullInvocation) => DecEq ~(t.specInvocation))
 44 |
 45 |   export
 46 |   mkShowClaims : List Decl
 47 |   mkShowClaims =
 48 |     [ public' "showImpl" $
 49 |       forallMTArgs t
 50 |         `(Show ~(t.fullInvocation) => ~(t.specInvocation) -> String)
 51 |     , public' "showPrecImpl" $
 52 |       forallMTArgs t
 53 |         `(Show ~(t.fullInvocation) => Prec -> ~(t.specInvocation) -> String)
 54 |     , interfaceHint Public "show'" $ forallMTArgs t $
 55 |       `(Show ~(t.fullInvocation) => Show ~(t.specInvocation))
 56 |     ]
 57 |
 58 |   export
 59 |   mkEqClaims : List Decl
 60 |   mkEqClaims = do
 61 |     let tInv = t.specInvocation
 62 |     [ public' "eqImpl" $ forallMTArgs t
 63 |         `(Eq ~(t.fullInvocation) => ~tInv -> ~tInv -> Bool)
 64 |     , public' "neqImpl" $ forallMTArgs t
 65 |         `(Eq ~(t.fullInvocation) => ~tInv -> ~tInv -> Bool)
 66 |     , interfaceHint Public "eq'" $ forallMTArgs t $
 67 |         `(Eq ~(t.fullInvocation) => Eq ~tInv)
 68 |     ]
 69 |
 70 |   ||| Generate specialised to polymorphic type conversion function signature
 71 |   export
 72 |   mkPToMImplClaim : Decl
 73 |   mkPToMImplClaim = public' "pToMImpl" $ forallMTArgs t $ arg t.fullInvocation .-> t.specInvocation
 74 |
 75 |   ||| Generate specialised to polimorphic cast signature
 76 |   export
 77 |   mkPToMClaim : Decl
 78 |   mkPToMClaim =
 79 |     interfaceHint Public "pToM" $ forallMTArgs t $ `(Cast ~(t.fullInvocation) ~(t.specInvocation))
 80 |
 81 |   export
 82 |   mkFromStringClaims : List Decl
 83 |   mkFromStringClaims = do
 84 |     let tInv = t.specInvocation
 85 |     [ public' "fromStringImpl" $
 86 |         forallMTArgs t
 87 |           `(FromString ~(t.fullInvocation) => String -> ~tInv)
 88 |     , interfaceHint Public "fromString'" $
 89 |         forallMTArgs t `(FromString ~(t.fullInvocation) => FromString ~tInv)
 90 |     ]
 91 |
 92 |   export
 93 |   mkNumClaims : List Decl
 94 |   mkNumClaims = do
 95 |     let tInv = t.specInvocation
 96 |     [ public' "numImpl" $
 97 |         forallMTArgs t
 98 |           `(Num ~(t.fullInvocation) => Integer -> ~tInv)
 99 |     , public' "plusImpl" $
100 |         forallMTArgs t
101 |           `(Num ~(t.fullInvocation) => ~tInv -> ~tInv -> ~tInv)
102 |     , public' "starImpl" $
103 |         forallMTArgs t
104 |           `(Num ~(t.fullInvocation) => ~tInv -> ~tInv -> ~tInv)
105 |     , interfaceHint Public "num'" $
106 |         forallMTArgs t `(Num ~(t.fullInvocation) => Num ~tInv)
107 |     ]
108 |
109 |   export
110 |   standardClaims : List Decl
111 |   standardClaims =
112 |     [ mkMToPImplClaim
113 |     , mkMToPClaim
114 |     , mkDecEqImplClaim
115 |     , mkDecEqClaim
116 |     ] ++ join
117 |       [ mkShowClaims
118 |       , mkEqClaims
119 |       ]
120 |
121 |   export
122 |   decidedClaims : List Decl
123 |   decidedClaims =
124 |     [ mkPToMImplClaim
125 |     , mkPToMClaim
126 |     ] ++ join
127 |       [ mkFromStringClaims
128 |       , mkNumClaims
129 |       ]
130 |