Skip to content

Commit

Permalink
Add MINIMAL pragma for Additive type class (#11001)
Browse files Browse the repository at this point in the history
* Add MINIMAL pragma for Additive type class

This ensures that the compiler gives an error if both (-) and negate are missing in an instance

Fixes #11000

changelog_begin
changelog_end

* Add test case to ensure incomplete Additive instance declaration triggers error message
  • Loading branch information
akrmn authored Sep 23, 2021
1 parent 8de162b commit 35666ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/damlc/daml-prim-src/GHC/Num.daml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ infixl 7 %
-- * `negate` gives the additive inverse, ie: `x + negate x` = `aunit`
--
class Additive a where
{-# MINIMAL (+), aunit, ((-) | negate) #-}
-- | Add the two arguments together.
(+) : a -> a -> a
-- | The additive identity for the type. For example, for numbers, this is 0.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- @ERROR range=14:10-14:23; • No explicit implementation for; either ‘-’ or ‘negate’; • In the instance declaration for ‘Additive Expr’

module IncompleteAdditiveInstance where

data Numero = Zero | Uno | Dos | Tres

data Expr = Add (Expr, Expr)
| Neg Expr
| Const Numero

instance Additive Expr where
(+) = curry Add
-- negate = Neg -- uncomment to fix!
aunit = Const Zero

0 comments on commit 35666ca

Please sign in to comment.