From a6077dd59ad2895632ac374d217060f2f10d9233 Mon Sep 17 00:00:00 2001 From: Brian Huffman Date: Fri, 9 May 2014 16:26:31 -0700 Subject: [PATCH] Add more destructor functions for TypeCheck.AST.Type --- src/Cryptol/TypeCheck/AST.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Cryptol/TypeCheck/AST.hs b/src/Cryptol/TypeCheck/AST.hs index 636f64ca..b5f7ca1d 100644 --- a/src/Cryptol/TypeCheck/AST.hs +++ b/src/Cryptol/TypeCheck/AST.hs @@ -290,6 +290,26 @@ tIsVar ty = case tNoUser ty of TVar x -> Just x _ -> Nothing +tIsFun :: Type -> Maybe (Type, Type) +tIsFun ty = case tNoUser ty of + TCon (TC TCFun) [a, b] -> Just (a, b) + _ -> Nothing + +tIsSeq :: Type -> Maybe (Type, Type) +tIsSeq ty = case tNoUser ty of + TCon (TC TCSeq) [n, a] -> Just (n, a) + _ -> Nothing + +tIsBit :: Type -> Bool +tIsBit ty = case tNoUser ty of + TCon (TC TCBit) [] -> True + _ -> False + +tIsTuple :: Type -> Maybe [Type] +tIsTuple ty = case tNoUser ty of + TCon (TC (TCTuple _)) ts -> Just ts + _ -> Nothing + pIsFin :: Prop -> Maybe Type pIsFin ty = case tNoUser ty of TCon (PC PFin) [t1] -> Just t1 @@ -305,6 +325,16 @@ pIsEq ty = case tNoUser ty of TCon (PC PEqual) [t1,t2] -> Just (t1,t2) _ -> Nothing +pIsArith :: Prop -> Maybe Type +pIsArith ty = case tNoUser ty of + TCon (PC PArith) [t1] -> Just t1 + _ -> Nothing + +pIsCmp :: Prop -> Maybe Type +pIsCmp ty = case tNoUser ty of + TCon (PC PCmp) [t1] -> Just t1 + _ -> Nothing + pIsNumeric :: Prop -> Bool