Skip to content

Commit

Permalink
Add operator precedences in Clash.Class.Num (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan committed May 16, 2024
1 parent c053e46 commit a245bb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGED: Added operator precedences for infix usage of functions exported from `Clash.Class.Num`: `mul`, `add`, `sub`, `satMul`, `satAdd`, `satSub`, `boundedMul`, `boundedAdd`, and `boundedSub`. This means that expressions such as `` a `add` b `mul` c `` now get parsed as `` a `add` (b `mul` c) `` instead of `` (a `add` b) `mul` c ``.
10 changes: 10 additions & 0 deletions clash-prelude/src/Clash/Class/Num.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-|
Copyright : (C) 2013-2016, University of Twente
2024, Google LLC
License : BSD2 (see the file LICENSE)
Maintainer : Christiaan Baaij <christiaan.baaij@gmail.com>
-}
Expand Down Expand Up @@ -42,6 +43,9 @@ class ExtendingNum a b where
-- that is potentially different from either argument.
mul :: a -> b -> MResult a b

infixl 7 `mul`
infixl 6 `add`, `sub`

-- * Saturating arithmetic functions

-- | Determine how overflow and underflow are handled by the functions in
Expand Down Expand Up @@ -76,19 +80,25 @@ class (Bounded a, Num a) => SaturatingNum a where
satPred s n = satSub s n 1
{-# INLINE satPred #-}

infixl 7 `satMul`
infixl 6 `satAdd`, `satSub`

-- | Addition that clips to 'maxBound' on overflow, and 'minBound' on underflow
boundedAdd :: SaturatingNum a => a -> a -> a
boundedAdd = satAdd SatBound
{-# INLINE boundedAdd #-}
infixl 6 `boundedAdd`

-- | Subtraction that clips to 'maxBound' on overflow, and 'minBound' on
-- underflow
boundedSub :: SaturatingNum a => a -> a -> a
boundedSub = satSub SatBound
{-# INLINE boundedSub #-}
infixl 6 `boundedSub`

-- | Multiplication that clips to 'maxBound' on overflow, and 'minBound' on
-- underflow
boundedMul :: SaturatingNum a => a -> a -> a
boundedMul = satMul SatBound
{-# INLINE boundedMul #-}
infixl 7 `boundedMul`

0 comments on commit a245bb8

Please sign in to comment.