@@ -2,13 +2,13 @@ module QueryType (
22 getType , getTypeSubst , HasType ,
33 getEffects , getEffectsSubst ,
44 computeAbsEffects , declNestEffects ,
5- depPairLeftTy , extendEffect ,
5+ caseAltsBinderTys , depPairLeftTy , extendEffect ,
66 getAppType , getTabAppType , getMethodType , getBaseMonoidType , getReferentTy ,
77 getMethodIndex ,
88 instantiateDataDef , instantiateDepPairTy , instantiatePi , instantiateTabPi ,
99 litType , lamExprTy ,
1010 numNaryPiArgs , naryLamExprType ,
11- oneEffect , projectLength , sourceNameType ,
11+ oneEffect , projectLength , sourceNameType , typeAsBinderNest
1212 ) where
1313
1414import Control.Monad
@@ -55,6 +55,19 @@ getEffectsSubst e = do
5555
5656-- === Exposed helpers for querying types and effects ===
5757
58+ caseAltsBinderTys :: (Fallible1 m , EnvReader m )
59+ => Type n -> m n [EmptyAbs (Nest Binder ) n ]
60+ caseAltsBinderTys ty = case ty of
61+ TypeCon _ defName params -> do
62+ def <- lookupDataDef defName
63+ cons <- applyDataDefParams def params
64+ return [bs | DataConDef _ bs <- cons]
65+ VariantTy (NoExt types) -> do
66+ mapM typeAsBinderNest $ toList types
67+ VariantTy _ -> fail " Can't pattern-match partially-known variants"
68+ SumTy cases -> mapM typeAsBinderNest cases
69+ _ -> fail $ " Case analysis only supported on ADTs and variants, not on " ++ pprint ty
70+
5871depPairLeftTy :: DepPairType n -> Type n
5972depPairLeftTy (DepPairType (_:> ty) _) = ty
6073{-# INLINE depPairLeftTy #-}
@@ -159,6 +172,9 @@ naryLamExprType (NaryLamExpr (NonEmptyNest b bs) eff body) = liftTypeQueryM idSu
159172 binderToPiBinder :: Binder n l -> PiBinder n l
160173 binderToPiBinder (nameBinder:> ty) = PiBinder nameBinder ty PlainArrow
161174
175+ oneEffect :: Effect n -> EffectRow n
176+ oneEffect eff = EffectRow (S. singleton eff) Nothing
177+
162178projectLength :: (Fallible1 m , EnvReader m ) => Type n -> m n Int
163179projectLength ty = case ty of
164180 TypeCon _ defName params -> do
@@ -181,8 +197,11 @@ sourceNameType v = do
181197 UClassVar v' -> lookupEnv v' >>= \ case ClassBinding def -> return $ getClassTy def
182198 UMethodVar v' -> lookupEnv v' >>= \ case MethodBinding _ _ e -> getType e
183199
184- oneEffect :: Effect n -> EffectRow n
185- oneEffect eff = EffectRow (S. singleton eff) Nothing
200+ typeAsBinderNest :: ScopeReader m => Type n -> m n (Abs (Nest Binder ) UnitE n )
201+ typeAsBinderNest ty = do
202+ Abs ignored body <- toConstAbs UnitE
203+ return $ Abs (Nest (ignored:> ty) Empty ) body
204+ {-# INLINE typeAsBinderNest #-}
186205
187206-- === computing effects ===
188207
0 commit comments