foo i a u | isNeutral a = True
foo i (Ter Sum{} _) u = isNeutral u
foo i (VGlue _ as) u =
- let shasBeta = (shape as) `face` (i ~> 0)
+ let shasBeta = shape as `face` (i ~> 0)
in shasBeta /= Map.empty && eps `Map.notMember` shasBeta && isNeutral u
foo _ _ _ = False
isNeutralTrans u _ = isNeutral u
-- | Pretty printing
instance Show Env where
- show = render . showEnv
-
-showEnv, showEnv1 :: Env -> Doc
-showEnv e = case e of
- Empty -> PP.empty
- Def _ env -> showEnv env
- Upd env (_,u) -> parens (showEnv1 env <> showVal u)
- Sub env (_,phi) -> parens (showEnv1 env <> text (show phi))
-showEnv1 (Upd env (_,u)) = showEnv1 env <> showVal u <> text ", "
-showEnv1 (Sub env (_,phi)) = showEnv1 env <> text (show phi) <> text ", "
-showEnv1 e = showEnv e
+ show = render . showEnv True
+
+showEnv :: Bool -> Env -> Doc
+showEnv b e =
+ let -- This decides if we should print "x = " or not
+ names x = if b then text x <+> equals else PP.empty
+
+ showEnv1 e = case e of
+ Upd env (x,u) -> showEnv1 env <> names x <+> showVal u <> comma
+ Sub env (i,phi) -> showEnv1 env <> names (show i) <+> text (show phi) <> comma
+ _ -> showEnv b e
+ in case e of
+ Empty -> PP.empty
+ Def _ env -> showEnv b env
+ Upd env (x,u) -> parens (showEnv1 env <+> names x <+> showVal u)
+ Sub env (i,phi) -> parens (showEnv1 env <+> names (show i) <+> text (show phi))
instance Show Loc where
show = render . showLoc
showVal :: Val -> Doc
showVal v = case v of
VU -> char 'U'
- Ter t env -> showTer1 t <+> showEnv env
+ Ter t@Sum{} rho -> showTer t <+> showEnv False rho
+ Ter t@Split{} rho -> showTer t <+> showEnv False rho
+ Ter t env -> showTer1 t <+> showEnv True env
VCon c us -> text c <+> showVals us
VPCon c a us phi -> text c <+> char '{' <+> showVal a <+> char '}' <+>
showVals us <+> showFormula phi
showVal1 :: Val -> Doc
showVal1 v = case v of
- VU -> char 'U'
- VCon c [] -> text c
- VVar{} -> showVal v
- Ter t@Sum{} rho -> showTer t <+> showEnv rho
- _ -> parens (showVal v)
+ VU -> showVal v
+ VCon c [] -> showVal v
+ VVar{} -> showVal v
+ Ter t@Sum{} rho -> showTer t <+> showEnv False rho
+ Ter t@Split{} rho -> showTer t <+> showEnv False rho
+ _ -> parens (showVal v)
showVals :: [Val] -> Doc
showVals = hsep . map showVal1
meets xs ys = nub [ meet x y | x <- xs, y <- ys, compatible x y ]
meetss :: [[Face]] -> [Face]
-meetss xss = foldr meets [eps] xss
+meetss = foldr meets [eps]
leq :: Face -> Face -> Bool
alpha `leq` beta = meetMaybe alpha beta == Just alpha
instance Show Formula where
show (Dir Zero) = "0"
show (Dir One) = "1"
- show (NegAtom a) = "-" ++ show a
+ show (NegAtom a) = '-' : show a
show (Atom a) = show a
show (a :\/: b) = show1 a ++ " \\/ " ++ show1 b
where show1 v@(a :/\: b) = "(" ++ show v ++ ")"
arbFormula :: [Name] -> Int -> Gen Formula
arbFormula names s =
- frequency [ (1, Dir <$> arbitrary)
- , (1, Atom <$> elements names)
- , (1, NegAtom <$> elements names)
- , (s, do op <- elements [andFormula,orFormula]
- op <$> arbFormula names s' <*> arbFormula names s')
- ]
- where s' = s `div` 3
+ frequency [ (1, Dir <$> arbitrary)
+ , (1, Atom <$> elements names)
+ , (1, NegAtom <$> elements names)
+ , (s, do op <- elements [andFormula,orFormula]
+ op <$> arbFormula names s' <*> arbFormula names s')
+ ]
+ where s' = s `div` 3
instance Arbitrary Formula where
arbitrary = do
orFormula phi psi = phi :\/: psi
dnf :: Formula -> Set (Set (Name,Dir))
-dnf (Dir One) = Set.singleton Set.empty
-dnf (Dir Zero) = Set.empty
-dnf (Atom n) = Set.singleton (Set.singleton (n,1))
-dnf (NegAtom n) = Set.singleton (Set.singleton (n,0))
+dnf (Dir One) = Set.singleton Set.empty
+dnf (Dir Zero) = Set.empty
+dnf (Atom n) = Set.singleton (Set.singleton (n,1))
+dnf (NegAtom n) = Set.singleton (Set.singleton (n,0))
dnf (phi :\/: psi) = dnf phi `Set.union` dnf psi
dnf (phi :/\: psi) = Set.fromList [ a `Set.union` b
| a <- Set.toList (dnf phi)
instance Nominal a => Nominal (Maybe a) where
support = maybe [] support
- act v f = fmap (\u -> act u f) v
+ act v f = fmap (`act` f) v
swap a n = fmap (`swap` n) a
instance Nominal Formula where
border v = Map.mapWithKey (const . face v)
shape :: System a -> System ()
-shape ts = border () ts
+shape = border ()
instance (Nominal a, Arbitrary a) => Arbitrary (System a) where
arbitrary = do