@@ -28,7 +28,7 @@ import Data.Char (chr, ord)
2828import Data.Eq.Deriving (deriveEq1 )
2929import Data.Fix (Fix (.. ))
3030import Data.Functor.Classes (Eq1 (.. ), Eq2 (.. ), Show1 (.. ), Show2 (.. ), eq1 ,
31- showsUnary1 )
31+ showsUnary1 , Ord1 )
3232import Data.Functor.Foldable (Base , Corecursive (embed ),
3333 Recursive (cata , project ))
3434import Data.Functor.Foldable.TH (MakeBaseFunctor (makeBaseFunctor ))
@@ -489,6 +489,11 @@ instance LamBase (UnprocessedParsedTermF p) where
489489 type LamVar (UnprocessedParsedTermF p ) = String
490490 type LamT (UnprocessedParsedTermF p ) = LocatedName
491491
492+ embedL = UnprocessedParsedTermL
493+ extractL = \ case
494+ UnprocessedParsedTermL x -> Just x
495+ _ -> Nothing
496+
492497type Pattern = Fix (PatternF UnprocessedParsedTerm )
493498newtype UnprocessedParsedTerm = UnprocessedParsedTerm { unUnprocessedParsedTerm :: UPT }
494499type UPT = Fix (UnprocessedParsedTermF Pattern )
@@ -930,6 +935,7 @@ instance Plated DataType where
930935 PairType a b -> PairType <$> f a <*> f b
931936 x -> pure x
932937
938+ {-
933939data PartialType
934940 = ZeroTypeP
935941 | AnyType
@@ -943,37 +949,78 @@ instance Plated PartialType where
943949 ArrTypeP i o -> ArrTypeP <$> f i <*> f o
944950 PairTypeP a b -> PairTypeP <$> f a <*> f b
945951 x -> pure x
952+ -}
953+ data PartialTypeF f
954+ = ZeroTypeP
955+ | AnyType
956+ | TypeVariable LocTag Int
957+ | ArrTypeP f f
958+ | PairTypeP f f
959+ deriving (Eq , Ord , Show , Generic1 , Functor , Foldable , Traversable )
960+ deriving Eq1 via (Generically1 PartialTypeF )
961+ deriving Ord1 via (Generically1 PartialTypeF )
962+ -- deriving instance (Show f) => Show (PartialTypeF f)
963+ instance Show1 PartialTypeF where
964+ liftShowsPrec showsPrecFunc showList d = \ case
965+ ZeroTypeP -> showString " ZeroTypeP"
966+ AnyType -> showString " AnyType"
967+ TypeVariable l i -> showString " TypeVariable " . shows l . showString " " . shows i
968+ ArrTypeP i o -> showString " ArrTypeP (" . showsPrecFunc 0 i . showString " -> " . showsPrecFunc 0 o . showString " )"
969+ PairTypeP a b -> showString " PairTypeP (" . showsPrecFunc 0 b . showString " , " . showsPrecFunc 0 b . showString " )"
946970
971+ type PartialType = Fix PartialTypeF
972+
973+ {-
947974instance Validity PartialType
948975instance GenValid PartialType
976+ -}
949977
950978toPartialType :: DataType -> PartialType
951979toPartialType = \ case
952- ZeroType -> ZeroTypeP
953- ArrType i o -> ArrTypeP (toPartialType i) (toPartialType o)
954- PairType a b -> PairTypeP (toPartialType a) (toPartialType b)
980+ ZeroType -> embed $ ZeroTypeP
981+ ArrType i o -> embed $ ArrTypeP (toPartialType i) (toPartialType o)
982+ PairType a b -> embed $ PairTypeP (toPartialType a) (toPartialType b)
955983
956984mergePairType :: DataType -> DataType
957985mergePairType = transform f where
958986 f (PairType ZeroType ZeroType ) = ZeroType
959987 f x = x
960988
961989mergePairTypeP :: PartialType -> PartialType
990+ {-
962991mergePairTypeP = transform f where
963992 f (PairTypeP ZeroTypeP ZeroTypeP) = ZeroTypeP
964993 f x = x
994+ -}
995+ mergePairTypeP = cata f where
996+ f = \ case
997+ (PairTypeP (Fix ZeroTypeP ) (Fix ZeroTypeP )) -> embed ZeroTypeP
998+ x -> embed x
965999
9661000containsFunction :: PartialType -> Bool
1001+ {-
9671002containsFunction = \case
9681003 ArrTypeP _ _ -> True
9691004 PairTypeP a b -> containsFunction a || containsFunction b
9701005 _ -> False
1006+ -}
1007+ containsFunction = cata f where
1008+ f = \ case
1009+ ArrTypeP _ _ -> True
1010+ x -> or x
9711011
9721012cleanType :: PartialType -> Bool
1013+ {-
9731014cleanType = \case
9741015 ZeroTypeP -> True
9751016 PairTypeP a b -> cleanType a && cleanType b
9761017 _ -> False
1018+ -}
1019+ cleanType = cata f where
1020+ f = \ case
1021+ ZeroTypeP -> True
1022+ PairTypeP a b -> a && b
1023+ _ -> False
9771024
9781025forget :: Corecursive a => Cofree (Base a ) anno -> a
9791026forget = cata (\ (_ CofreeT. :< z) -> embed z)
0 commit comments