Commit 5984a698 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Override default `clearBit` method impl for `Natural`

The default implementation of `clearBit` is in terms of
`complement`. However, `complement` is not well-defined
for `Natural` and this consequently renders the default
implementation of `clearBit` dysfunctional.

This implements `clearBit` in terms of `testBit`
and `setBit` which are both well-defined for `Natural`s.

This addresses #13203
parent e3ba26f8
......@@ -345,6 +345,11 @@ instance Bits Natural where
-- TODO: setBit, clearBit, complementBit (needs more primitives)
-- NB: We cannot use the default impl of 'clearBit' due to
-- 'complement' not being well-defined for 'Natural' (c.f. #13203)
clearBit x i | testBit x i = complementBit x i
| otherwise = x
shiftL n 0 = n
shiftL (NatS# 0##) _ = NatS# 0##
shiftL (NatS# 1##) i = bit i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment