|
5 | 5 | {-# LANGUAGE MultiParamTypeClasses #-}
|
6 | 6 | {-# LANGUAGE TypeFamilies #-}
|
7 | 7 | {-# LANGUAGE LambdaCase #-}
|
| 8 | +{-# LANGUAGE OverloadedStrings #-} |
8 | 9 |
|
9 | 10 | {- |
|
10 | 11 | Module : Verifier.SAW.SCTypeCheck
|
@@ -573,10 +574,31 @@ ensureRecognizer f err trm =
|
573 | 574 | ensureSort :: Term -> TCM Sort
|
574 | 575 | ensureSort tp = ensureRecognizer asSort (NotSort tp) tp
|
575 | 576 |
|
576 |
| --- | Ensure a 'Term' is a tuple type, normalizing if necessary, and return the |
577 |
| --- components of that tuple type |
| 577 | +-- | Ensure a 'Term' is a @TypeList@, normalizing if necessary, and |
| 578 | +-- return the components of that @TypeList@. Note that this function |
| 579 | +-- cannot be correctly implemented with 'ensureRecognizer', because |
| 580 | +-- that function does not normalize deeply enough. |
| 581 | +ensureTypeList :: Term -> TCM (Maybe [Term]) |
| 582 | +ensureTypeList t = |
| 583 | + do t' <- typeCheckWHNF t |
| 584 | + case asCtor t' of |
| 585 | + Just (c, []) |
| 586 | + | primName c == "Prelude.TypeNil" -> pure (Just []) |
| 587 | + Just (c, [t1, t2]) |
| 588 | + | primName c == "Prelude.TypeCons" -> |
| 589 | + do ts <- ensureTypeList t2 |
| 590 | + pure ((t1 :) <$> ts) |
| 591 | + _ -> pure Nothing |
| 592 | + |
| 593 | +-- | Ensure a 'Term' is a tuple type, normalizing if necessary, and |
| 594 | +-- return the components of that tuple type. Note that this function |
| 595 | +-- cannot be correctly implemented with 'ensureRecognizer', because |
| 596 | +-- that function does not normalize deeply enough. |
578 | 597 | ensureTupleType :: Term -> TCM [Term]
|
579 |
| -ensureTupleType tp = ensureRecognizer asTupleType (NotSort tp) tp |
| 598 | +ensureTupleType tp = |
| 599 | + do let err = NotTupleType tp |
| 600 | + t <- ensureRecognizer (isGlobalDef "Prelude.Tuple" @> Just) err tp |
| 601 | + maybe (throwTCError err) pure =<< ensureTypeList t |
580 | 602 |
|
581 | 603 | -- | Ensure a 'Term' is a record type, normalizing if necessary, and return the
|
582 | 604 | -- components of that record type
|
|
0 commit comments