1
{-# LANGUAGE CPP, TypeSynonymInstances, FlexibleInstances, OverlappingInstances,
2
DeriveDataTypeable, DeriveFunctor, StandaloneDeriving #-}
2
{-# LANGUAGE DeriveDataTypeable #-}
3
{-# LANGUAGE DeriveFunctor #-}
4
{-# LANGUAGE FlexibleInstances #-}
5
{-# LANGUAGE PatternGuards #-}
6
{-# LANGUAGE OverlappingInstances #-}
7
{-# LANGUAGE StandaloneDeriving #-}
8
{-# LANGUAGE TupleSections #-}
9
{-# LANGUAGE TypeSynonymInstances #-}
3
11
module Agda.TypeChecking.Substitute where
5
import Control.Monad.Identity
6
import Control.Monad.Reader
7
13
import Control.Arrow ((***))
9
import Data.Typeable (Typeable)
10
import Data.List hiding (sort)
17
import Data.List hiding (sort, drop)
11
18
import qualified Data.List as List
13
19
import Data.Map (Map)
14
import qualified Data.Map as Map
15
import qualified Data.Set as Set
17
import Agda.Syntax.Common
20
import Data.Typeable (Typeable)
22
import Debug.Trace (trace)
24
import Agda.Syntax.Common hiding (Arg, Dom, NamedArg)
25
import qualified Agda.Syntax.Common as Common
18
26
import Agda.Syntax.Internal
19
27
import Agda.Syntax.Position
22
30
import Agda.TypeChecking.Free as Free
23
31
import Agda.TypeChecking.CompiledClause
33
import Agda.Utils.List
25
34
import Agda.Utils.Monad
35
import Agda.Utils.Permutation
26
36
import Agda.Utils.Size
27
import Agda.Utils.Permutation
37
import Agda.Utils.Tuple
29
39
#include "../undefined.h"
30
40
import Agda.Utils.Impossible
42
---------------------------------------------------------------------------
44
---------------------------------------------------------------------------
32
46
-- | Apply something to a bunch of arguments.
33
47
-- Preserves blocking tags (application can never resolve blocking).
34
48
class Apply t where
35
apply :: t -> Args -> t
49
apply :: t -> Args -> t
50
applyE :: t -> Elims -> t
52
apply t args = applyE t $ map Apply args
53
applyE t es = apply t $ map argFromElim es
54
-- precondition: all @es@ are @Apply@s
37
56
instance Apply Term where
39
apply m args@(a:args0) =
41
Var i args' -> Var i (args' ++ args)
42
Def c args' -> Def c (args' ++ args)
43
Con c args' -> Con c (args' ++ args)
44
Lam _ u -> absApp u (unArg a) `apply` args0
45
MetaV x args' -> MetaV x (args' ++ args)
46
Shared p -> Shared $ apply p args
47
Lit{} -> __IMPOSSIBLE__
48
Level{} -> __IMPOSSIBLE__
49
Pi _ _ -> __IMPOSSIBLE__
50
Sort _ -> __IMPOSSIBLE__
51
DontCare mv -> DontCare $ mv `apply` args -- Andreas, 2011-10-02
52
-- need to go under DontCare, since "with" might resurrect irrelevant term
60
Var i es' -> Var i (es' ++ es)
61
Def f es' -> defApp f es' es -- remove projection redexes
62
Con c args -> conApp c args es
65
Apply a : es0 -> absApp b (unArg a) `applyE` es0
67
MetaV x es' -> MetaV x (es' ++ es)
68
Shared p -> Shared $ applyE p es
69
Lit{} -> __IMPOSSIBLE__
70
Level{} -> __IMPOSSIBLE__
71
Pi _ _ -> __IMPOSSIBLE__
72
Sort _ -> __IMPOSSIBLE__
73
DontCare mv -> dontCare $ mv `applyE` es -- Andreas, 2011-10-02
74
-- need to go under DontCare, since "with" might resurrect irrelevant term
76
-- | If $v$ is a record value, @canProject f v@
77
-- returns its field @f@.
78
canProject :: QName -> Term -> Maybe (Arg Term)
80
case ignoreSharing v of
81
(Con (ConHead _ fs) vs) -> do
86
-- | Eliminate a constructed term.
87
conApp :: ConHead -> Args -> Elims -> Term
88
conApp ch args [] = Con ch args
89
conApp ch args (Apply a : es) = conApp ch (args ++ [a]) es
90
conApp ch@(ConHead c fs) args (Proj f : es) =
91
let failure = flip trace __IMPOSSIBLE__ $
92
"conApp: constructor " ++ show c ++
93
" with fields " ++ show fs ++
94
" projected by " ++ show f
95
i = maybe failure id $ elemIndex f fs
96
v = maybe failure argToDontCare $ mhead $ drop i args
99
i = maybe failure id $ elemIndex f $ map unArg fs
100
v = maybe failure unArg $ mhead $ drop i args
101
-- Andreas, 2013-10-20 see Issue543a:
102
-- protect result of irrelevant projection.
103
r = maybe __IMPOSSIBLE__ getRelevance $ mhead $ drop i fs
104
u | Irrelevant <- r = DontCare v
109
-- | @defApp f us vs@ applies @Def f us@ to further arguments @vs@,
110
-- eliminating top projection redexes.
111
-- If @us@ is not empty, we cannot have a projection redex, since
112
-- the record argument is the first one.
113
defApp :: QName -> Elims -> Elims -> Term
114
defApp f [] (Apply a : es) | Just v <- canProject f (unArg a)
115
= argToDontCare v `applyE` es
116
defApp f es0 es = Def f $ es0 ++ es
118
-- protect irrelevant fields (see issue 610)
119
argToDontCare :: Common.Arg c Term -> Term
120
argToDontCare (Common.Arg ai v)
121
| Irrelevant <- getRelevance ai = dontCare v
54
124
instance Apply Type where
126
-- Maybe an @applyE@ instance would be useful here as well.
127
-- A record type could be applied to a projection name
128
-- to yield the field type.
129
-- However, this works only in the monad where we can
130
-- look up the fields of a record type.
57
132
instance Apply Sort where
59
apply s _ = __IMPOSSIBLE__
134
applyE s _ = __IMPOSSIBLE__
61
136
instance Apply a => Apply (Ptr a) where
62
apply p xs = fmap (`apply` xs) p
137
applyE p xs = fmap (`applyE` xs) p
139
-- @applyE@ does not make sense for telecopes, definitions, clauses etc.
64
141
instance Subst a => Apply (Tele a) where
65
142
apply tel [] = tel
67
144
apply (ExtendTel _ tel) (t : ts) = absApp tel (unArg t) `apply` ts
69
146
instance Apply Definition where
70
apply (Defn rel x t pol occ df m c d) args = Defn rel x (piApply t args) (apply pol args) (apply occ args) df m c (apply d args)
147
apply (Defn info x t pol occ df m c d) args = Defn info x (piApply t args) (apply pol args) (apply occ args) df m c (apply d args)
72
149
instance Apply [Base.Occurrence] where
73
apply occ args = drop (length args) occ
150
apply occ args = List.drop (length args) occ
75
152
instance Apply [Polarity] where
76
apply pol args = drop (length args) pol
153
apply pol args = List.drop (length args) pol
155
instance Apply Projection where
157
{ projIndex = projIndex p - size args
158
, projDropPars = projDropPars p `apply` args
78
161
instance Apply Defn where
80
163
apply d args = case d of
82
165
Function{ funClauses = cs, funCompiled = cc, funInv = inv
83
, funProjection = Nothing {-, funArgOccurrences = occ -} } ->
166
, funProjection = Nothing } ->
84
167
d { funClauses = apply cs args
85
168
, funCompiled = apply cc args
86
169
, funInv = apply inv args
88
Function{ funClauses = cs, funCompiled = cc, funInv = inv
89
, funProjection = Just (r, n) {-, funArgOccurrences = occ -} }
90
| m < n -> d { funProjection = Just (r, n - m) }
172
Function{ funClauses = cs, funCompiled = cc, funInv = inv
173
, funProjection = Just p} ->
174
case p `apply` args of
175
p@Projection{ projIndex = n }
176
| n < 0 -> __IMPOSSIBLE__
177
-- case: applied only to parameters
178
| n > 0 -> d { funProjection = Just p }
179
-- case: applied also to record value
181
d { funClauses = apply cs args'
182
, funCompiled = apply cc args'
183
, funInv = apply inv args'
184
, funProjection = Nothing -- WAS: Just $ p { projIndex = 0 }
186
where args' = [last args] -- the record value
188
Function{ funClauses = cs, funCompiled = cc, funInv = inv
189
, funProjection = Just p@Projection{ projIndex = n } }
190
-- case: only applying parameters
191
| size args < n -> d { funProjection = Just $ p `apply` args }
192
-- case: apply also to record value
92
194
d { funClauses = apply cs args'
93
195
, funCompiled = apply cc args'
94
196
, funInv = apply inv args'
95
, funProjection = Just (r, 0)
197
, funProjection = Just $ p { projIndex = 0 } -- Nothing ?
97
where args' = [last args]
99
Datatype{ dataPars = np, dataClause = cl
199
where args' = [last args] -- the record value
201
Datatype{ dataPars = np, dataSmallPars = sps, dataNonLinPars = nlps, dataClause = cl
100
202
{-, dataArgOccurrences = occ-} } ->
101
d { dataPars = np - size args, dataClause = apply cl args
203
d { dataPars = np - size args
204
, dataSmallPars = apply sps args
205
, dataNonLinPars = apply nlps args
206
, dataClause = apply cl args
207
-- , dataArgOccurrences = List.drop (length args) occ
103
209
Record{ recPars = np, recConType = t, recClause = cl, recTel = tel
104
210
{-, recArgOccurrences = occ-} } ->
105
211
d { recPars = np - size args, recConType = apply t args
106
212
, recClause = apply cl args, recTel = apply tel args
213
-- , recArgOccurrences = List.drop (length args) occ
108
215
Constructor{ conPars = np } ->
109
216
d { conPars = np - size args }
140
247
len = length args
142
249
instance Apply a => Apply (WithArity a) where
143
apply (WithArity n a) args = WithArity n $ apply a args
250
apply (WithArity n a) args = WithArity n $ apply a args
251
applyE (WithArity n a) es = WithArity n $ applyE a es
145
253
instance Apply a => Apply (Case a) where
146
254
apply (Branches cs ls m) args =
147
255
Branches (apply cs args) (apply ls args) (apply m args)
256
applyE (Branches cs ls m) es =
257
Branches (applyE cs es) (applyE ls es) (applyE m es)
149
259
instance Apply FunctionInverse where
150
260
apply NotInjective args = NotInjective
151
261
apply (Inverse inv) args = Inverse $ apply inv args
153
263
instance Apply ClauseBody where
155
apply (Bind (Abs _ b)) (a:args) = subst (unArg a) b `apply` args
156
apply (Bind (NoAbs _ b)) (_:args) = b `apply` args
157
apply (Body v) args = Body $ v `apply` args
158
apply NoBody _ = NoBody
265
apply (Bind b) (a:args) = absApp b (unArg a) `apply` args
266
apply (Body v) args = Body $ v `apply` args
267
apply NoBody _ = NoBody
270
applyE (Bind b) (Apply a : es) = absApp b (unArg a) `applyE` es
271
applyE (Bind b) (Proj{} : es) = __IMPOSSIBLE__
272
applyE (Body v) es = Body $ v `applyE` es
273
applyE NoBody _ = NoBody
160
275
instance Apply DisplayTerm where
161
276
apply (DTerm v) args = DTerm $ apply v args
162
277
apply (DDot v) args = DDot $ apply v args
163
278
apply (DCon c vs) args = DCon c $ vs ++ map (fmap DTerm) args
164
279
apply (DDef c vs) args = DDef c $ vs ++ map (fmap DTerm) args
165
apply (DWithApp v args') args = DWithApp v $ args' ++ args
280
apply (DWithApp v ws args') args = DWithApp v ws $ args' ++ args
167
282
instance Apply t => Apply [t] where
168
apply ts args = map (`apply` args) ts
283
apply ts args = map (`apply` args) ts
284
applyE ts es = map (`applyE` es) ts
170
286
instance Apply t => Apply (Blocked t) where
171
apply b args = fmap (`apply` args) b
287
apply b args = fmap (`apply` args) b
288
applyE b es = fmap (`applyE` es) b
173
290
instance Apply t => Apply (Maybe t) where
174
apply x args = fmap (`apply` args) x
291
apply x args = fmap (`apply` args) x
292
applyE x es = fmap (`applyE` es) x
176
294
instance Apply v => Apply (Map k v) where
177
apply x args = fmap (`apply` args) x
295
apply x args = fmap (`apply` args) x
296
applyE x es = fmap (`applyE` es) x
179
298
instance (Apply a, Apply b) => Apply (a,b) where
180
apply (x,y) args = (apply x args, apply y args)
299
apply (x,y) args = (apply x args, apply y args)
300
applyE (x,y) es = (applyE x es , applyE y es )
182
302
instance (Apply a, Apply b, Apply c) => Apply (a,b,c) where
183
apply (x,y,z) args = (apply x args, apply y args, apply z args)
303
apply (x,y,z) args = (apply x args, apply y args, apply z args)
304
applyE (x,y,z) es = (applyE x es , applyE y es , applyE z es )
306
instance DoDrop a => Apply (Drop a) where
307
apply x args = dropMore (size args) x
309
instance DoDrop a => Abstract (Drop a) where
310
abstract tel x = unDrop (size tel) x
185
312
instance Apply Permutation where
186
313
-- The permutation must start with [0..m - 1]
314
-- NB: section (- m) not possible (unary minus), hence (flip (-) m)
187
315
apply (Perm n xs) args = Perm (n - m) $ map (flip (-) m) $ genericDrop m xs
231
364
abstract tel [] = []
232
365
abstract tel pol = replicate (size tel) Invariant ++ pol -- TODO: check polarity
367
instance Abstract Projection where
369
{ projIndex = size tel + projIndex p
370
, projDropPars = abstract tel $ projDropPars p
234
373
instance Abstract Defn where
235
374
abstract tel d = case d of
237
376
Function{ funClauses = cs, funCompiled = cc, funInv = inv
238
, funProjection = Nothing {-, funArgOccurrences = occ-} } ->
239
d { funClauses = abstract tel cs, funCompiled = abstract tel cc
240
, funInv = abstract tel inv
242
Function{ funClauses = cs, funCompiled = cc, funInv = inv
243
, funProjection = Just (r, n) {-, funArgOccurrences = occ-} } ->
244
d { funProjection = Just (r, n + size tel) }
245
Datatype{ dataPars = np, dataClause = cl {-, dataArgOccurrences = occ-} } ->
246
d { dataPars = np + size tel, dataClause = abstract tel cl
248
Record{ recPars = np, recConType = t, recClause = cl, recTel = tel'
249
{-, recArgOccurrences = occ-} } ->
250
d { recPars = np + size tel, recConType = abstract tel t
251
, recClause = abstract tel cl, recTel = abstract tel tel'
377
, funProjection = Nothing } ->
378
d { funClauses = abstract tel cs
379
, funCompiled = abstract tel cc
380
, funInv = abstract tel inv
382
Function{ funProjection = Just p } ->
383
d { funProjection = Just $ abstract tel p }
384
Datatype{ dataPars = np, dataSmallPars = sps, dataNonLinPars = nlps, dataClause = cl } ->
385
d { dataPars = np + size tel
386
, dataSmallPars = abstract tel sps
387
, dataNonLinPars = abstract tel nlps
388
, dataClause = abstract tel cl
390
Record{ recPars = np, recConType = t, recClause = cl, recTel = tel' } ->
391
d { recPars = np + size tel
392
, recConType = abstract tel t
393
, recClause = abstract tel cl
394
, recTel = abstract tel tel'
253
396
Constructor{ conPars = np } ->
254
397
d { conPars = np + size tel }
434
589
instance Subst Term where
435
590
applySubst IdS t = t
436
591
applySubst rho t = case t of
437
Var i vs -> lookupS rho i `apply` applySubst rho vs
592
Var i es -> lookupS rho i `applyE` applySubst rho es
438
593
Lam h m -> Lam h $ applySubst rho m
439
Def c vs -> Def c $ applySubst rho vs
594
Def f es -> defApp f [] $ applySubst rho es
440
595
Con c vs -> Con c $ applySubst rho vs
441
MetaV x vs -> MetaV x $ applySubst rho vs
596
MetaV x es -> MetaV x $ applySubst rho es
443
598
Level l -> levelTm $ applySubst rho l
444
599
Pi a b -> uncurry Pi $ applySubst rho (a,b)
445
600
Sort s -> sortTm $ applySubst rho s
446
601
Shared p -> Shared $ applySubst rho p
447
DontCare mv -> DontCare $ applySubst rho mv
602
DontCare mv -> dontCare $ applySubst rho mv
449
604
instance Subst a => Subst (Ptr a) where
450
605
applySubst rho = fmap (applySubst rho)
468
623
applySubst rho (Plus n l) = Plus n $ applySubst rho l
470
625
instance Subst LevelAtom where
471
applySubst rho (MetaLevel m vs) = MetaLevel m $ applySubst rho vs
472
applySubst rho (BlockedLevel m v) = BlockedLevel m $ applySubst rho v
473
applySubst rho (NeutralLevel v) = UnreducedLevel $ applySubst rho v
474
applySubst rho (UnreducedLevel v) = UnreducedLevel $ applySubst rho v
626
applySubst rho (MetaLevel m vs) = MetaLevel m $ applySubst rho vs
627
applySubst rho (BlockedLevel m v) = BlockedLevel m $ applySubst rho v
628
applySubst rho (NeutralLevel v) = UnreducedLevel $ applySubst rho v
629
applySubst rho (UnreducedLevel v) = UnreducedLevel $ applySubst rho v
631
instance Subst Bool where
634
instance Subst Name where
476
637
instance Subst Pattern where
477
638
applySubst rho p = case p of
480
639
ConP c mt ps -> ConP c (applySubst rho mt) $ applySubst rho ps
481
640
DotP t -> DotP $ applySubst rho t
483
645
instance Subst t => Subst (Blocked t) where
484
applySubst rho b = fmap (applySubst rho) b
646
applySubst rho b = fmap (applySubst rho) b
486
648
instance Subst DisplayForm where
487
649
applySubst rho (Display n ps v) =
489
651
(applySubst (liftS n rho) v)
491
653
instance Subst DisplayTerm where
492
applySubst rho (DTerm v) = DTerm $ applySubst rho v
493
applySubst rho (DDot v) = DDot $ applySubst rho v
494
applySubst rho (DCon c vs) = DCon c $ applySubst rho vs
495
applySubst rho (DDef c vs) = DDef c $ applySubst rho vs
496
applySubst rho (DWithApp vs ws) = uncurry DWithApp $ applySubst rho (vs, ws)
654
applySubst rho (DTerm v) = DTerm $ applySubst rho v
655
applySubst rho (DDot v) = DDot $ applySubst rho v
656
applySubst rho (DCon c vs) = DCon c $ applySubst rho vs
657
applySubst rho (DDef c vs) = DDef c $ applySubst rho vs
658
applySubst rho (DWithApp v vs ws) = uncurry3 DWithApp $ applySubst rho (v, vs, ws)
498
660
instance Subst a => Subst (Tele a) where
499
applySubst rho EmptyTel = EmptyTel
500
applySubst rho (ExtendTel t tel) = uncurry ExtendTel $ applySubst rho (t, tel)
661
applySubst rho EmptyTel = EmptyTel
662
applySubst rho (ExtendTel t tel) = uncurry ExtendTel $ applySubst rho (t, tel)
502
664
instance Subst Constraint where
503
665
applySubst rho c = case c of
541
706
instance (Subst a, Subst b) => Subst (a,b) where
542
707
applySubst rho (x,y) = (applySubst rho x, applySubst rho y)
709
instance (Subst a, Subst b, Subst c) => Subst (a,b,c) where
710
applySubst rho (x,y,z) = (applySubst rho x, applySubst rho y, applySubst rho z)
712
instance (Subst a, Subst b, Subst c, Subst d) => Subst (a,b,c,d) where
713
applySubst rho (x,y,z,u) = (applySubst rho x, applySubst rho y, applySubst rho z, applySubst rho u)
544
715
instance Subst ClauseBody where
545
716
applySubst rho (Body t) = Body $ applySubst rho t
546
717
applySubst rho (Bind b) = Bind $ applySubst rho b
547
718
applySubst _ NoBody = NoBody
549
data TelV a = TelV (Tele (Dom a)) a
720
---------------------------------------------------------------------------
722
---------------------------------------------------------------------------
724
type TelView = TelV Type
725
data TelV a = TelV { theTel :: Tele (Dom a), theCore :: a }
550
726
deriving (Typeable, Show, Eq, Ord, Functor)
552
type TelView = TelV Type
554
telFromList :: [Dom (String, Type)] -> Telescope
555
telFromList = foldr (\(Dom h r (x, a)) -> ExtendTel (Dom h r a) . Abs x) EmptyTel
557
telToList :: Telescope -> [Dom (String, Type)]
558
telToList EmptyTel = []
559
telToList (ExtendTel arg tel) = fmap ((,) $ absName tel) arg : telToList (absBody tel)
728
type ListTel' a = [Dom (a, Type)]
729
type ListTel = ListTel' ArgName
731
telFromList' :: (a -> ArgName) -> ListTel' a -> Telescope
732
telFromList' f = foldr extTel EmptyTel
734
extTel (Common.Dom info (x, a)) = ExtendTel (Common.Dom info a) . Abs (f x)
736
telFromList :: ListTel -> Telescope
737
telFromList = telFromList' id
739
telToList :: Telescope -> ListTel
740
telToList EmptyTel = []
741
telToList (ExtendTel arg tel) = fmap (absName tel,) arg : telToList (absBody tel)
742
-- Andreas, 2013-12-14: This would work also for 'NoAbs',
743
-- since 'absBody' raises.
745
-- | Turn a typed binding @(x1 .. xn : A)@ into a telescope.
746
bindsToTel' :: (Name -> a) -> [Name] -> Dom Type -> ListTel' a
747
bindsToTel' f [] t = []
748
bindsToTel' f (x:xs) t = fmap (f x,) t : bindsToTel' f xs (raise 1 t)
750
bindsToTel :: [Name] -> Dom Type -> ListTel
751
bindsToTel = bindsToTel' nameToArgName
561
753
telView' :: Type -> TelView
562
754
telView' t = case ignoreSharing $ unEl t of
566
758
absV a x (TelV tel t) = TelV (ExtendTel a (Abs x tel)) t
568
760
-- | @mkPi dom t = telePi (telFromList [dom]) t@
569
mkPi :: Dom (String, Type) -> Type -> Type
570
mkPi (Dom h r (x, a)) b = el $ Pi (Dom h r a) (mkAbs x b)
761
mkPi :: Dom (ArgName, Type) -> Type -> Type
762
mkPi (Common.Dom info (x, a)) b = el $ Pi (Common.Dom info a) (mkAbs x b)
572
764
el = El $ dLub (getSort a) (Abs x (getSort b)) -- dLub checks x freeIn
766
telePi' :: (Abs Type -> Abs Type) -> Telescope -> Type -> Type
767
telePi' reAbs = telePi where
768
telePi EmptyTel t = t
769
telePi (ExtendTel u tel) t = el $ Pi u $ reAbs b
771
b = (`telePi` t) <$> tel
772
s1 = getSort $ unDom u
776
-- | Uses free variable analysis to introduce 'noAbs' bindings.
574
777
telePi :: Telescope -> Type -> Type
575
telePi EmptyTel t = t
576
telePi (ExtendTel u tel) t = el $ Pi u (reAbs b)
579
b = fmap (flip telePi t) tel
580
s1 = getSort $ unDom u
778
telePi = telePi' reAbs
780
-- | Everything will be a 'Abs'.
781
telePi_ :: Telescope -> Type -> Type
583
785
-- | Everything will be a pi.
584
telePi_ :: Telescope -> Type -> Type
585
786
telePi_ EmptyTel t = t
586
787
telePi_ (ExtendTel u tel) t = el $ Pi u b
650
865
Lam h b -> Lam h $ underAbs (loop $ n-1) a b
651
866
_ -> __IMPOSSIBLE__
868
-- | @getBody@ returns the properly raised clause 'Body',
869
-- and 'Nothing' if 'NoBody'.
871
-- @getBodyUnraised@ just grabs the body, without raising the de Bruijn indices.
872
-- This is useful if you want to consider the body in context 'clauseTel'.
873
class GetBody a where
874
getBody :: a -> Maybe Term
875
getBodyUnraised :: a -> Maybe Term
877
instance GetBody ClauseBody where
880
-- collect all shiftings and do them in the end in one go
881
body :: Int -> ClauseBody -> Maybe Term
882
body _ NoBody = Nothing
883
body n (Body v) = Just $ raise n v
884
body n (Bind (NoAbs _ v)) = body n v
885
body n (Bind (Abs _ v)) = body (n + 1) v
887
getBodyUnraised NoBody = Nothing
888
getBodyUnraised (Body v) = Just v
889
getBodyUnraised (Bind b) = getBodyUnraised $ unAbs b -- Does not raise!
891
instance GetBody Clause where
892
getBody = getBody . clauseBody
893
getBodyUnraised = getBodyUnraised . clauseBody
895
---------------------------------------------------------------------------
896
-- * Syntactic equality and order
897
---------------------------------------------------------------------------
653
899
deriving instance (Subst a, Eq a) => Eq (Tele a)
654
900
deriving instance (Subst a, Ord a) => Ord (Tele a)