{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.Anchor where import Control.DeepSeq (NFData(..)) import Data.Data import Data.Eq (Eq) import Data.Function (($), (.), id) import Data.Functor (Functor(..)) import Data.Int (Int) import Data.NonNull (NonNull) import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import Data.Monoid (Monoid(..)) import Data.Text (Text) import Data.Typeable () import qualified Data.Sequences as Seqs import qualified Data.MonoTraversable as MT import Text.Show (Show) import Hcompta.Lib.Consable import Hcompta.Name -- * Class 'Anchor' class Anchor a _Anchor :: Proxy Anchor _Anchor = Proxy -- * Class 'Anchors' class Anchor (MT.Element as) => Anchors as _Anchors :: Proxy Anchors _Anchors = Proxy {- class Anchor (Anchors_Anchor as) => Anchors as where type Anchors_Anchor as -- * Type 'Anchor' type Anchor = Anchor_Path type Anchor_Section = Name type Anchor_Path = NonNull [Anchor_Section] -- * Type 'Anchors' newtype Anchors = Anchors (Map Anchor_Path ()) deriving (Data, Eq, NFData, Show, Typeable , MT.MonoFunctor, MT.MonoFoldable) -- TODO: use Data.Set? unAnchors :: Anchors -> Map Anchor () unAnchors (Anchors m) = m -} {- instance Monoid Anchors where mempty = Anchors mempty mappend (Anchors x0) (Anchors x1) = Anchors (mappend x0 x1) instance Consable Anchor Anchors where mcons = anchor_cons instance NFData Anchors where rnf (Anchors m) = rnf m -- | Return the given 'Anchors' with the given 'Anchor' incorporated. anchor_cons :: Anchor -> Anchors -> Anchors anchor_cons a (Anchors as) = Anchors $ mcons (a, ()) as -- | Return the 'Anchor' formed by the given 'Anchor_Path' and 'Value'. anchor :: Anchor_Path -> Anchor anchor = id -- | Return the 'Value' formed by the given 'Anchor_Section' and 'Anchor_Section's. anchor_path :: Anchor_Section -> [Anchor_Section] -> Anchor_Path anchor_path = (:|) -- | Return the number of 'Anchor_Section's in the given 'Anchor'. anchor_depth :: Anchor_Path -> Int anchor_depth = NonEmpty.length -- | Return a 'Anchor_Path' from the given list. anchor_from_List :: [Anchor] -> Anchors anchor_from_List = Anchors . Map.fromList . fmap (, ()) -}