1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE NamedFieldPuns #-}
6 {-# LANGUAGE TypeFamilies #-}
7 {-# OPTIONS_GHC -fno-warn-orphans #-}
8 module Hcompta.LCC.Tag where
10 import Control.DeepSeq (NFData(..))
11 import Data.Data (Data(..))
12 import Data.Eq (Eq(..))
13 import Data.Function (($), flip)
14 import Data.Monoid (Monoid(..))
15 import Data.NonNull (NonNull)
16 import Data.Ord (Ord(..))
17 import Data.Semigroup (Semigroup(..))
18 import Data.Text (Text)
19 import Data.TreeMap.Strict (TreeMap)
20 import Data.Typeable (Typeable)
22 import Text.Show (Show)
23 import qualified Data.MonoTraversable as MT
24 import qualified Data.TreeMap.Strict as TreeMap
26 import qualified Hcompta as H
27 import Hcompta.LCC.Name
32 { tag_path :: Tag_Path
33 , tag_data :: Tag_Data
34 } deriving (Data, Eq, Ord, Show, Typeable)
35 instance NFData Tag where
36 rnf (Tag p d) = rnf p `seq` rnf d
39 newtype Tag_Path = Tag_Path (NonNull [Tag_Path_Section])
40 deriving (Data, Eq, NFData, Ord, Semigroup, Show, Typeable)
41 instance H.Tag_Path Tag_Path
42 type Tag_Path_Section = Name
45 newtype Tag_Data = Tag_Data Text
46 deriving (Data, Eq, NFData, Ord, Show, Typeable)
47 instance H.Tag_Data Tag_Data
51 = Tags (TreeMap Tag_Path_Section [Tag_Data])
52 deriving (Data, Eq, NFData, Ord, Show, Typeable)
53 instance Semigroup Tags where
55 Tags $ TreeMap.union (flip (<>)) x y
56 instance Monoid Tags where
59 type instance MT.Element Tags = Tag