@@ -24,20 +24,21 @@ conflictMatch : {vars : _} -> List (Name, Term vars) -> Bool
24
24
conflictMatch [] = False
25
25
conflictMatch ((x, tm) :: ms) = conflictArgs x tm ms || conflictMatch ms
26
26
where
27
- clash : Term vars -> Term vars -> Bool
27
+ data ClashResult = Distinct | Same | Incomparable
28
+
29
+ clash : Term vars -> Term vars -> ClashResult
28
30
clash (Ref _ (DataCon t _ ) _ ) (Ref _ (DataCon t' _ ) _ )
29
- = t /= t'
31
+ = if t /= t' then Distinct else Same
30
32
clash (Ref _ (TyCon t _ ) _ ) (Ref _ (TyCon t' _ ) _ )
31
- = t /= t'
32
- clash (PrimVal _ c) (PrimVal _ c')
33
- = c /= c'
34
- clash (Ref _ t _ ) (PrimVal _ _ ) = isJust (isCon t)
35
- clash (PrimVal _ _ ) (Ref _ t _ ) = isJust (isCon t)
36
- clash (Ref _ t _ ) (TType _ _ ) = isJust (isCon t)
37
- clash (TType _ _ ) (Ref _ t _ ) = isJust (isCon t)
38
- clash (TType _ _ ) (PrimVal _ _ ) = True
39
- clash (PrimVal _ _ ) (TType _ _ ) = True
40
- clash _ _ = False
33
+ = if t /= t' then Distinct else Same
34
+ clash (PrimVal _ c) (PrimVal _ c') = if c /= c' then Distinct else Same
35
+ clash (Ref _ t _ ) (PrimVal _ _ ) = if isJust (isCon t) then Distinct else Incomparable
36
+ clash (PrimVal _ _ ) (Ref _ t _ ) = if isJust (isCon t) then Distinct else Incomparable
37
+ clash (Ref _ t _ ) (TType _ _ ) = if isJust (isCon t) then Distinct else Incomparable
38
+ clash (TType _ _ ) (Ref _ t _ ) = if isJust (isCon t) then Distinct else Incomparable
39
+ clash (TType _ _ ) (PrimVal _ _ ) = Distinct
40
+ clash (PrimVal _ _ ) (TType _ _ ) = Distinct
41
+ clash _ _ = Incomparable
41
42
42
43
findN : Nat -> Term vars -> Bool
43
44
findN i (Local _ _ i' _ ) = i == i'
@@ -60,7 +61,10 @@ conflictMatch ((x, tm) :: ms) = conflictArgs x tm ms || conflictMatch ms
60
61
conflictTm tm tm'
61
62
= let (f, args) = getFnArgs tm
62
63
(f', args') = getFnArgs tm' in
63
- clash f f' || any (uncurry conflictTm) (zip args args')
64
+ case clash f f' of
65
+ Distinct => True
66
+ Incomparable => False
67
+ Same => (any (uncurry conflictTm) (zip args args'))
64
68
65
69
conflictArgs : Name -> Term vars -> List (Name, Term vars) -> Bool
66
70
conflictArgs n tm [] = False
@@ -107,13 +111,12 @@ conflict defs env nfty n
107
111
conflictNF i t (NBind fc x b sc)
108
112
-- invent a fresh name, in case a user has bound the same name
109
113
-- twice somehow both references appear in the result it's unlikely
110
- -- put posslbe
114
+ -- put possible
111
115
= let x' = MN (show x) i in
112
116
conflictNF (i + 1 ) t
113
117
! (sc defs (toClosure defaultOpts [] (Ref fc Bound x')))
114
118
conflictNF i nf (NApp _ (NRef Bound n) [])
115
- = do empty <- clearDefs defs
116
- pure (Just [(n, ! (quote empty env nf))])
119
+ = pure (Just [(n, ! (quote defs env nf))])
117
120
conflictNF i (NDCon _ n t a args) (NDCon _ n' t' a' args')
118
121
= if t == t'
119
122
then conflictArgs i (map snd args) (map snd args')
0 commit comments