]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Lib/Consable.hs
Épure hcompta-lib.
[comptalang.git] / lib / Hcompta / Lib / Consable.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# OPTIONS_GHC -fno-warn-orphans #-}
5
6 module Hcompta.Lib.Consable where
7
8 -- import Control.Applicative (Const(..))
9 import Data.Function (id)
10 -- import Data.Functor.Compose (Compose(..))
11 import Data.Monoid (Monoid(..))
12 import Data.Ord (Ord(..))
13 import qualified Data.Map.Strict as Map
14 import Data.Map.Strict (Map)
15
16 class Consable x m where
17 mcons :: x -> m -> m
18
19 instance Consable x () where
20 mcons _x = id
21 instance Consable x [x] where
22 mcons = (:)
23
24 instance (Monoid v, Ord k) => Consable (k, v) (Map k v) where
25 mcons (k, v) = Map.insertWith mappend k v
26
27 {-
28 instance Monoid (f (g x)) => Monoid ((Compose f g) x) where
29 mempty = Compose mempty
30 mappend (Compose x) (Compose y) = Compose (mappend x y)
31 -}