From 27cf519a5fda0ad3821e4f545632adc36a83f09b Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 1 Apr 2019 20:37:22 +0300 Subject: [PATCH] Add Foldable & Traversable Field instances --- Cabal/Distribution/Fields/Field.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Cabal/Distribution/Fields/Field.hs b/Cabal/Distribution/Fields/Field.hs index ad08ee72d50..3cceb7e4fa5 100644 --- a/Cabal/Distribution/Fields/Field.hs +++ b/Cabal/Distribution/Fields/Field.hs @@ -1,4 +1,6 @@ {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE DeriveFoldable #-} +{-# LANGUAGE DeriveTraversable #-} -- | Cabal-like file AST types: 'Field', 'Section' etc -- -- These types are parametrized by an annotation. @@ -33,7 +35,7 @@ import qualified Data.Char as Char data Field ann = Field !(Name ann) [FieldLine ann] | Section !(Name ann) [SectionArg ann] [Field ann] - deriving (Eq, Show, Functor) + deriving (Eq, Show, Functor, Foldable, Traversable) -- | Section of field name fieldName :: Field ann -> Name ann @@ -56,7 +58,7 @@ fieldUniverse f@(Field _ _) = [f] -- -- /Invariant:/ 'ByteString' has no newlines. data FieldLine ann = FieldLine !ann !ByteString - deriving (Eq, Show, Functor) + deriving (Eq, Show, Functor, Foldable, Traversable) -- | Section arguments, e.g. name of the library data SectionArg ann @@ -66,7 +68,7 @@ data SectionArg ann -- ^ quoted string | SecArgOther !ann !ByteString -- ^ everything else, mm. operators (e.g. in if-section conditionals) - deriving (Eq, Show, Functor) + deriving (Eq, Show, Functor, Foldable, Traversable) -- | Extract annotation from 'SectionArg'. sectionArgAnn :: SectionArg ann -> ann @@ -84,7 +86,7 @@ type FieldName = ByteString -- -- /Invariant/: 'ByteString' is lower-case ASCII. data Name ann = Name !ann !FieldName - deriving (Eq, Show, Functor) + deriving (Eq, Show, Functor, Foldable, Traversable) mkName :: ann -> FieldName -> Name ann mkName ann bs = Name ann (B.map Char.toLower bs)