From 71244796470aef2b2cd7e639653ceef2a0552a3b Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 14 Feb 2020 14:55:47 +0100 Subject: [PATCH] Add `subtract` to the daml-stdlib (#4523) 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 --- compiler/damlc/daml-prim-src/GHC/Num.daml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/damlc/daml-prim-src/GHC/Num.daml b/compiler/damlc/daml-prim-src/GHC/Num.daml index e55b50182e..47b0560f01 100644 --- a/compiler/damlc/daml-prim-src/GHC/Num.daml +++ b/compiler/damlc/daml-prim-src/GHC/Num.daml @@ -16,6 +16,7 @@ module GHC.Num , Signed (..) , Number (..) , (%) + , subtract ) where import GHC.Base @@ -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: --