0 | module Core.TT.Binder
32 | isImplicit : PiInfo t -> Bool
33 | isImplicit Explicit = False
39 | eqPiInfoBy : (t -> u -> Bool) -> PiInfo t -> PiInfo u -> Bool
40 | eqPiInfoBy eqT = go where
42 | go : PiInfo t -> PiInfo u -> Bool
43 | go Implicit Implicit = True
44 | go Explicit Explicit = True
45 | go AutoImplicit AutoImplicit = True
46 | go (DefImplicit t) (DefImplicit t') = eqT t t'
53 | forgetDef : PiInfo t -> PiInfo t'
54 | forgetDef Explicit = Explicit
55 | forgetDef Implicit = Implicit
56 | forgetDef AutoImplicit = AutoImplicit
57 | forgetDef (DefImplicit t) = Implicit
60 | Show t => Show (PiInfo t) where
61 | show Implicit = "Implicit"
62 | show Explicit = "Explicit"
63 | show AutoImplicit = "AutoImplicit"
64 | show (DefImplicit t) = "DefImplicit " ++ show t
67 | Eq t => Eq (PiInfo t) where
68 | (==) = eqPiInfoBy (==)
76 | record PiBindData (t : Type) where
77 | constructor MkPiBindData
82 | mapType : (t -> t) -> PiBindData t -> PiBindData t
83 | mapType f = {boundType $= f}
86 | Show t => Show (PiBindData t) where
87 | show bind = show bind.info ++ ", " ++ show bind.boundType
92 | data Binder : Type -> Type where
94 | Lam : FC -> RigCount -> PiInfo type -> (ty : type) -> Binder type
96 | Let : FC -> RigCount -> (val : type) -> (ty : type) -> Binder type
98 | Pi : FC -> RigCount -> PiInfo type -> (ty : type) -> Binder type
102 | PVar : FC -> RigCount -> PiInfo type -> (ty : type) -> Binder type
106 | PLet : FC -> RigCount -> (val : type) -> (ty : type) -> Binder type
108 | PVTy : FC -> RigCount -> (ty : type) -> Binder type
113 | isLet : Binder t -> Bool
114 | isLet (Let {}) = True
118 | binderLoc : Binder tm -> FC
119 | binderLoc (Lam fc _ x ty) = fc
120 | binderLoc (Let fc _ val ty) = fc
121 | binderLoc (Pi fc _ x ty) = fc
122 | binderLoc (PVar fc _ p ty) = fc
123 | binderLoc (PLet fc _ val ty) = fc
124 | binderLoc (PVTy fc _ ty) = fc
127 | binderType : Binder tm -> tm
128 | binderType (Lam _ _ x ty) = ty
129 | binderType (Let _ _ val ty) = ty
130 | binderType (Pi _ _ x ty) = ty
131 | binderType (PVar _ _ _ ty) = ty
132 | binderType (PLet _ _ val ty) = ty
133 | binderType (PVTy _ _ ty) = ty
136 | multiplicity : Binder tm -> RigCount
137 | multiplicity (Lam _ c x ty) = c
138 | multiplicity (Let _ c val ty) = c
139 | multiplicity (Pi _ c x ty) = c
140 | multiplicity (PVar _ c p ty) = c
141 | multiplicity (PLet _ c val ty) = c
142 | multiplicity (PVTy _ c ty) = c
145 | piInfo : Binder tm -> PiInfo tm
146 | piInfo (Lam _ c x ty) = x
147 | piInfo (Let _ c val ty) = Explicit
148 | piInfo (Pi _ c x ty) = x
149 | piInfo (PVar _ c p ty) = p
150 | piInfo (PLet _ c val ty) = Explicit
151 | piInfo (PVTy _ c ty) = Explicit
154 | isImplicit : Binder tm -> Bool
155 | isImplicit = PiInfo.isImplicit . piInfo
158 | setMultiplicity : Binder tm -> RigCount -> Binder tm
159 | setMultiplicity (Lam fc _ x ty) c = Lam fc c x ty
160 | setMultiplicity (Let fc _ val ty) c = Let fc c val ty
161 | setMultiplicity (Pi fc _ x ty) c = Pi fc c x ty
162 | setMultiplicity (PVar fc _ p ty) c = PVar fc c p ty
163 | setMultiplicity (PLet fc _ val ty) c = PLet fc c val ty
164 | setMultiplicity (PVTy fc _ ty) c = PVTy fc c ty
166 | Show ty => Show (Binder ty) where
167 | show (Lam _ c _ t) = "\\" ++ showCount c ++ show t
168 | show (Pi _ c _ t) = "Pi " ++ showCount c ++ show t
169 | show (Let _ c v t) = "let " ++ showCount c ++ show v ++ " : " ++ show t
170 | show (PVar _ c _ t) = "pat " ++ showCount c ++ show t
171 | show (PLet _ c v t) = "plet " ++ showCount c ++ show v ++ " : " ++ show t
172 | show (PVTy _ c t) = "pty " ++ showCount c ++ show t
175 | setType : Binder tm -> tm -> Binder tm
176 | setType (Lam fc c x _) ty = Lam fc c x ty
177 | setType (Let fc c val _) ty = Let fc c val ty
178 | setType (Pi fc c x _) ty = Pi fc c x ty
179 | setType (PVar fc c p _) ty = PVar fc c p ty
180 | setType (PLet fc c val _) ty = PLet fc c val ty
181 | setType (PVTy fc c _) ty = PVTy fc c ty
184 | Functor PiInfo where
185 | map func Explicit = Explicit
186 | map func Implicit = Implicit
187 | map func AutoImplicit = AutoImplicit
188 | map func (DefImplicit t) = (DefImplicit (func t))
191 | Foldable PiInfo where
192 | foldr f acc Implicit = acc
193 | foldr f acc Explicit = acc
194 | foldr f acc AutoImplicit = acc
195 | foldr f acc (DefImplicit x) = f x acc
198 | Traversable PiInfo where
199 | traverse f Implicit = pure Implicit
200 | traverse f Explicit = pure Explicit
201 | traverse f AutoImplicit = pure AutoImplicit
202 | traverse f (DefImplicit x) = map DefImplicit (f x)
205 | Functor PiBindData where
206 | map f (MkPiBindData info type) = MkPiBindData (map f info) (f type)
209 | Foldable PiBindData where
210 | foldr f acc (MkPiBindData info type) = f type (foldr f acc info)
213 | Traversable PiBindData where
214 | traverse f (MkPiBindData info type) = MkPiBindData <$> traverse f info <*> f type
217 | Functor Binder where
218 | map func (Lam fc c x ty) = Lam fc c (map func x) (func ty)
219 | map func (Let fc c val ty) = Let fc c (func val) (func ty)
220 | map func (Pi fc c x ty) = Pi fc c (map func x) (func ty)
221 | map func (PVar fc c p ty) = PVar fc c (map func p) (func ty)
222 | map func (PLet fc c val ty) = PLet fc c (func val) (func ty)
223 | map func (PVTy fc c ty) = PVTy fc c (func ty)
226 | Foldable Binder where
227 | foldr f acc (Lam fc c x ty) = foldr f (f ty acc) x
228 | foldr f acc (Let fc c val ty) = f val (f ty acc)
229 | foldr f acc (Pi fc c x ty) = foldr f (f ty acc) x
230 | foldr f acc (PVar fc c p ty) = foldr f (f ty acc) p
231 | foldr f acc (PLet fc c val ty) = f val (f ty acc)
232 | foldr f acc (PVTy fc c ty) = f ty acc
235 | Traversable Binder where
236 | traverse f (Lam fc c x ty) = Lam fc c <$> traverse f x <*> f ty
237 | traverse f (Let fc c val ty) = Let fc c <$> f val <*> f ty
238 | traverse f (Pi fc c x ty) = Pi fc c <$> traverse f x <*> f ty
239 | traverse f (PVar fc c p ty) = PVar fc c <$> traverse f p <*> f ty
240 | traverse f (PLet fc c val ty) = PLet fc c <$> f val <*> f ty
241 | traverse f (PVTy fc c ty) = PVTy fc c <$> f ty
245 | eqBinderBy : (t -> u -> Bool) -> (Binder t -> Binder u -> Bool)
246 | eqBinderBy eqTU = go where
248 | go : Binder t -> Binder u -> Bool
249 | go (Lam _ c p ty) (Lam _ c' p' ty') = c == c' && eqPiInfoBy eqTU p p' && eqTU ty ty'
250 | go (Let _ c v ty) (Let _ c' v' ty') = c == c' && eqTU v v' && eqTU ty ty'
251 | go (Pi _ c p ty) (Pi _ c' p' ty') = c == c' && eqPiInfoBy eqTU p p' && eqTU ty ty'
252 | go (PVar _ c p ty) (PVar _ c' p' ty') = c == c' && eqPiInfoBy eqTU p p' && eqTU ty ty'
253 | go (PLet _ c v ty) (PLet _ c' v' ty') = c == c' && eqTU v v' && eqTU ty ty'
254 | go (PVTy _ c ty) (PVTy _ c' ty') = c == c' && eqTU ty ty'
258 | Eq a => Eq (Binder a) where
259 | (==) = eqBinderBy (==)