1 | module Deriving.SpecialiseData.Unification
3 | import public Data.DPair
4 | import Deriving.SpecialiseData.Task
5 | import Deriving.SpecialiseData.Helpers
6 | import Deriving.SpecialiseData.Utils.Quantifiers
7 | import public Language.Reflection.Unify
16 | UniResults = List UnificationVerdict
18 | parameters (t : SpecTask)
22 | (f : (pCon : Con) ->
23 | (0 _ : ConArgsNamed pCon) =>
27 | let adp = pushIn t.polyTy.cons t.polyTyNamed.tyConArgsNamed
28 | map (\(Element c pc) => f c) adp
33 | (f : UnificationResult ->
35 | (0 _ : ConArgsNamed pCon) =>
41 | let adp = pushIn t.polyTy.cons t.polyTyNamed.tyConArgsNamed
42 | let f' : List (Subset Con ConArgsNamed) -> UniResults -> Nat -> List r
43 | f' (Element con _ :: xs) (Success res :: ys) n = f res con n :: f' xs ys (S n)
44 | f' (_ :: xs) (_ :: ys) n = f' xs ys n
51 | (f : UnificationResult ->
53 | (0 _ : AllTyArgsNamed mt) =>
55 | (0 _ : ConArgsNamed con) =>
57 | (0 _ : ConArgsNamed mcon) =>
63 | (0 _ : AllTyArgsNamed mt) =>
66 | map2UConsN f rs mt @{mtp} meta = do
67 | let p1 = pushIn t.polyTy.cons t.polyTyNamed.tyConArgsNamed
68 | let p2 = pushIn mt.cons mtp.tyConArgsNamed
69 | f' 0 p1 p2 rs meta.conMeta
73 | List (Subset Con ConArgsNamed) ->
74 | List (Subset Con ConArgsNamed) ->
78 | f' n (Element con _ :: xs) (Element mcon _ :: ys) (Success res :: zs) (meta' :: metas) =
79 | f res mt con mcon meta' n :: f' (S n) xs ys zs metas
80 | f' n (_ :: xs) ys (_:: zs) ms =
91 | MonadLog m => (unifier : CanUnify m) =>
92 | (t : SpecTask) -> (con : Con) -> (0 conN : ConArgsNamed con) => m UnificationVerdict
93 | unifyCon t con = logBounds Debug "specialiseData.unifyCon" [t, con] $
do
94 | let Element ca _ = fromListAll con.args @{conArgsNamed}
95 | let Element ta _ = fromListAll t.tqArgs @{t.tqArgsNamed}
97 | MkUniTask {lfv=_} ca con.type
98 | {rfv=_} ta t.fullInvocation
99 | logPoint DetailedDebug "specialiseData.unifyCon" [t, con] "Unifier task: \{show uniTask}"
100 | uniRes <- unify uniTask
101 | logValue DetailedDebug "specialiseData.unifyCon" [t, con] "Unifier output: \{show uniRes}" uniRes