Skip to content

Commit 2b7f475

Browse files
committed
[ fix #55 ] Keep global properties on display
1 parent 2b84e82 commit 2b7f475

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Syntax/ConstExpr.hs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
module Syntax.ConstExpr where
22

3-
import Data.Bifunctor ( bimap )
3+
import Data.Char ( isLower )
44
import Data.List ( partition )
5-
import Data.Maybe ( mapMaybe )
5+
import Data.Maybe ( listToMaybe
6+
, mapMaybe
7+
)
68
import qualified Data.Set as Set
9+
import qualified Data.Text as Text
710
import GCL.Common ( fv )
811
import Syntax.Abstract
9-
import Syntax.Common ( Name )
12+
import Syntax.Common ( Name
13+
, nameToText
14+
)
1015

1116
pickGlobals :: [Declaration] -> ([Expr], [Expr])
12-
pickGlobals =
13-
bimap (map snd) (map snd)
14-
. partition isGlobalProp
15-
. mapMaybe extractAssertion
17+
pickGlobals = partition isGlobalProp . mapMaybe extractAssertion
1618
where
1719
-- An assertion is a global prop
18-
-- if it has no free variables other than the accompanied declared names
19-
isGlobalProp :: ([Name], Expr) -> Bool
20-
isGlobalProp (names, assertion) =
21-
fv assertion `Set.isSubsetOf` Set.fromList names
20+
-- if all of its free variables are of CONSTANTS
21+
isGlobalProp :: Expr -> Bool
22+
isGlobalProp assertion = Set.null $ Set.filter nameIsVar (fv assertion)
23+
24+
nameIsVar :: Name -> Bool
25+
nameIsVar name =
26+
maybe False isLower (listToMaybe (Text.unpack (nameToText name)))
2227

2328
-- Extracts both the assertion and those declared names
24-
extractAssertion :: Declaration -> Maybe ([Name], Expr)
25-
extractAssertion (ConstDecl _ _ Nothing _) = Nothing
26-
extractAssertion (ConstDecl names _ (Just e) _) = Just (names, e)
27-
extractAssertion (VarDecl _ _ Nothing _) = Nothing
28-
extractAssertion (VarDecl names _ (Just e) _) = Just (names, e)
29+
extractAssertion :: Declaration -> Maybe Expr
30+
extractAssertion (ConstDecl _ _ e _) = e
31+
extractAssertion (VarDecl _ _ e _) = e

0 commit comments

Comments
 (0)