Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit f3ccc5b

Browse files
committed
Represent ExcSet as a product of sets instead of a set of sums.
Duality!
1 parent 229594b commit f3ccc5b

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

semantic-analysis/src/Analysis/Exception.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ newtype Exception = Exception { exceptionName :: String }
2323
deriving (Eq, Ord, Show)
2424

2525
-- | Sets whose elements are each a variable or an exception.
26-
newtype ExcSet = ExcSet { values :: Set.Set (Either Name Exception) }
27-
deriving (Eq, Monoid, Semigroup, Ord, Show)
26+
data ExcSet = ExcSet { freeVariables :: Set.Set Name, exceptions :: Set.Set Exception }
27+
deriving (Eq, Ord, Show)
28+
29+
instance Semigroup ExcSet where
30+
ExcSet v1 e1 <> ExcSet v2 e2 = ExcSet (v1 <> v2) (e1 <> e2)
31+
32+
instance Monoid ExcSet where
33+
mempty = ExcSet mempty mempty
2834

2935
var :: Name -> ExcSet
30-
var = ExcSet . Set.singleton . Left
36+
var v = ExcSet (Set.singleton v) mempty
3137

3238
exc :: Exception -> ExcSet
33-
exc = ExcSet . Set.singleton . Right
39+
exc e = ExcSet mempty (Set.singleton e)
3440

3541

3642
newtype ExcC m a = ExcC { runExcC :: m a }
@@ -50,6 +56,6 @@ instance (Algebra sig m, Alternative m) => Algebra (Dom ExcSet :+: sig) (ExcC m)
5056
-- FIXME: return a set indicating a failure with e as the payload
5157
DDie e -> pure $ e <$ ctx
5258
where
53-
nil = ExcSet mempty <$ ctx
59+
nil = (mempty :: ExcSet) <$ ctx
5460

5561
R other -> alg (runExcC . hdl) other ctx

0 commit comments

Comments
 (0)