From a4a23e9a510c3c8a240528d02f175f095db69d17 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Fri, 17 Jan 2020 10:31:09 -0500 Subject: [PATCH] Move the Named functor to Analysis.Functor.Named. --- .../src/Analysis/Functor/Named.hs | 32 +++++++++++++++++++ semantic-analysis/src/Analysis/Name.hs | 30 ++--------------- 2 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 semantic-analysis/src/Analysis/Functor/Named.hs diff --git a/semantic-analysis/src/Analysis/Functor/Named.hs b/semantic-analysis/src/Analysis/Functor/Named.hs new file mode 100644 index 000000000..56b117f1a --- /dev/null +++ b/semantic-analysis/src/Analysis/Functor/Named.hs @@ -0,0 +1,32 @@ +module Analysis.Functor.Named +( module Analysis.Name +, Named (..) +, named +, named' +, namedName +, namedValue +) where + +import Analysis.Name + +-- | Annotates an @a@ with a 'Name'-provided name, which is ignored for '==' and 'compare'. +data Named a = Named Name a + deriving (Foldable, Functor, Show, Traversable) + +named :: Name -> a -> Named a +named = Named + +named' :: Name -> Named Name +named' u = Named u u + +namedName :: Named a -> Name +namedName (Named n _) = n + +namedValue :: Named a -> a +namedValue (Named _ a) = a + +instance Eq a => Eq (Named a) where + (==) = (==) `on` namedValue + +instance Ord a => Ord (Named a) where + compare = compare `on` namedValue diff --git a/semantic-analysis/src/Analysis/Name.hs b/semantic-analysis/src/Analysis/Name.hs index 024b4eda1..b0586105a 100644 --- a/semantic-analysis/src/Analysis/Name.hs +++ b/semantic-analysis/src/Analysis/Name.hs @@ -1,14 +1,9 @@ -{-# LANGUAGE DeriveTraversable, GeneralizedNewtypeDeriving #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Analysis.Name ( Name(..) -, Named(..) -, named -, named' -, namedName -, namedValue ) where -import Data.Function (on) import Data.String (IsString) import Data.Text (Text) @@ -17,24 +12,3 @@ 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 Name a - deriving (Foldable, Functor, Show, Traversable) - -named :: Name -> a -> Named a -named = Named - -named' :: Name -> Named Name -named' u = Named u u - -namedName :: Named a -> Name -namedName (Named n _) = n - -namedValue :: Named a -> a -namedValue (Named _ a) = a - -instance Eq a => Eq (Named a) where - (==) = (==) `on` namedValue - -instance Ord a => Ord (Named a) where - compare = compare `on` namedValue