Skip to content

Commit

Permalink
Move ToJSON comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed May 7, 2019
1 parent 81c4651 commit 89d9529
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/core/src/Data/Quantity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ import qualified Data.Text as T
--
-- The unit is mostly a phantom type, but it is also included in the
-- @ToJSON@/@FromJSON@ instances.
--
-- >>> Aeson.encode $ Quantity @"lovelace" 14
-- {"unit":"lovelace","quantity":14}
newtype Quantity (unit :: Symbol) a = Quantity a
deriving stock (Generic, Show, Eq, Ord)
deriving newtype (Bounded, Enum)

instance NFData a => NFData (Quantity unit a)

-- >>> Aeson.encode $ Quantity @"lovelace" 14
-- {"unit":"lovelace","quantity":14}
instance (KnownSymbol unit, ToJSON a) => ToJSON (Quantity unit a) where
toJSON (Quantity a) = object
[ "unit" .= symbolVal (Proxy :: Proxy unit)
Expand Down

0 comments on commit 89d9529

Please sign in to comment.