]> Git — Sourcephile - tmp/julm/literate-invoice.git/blob - src/Literate/Accounting/Unit.hs
maint/correctness(Work): use sum type for ScopeId
[tmp/julm/literate-invoice.git] / src / Literate / Accounting / Unit.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2
3 module Literate.Accounting.Unit where
4
5 import Literate.Prelude
6 import Text.Show (ShowS, showParen, showString)
7
8 data Unit where
9 UnitName :: Symbol -> Unit
10 (:*:) :: Unit -> Unit -> Unit
11 (:/:) :: Unit -> Unit -> Unit
12
13 class UnitShowS (u :: Unit) where
14 unitShowS :: Int -> ShowS
15 instance KnownSymbol u => UnitShowS (UnitName u) where
16 unitShowS _prec = showString (symbolVal (Proxy @u))
17 instance (UnitShowS x, UnitShowS y) => UnitShowS (x :*: y) where
18 unitShowS p = showParen (7 <= p) $ unitShowS @x 7 . showString "\x202F*\x202F" . unitShowS @y 7
19 instance (UnitShowS x, UnitShowS y) => UnitShowS (x :/: y) where
20 unitShowS p = showParen (7 <= p) $ unitShowS @x 7 . showString "\x202F/\x202F" . unitShowS @y 7
21
22 unitShow :: forall u. UnitShowS u => String
23 unitShow = unitShowS @u 0 ""