From 46295fed52c1a108fda08f326a6f519367f67f49 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 May 2018 09:03:21 -0400 Subject: [PATCH] Define unEnvironment as a function rather than a field selector. --- src/Data/Abstract/Environment.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Data/Abstract/Environment.hs b/src/Data/Abstract/Environment.hs index 16b1b7b4c..b6d8bf6a4 100644 --- a/src/Data/Abstract/Environment.hs +++ b/src/Data/Abstract/Environment.hs @@ -37,12 +37,15 @@ import qualified Data.List.NonEmpty as NonEmpty -- | A LIFO stack of maps of names to addresses, representing a lexically-scoped evaluation environment. -- All behaviors can be assumed to be frontmost-biased: looking up "a" will check the most specific -- scope for "a", then the next, and so on. -newtype Environment location value = Environment { unEnvironment :: NonEmpty (Map.Map Name location) } +newtype Environment location value = Environment (NonEmpty (Map.Map Name location)) deriving (Eq, Ord, Show) -instance Eq location => Eq1 (Environment location) where liftEq _ a b = unEnvironment a == unEnvironment b -instance Ord location => Ord1 (Environment location) where liftCompare _ a b = unEnvironment a `compare` unEnvironment b -instance Show location => Show1 (Environment location) where liftShowsPrec _ _ = showsPrec +unEnvironment :: Environment location value -> NonEmpty (Map.Map Name location) +unEnvironment (Environment env) = env + +instance Eq location => Eq1 (Environment location) where liftEq _ (Environment a) (Environment b) = a == b +instance Ord location => Ord1 (Environment location) where liftCompare _ (Environment a) (Environment b) = a `compare` b +instance Show location => Show1 (Environment location) where liftShowsPrec _ _ = showsPrec -- | The provided list will be put into an Environment with one member, so fromList is total -- (despite NonEmpty's instance being partial). Don't pass in multiple Addresses for the @@ -106,7 +109,7 @@ insert name (Address value) (Environment (a :| as)) = Environment (Map.insert na -- | Remove a 'Name' from the environment. -- -- >>> delete (name "foo") shadowed --- Environment {unEnvironment = fromList [] :| []} +-- Environment (fromList [] :| []) delete :: Name -> Environment location value -> Environment location value delete name = trim . Environment . fmap (Map.delete name) . unEnvironment