From 6485f858edb3c8968ad3c30680f1107936788a40 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 18 Dec 2019 10:51:02 -0500 Subject: [PATCH] Move Named & Ignored into Analysis.Name. --- semantic-analysis/src/Analysis/Name.hs | 32 +++++++++++++++++++++++++- semantic-core/src/Core/Name.hs | 31 +------------------------ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/semantic-analysis/src/Analysis/Name.hs b/semantic-analysis/src/Analysis/Name.hs index 99b1f809b..3056f5f76 100644 --- a/semantic-analysis/src/Analysis/Name.hs +++ b/semantic-analysis/src/Analysis/Name.hs @@ -1,6 +1,12 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE DeriveTraversable, GeneralizedNewtypeDeriving #-} module Analysis.Name ( Name(..) +, Named(..) +, named +, named' +, namedName +, namedValue +, Ignored(..) ) where import Data.String (IsString) @@ -9,3 +15,27 @@ import Data.Text (Text) -- | User-specified and -relevant names. newtype Name = Name { unName :: Text } deriving (Eq, IsString, Ord, Show) + + +-- | Annotates an @a@ with a 'Name'-provided name, which is ignored for '==' and 'compare'. +data Named a = Named (Ignored Name) a + deriving (Eq, Foldable, Functor, Ord, Show, Traversable) + +named :: Name -> a -> Named a +named = Named . Ignored + +named' :: Name -> Named Name +named' u = Named (Ignored u) u + +namedName :: Named a -> Name +namedName (Named (Ignored n) _) = n + +namedValue :: Named a -> a +namedValue (Named _ a) = a + + +newtype Ignored a = Ignored a + deriving (Foldable, Functor, Show, Traversable) + +instance Eq (Ignored a) where _ == _ = True +instance Ord (Ignored a) where compare _ _ = EQ diff --git a/semantic-core/src/Core/Name.hs b/semantic-core/src/Core/Name.hs index 27bfb4638..af10a53b3 100644 --- a/semantic-core/src/Core/Name.hs +++ b/semantic-core/src/Core/Name.hs @@ -1,12 +1,6 @@ {-# LANGUAGE DeriveGeneric, DeriveTraversable, GeneralizedNewtypeDeriving, LambdaCase, OverloadedLists #-} module Core.Name -( Name (..) -, Named(..) -, named -, named' -, namedName -, namedValue -, Ignored(..) +( module Analysis.Name , reservedNames , isSimpleCharacter , needsQuotation @@ -18,29 +12,6 @@ import Data.HashSet (HashSet) import qualified Data.HashSet as HashSet import Data.Text as Text (any, unpack) --- | Annotates an @a@ with a 'Name'-provided name, which is ignored for '==' and 'compare'. -data Named a = Named (Ignored Name) a - deriving (Eq, Foldable, Functor, Ord, Show, Traversable) - -named :: Name -> a -> Named a -named = Named . Ignored - -named' :: Name -> Named Name -named' u = Named (Ignored u) u - -namedName :: Named a -> Name -namedName (Named (Ignored n) _) = n - -namedValue :: Named a -> a -namedValue (Named _ a) = a - -newtype Ignored a = Ignored a - deriving (Foldable, Functor, Show, Traversable) - -instance Eq (Ignored a) where _ == _ = True -instance Ord (Ignored a) where compare _ _ = EQ - - reservedNames :: HashSet String reservedNames = [ "#true", "#false", "if", "then", "else" , "#unit", "load", "rec", "#record"]