1 {-# LANGUAGE AllowAmbiguousTypes #-}
3 module Literate.Accounting.Unit where
5 import Literate.Prelude
6 import Text.Show (ShowS, showParen, showString)
9 UnitName :: Symbol -> Unit
10 (:*:) :: Unit -> Unit -> Unit
11 (:/:) :: Unit -> Unit -> Unit
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
22 unitShow :: forall u. UnitShowS u => String
23 unitShow = unitShowS @u 0 ""