Skip to content

Commit

Permalink
Add subtract to the daml-stdlib (digital-asset#4523)
Browse files Browse the repository at this point in the history
changelog_begin

- [DAML Standard Library] Add a ``subtract`` function which is useful
  as a replacement for sections of ``(-)``, e.g., ``subtract 1`` is
  equivalent to ``\x -> x - 1``.

changelog_end
  • Loading branch information
cocreature authored Feb 14, 2020
1 parent a589f4a commit 7124479
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/damlc/daml-prim-src/GHC/Num.daml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module GHC.Num
, Signed (..)
, Number (..)
, (%)
, subtract
) where

import GHC.Base
Expand Down Expand Up @@ -58,6 +59,14 @@ class Additive a where
negate : a -> a
negate x = aunit - x

-- | `subtract x y` is equivalent to `y - x`.
--
-- This is useful for partial application, e.g., in `subtract 1` since `(- 1)` is
-- interpreted as the number `-1` and not a function that subtracts `1` from
-- its argument.
subtract : Additive a => a -> a -> a
subtract x y = y - x

-- | Use the `Multiplicative` class for types that can be multiplied.
-- Instances have to respect the following laws:
--
Expand Down

0 comments on commit 7124479

Please sign in to comment.