]> Git — Sourcephile - comptalang.git/blob - ledger/Hcompta/Format/Ledger/Unit.hs
Correction : rétro support de GHC 7.6.3 (Debian/jessie).
[comptalang.git] / ledger / Hcompta / Format / Ledger / Unit.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 {-# LANGUAGE StandaloneDeriving #-}
7 {-# LANGUAGE TypeFamilies #-}
8 {-# OPTIONS_GHC -fno-warn-orphans #-}
9 module Hcompta.Format.Ledger.Unit where
10
11 import Control.DeepSeq
12 import Data.Data
13 import Data.Eq (Eq(..))
14 import Data.Ord (Ord(..))
15 import Data.String (IsString)
16 import Data.Text (Text)
17 import qualified Data.Text as Text
18 import Data.Typeable ()
19 import Prelude ((.), Int)
20 import Text.Show (Show(..))
21
22 import qualified Hcompta.Unit as Unit
23
24 -- * Type 'Unit'
25
26 newtype Unit = Unit Text
27 deriving (Data, Eq, IsString, Ord, Show, Typeable)
28 instance Unit.Unit Unit where
29 unit_empty = Unit ""
30 unit_text (Unit t) = t
31 instance NFData Unit where
32 rnf (Unit t) = rnf t
33
34 unit_length :: Unit -> Int
35 unit_length = Text.length . Unit.unit_text
36
37 -- * Example 'Unit's
38
39 -- | 'Unit.unit_empty'.
40 scalar :: Unit
41 scalar = Unit.unit_empty
42
43 -- | <https://en.wikipedia.org/wiki/Swiss_franc Swiss franc> unit of currency.
44 chf :: Unit
45 chf = Unit "CHF"
46
47 -- | <https://en.wikipedia.org/wiki/Yuan Yuan> unit of currency.
48 cny :: Unit
49 cny = Unit "Ұ"
50
51 -- | <https://en.wikipedia.org/wiki/Euro Euro> unit of currency.
52 eur :: Unit
53 eur = Unit "€"
54
55 -- | <https://en.wikipedia.org/wiki/Pound_sterling Pound sterling> unit of currency.
56 gbp :: Unit
57 gbp = Unit "£"
58
59 -- | <https://en.wikipedia.org/wiki/Indian_rupee Indian rupee> unit of currency.
60 inr :: Unit
61 inr = Unit "₹"
62
63 -- | <https://en.wikipedia.org/wiki/Japanese_yen Japanese yen> unit of currency.
64 jpy :: Unit
65 jpy = Unit "¥"
66
67 -- | <https://en.wikipedia.org/wiki/Russian_ruble Russian ruble> unit of currency.
68 --
69 -- NOTE: Ꝑ (U+A750) is used as a replacement latin letter,
70 -- because GHC currently chokes on ₽ (U+20BD),
71 -- which is the recently (2014/02) assigned Unicode code-point
72 -- for this currency.
73 rub :: Unit
74 rub = Unit "Ꝑ"
75
76 -- | <https://en.wikipedia.org/wiki/United_States_dollar United States dollar> unit of currency.
77 usd :: Unit
78 usd = Unit "$"
79