Skip to content

Commit

Permalink
Disallow unchecked record updates with fromNimber
Browse files Browse the repository at this point in the history
Previously, one could write 0 {fromNimber=-1} to bypass the
nonnegative check.

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Jan 2, 2014
1 parent 7f81035 commit 3e72bce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Data/Nimber.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ instance Show NimberException where
instance Exception NimberException

-- |The type of finite nimbers.
newtype Nimber = Nimber {fromNimber :: Integer} deriving (Eq, Ord)
newtype Nimber = Nimber Integer deriving (Eq, Ord)

nimSize :: Nimber -> Int
nimSize (Nimber a) = bit (intLog2 (integerLog2 a))
Expand Down Expand Up @@ -162,3 +162,7 @@ instance Floating Nimber where
asinh = throw (Innimerable "asinh")
atanh = throw (Innimerable "atanh")
acosh = throw (Innimerable "acosh")

-- |Convert a 'Nimber' to the corresponding natural number.
fromNimber :: Nimber -> Integer
fromNimber (Nimber a) = a
4 changes: 2 additions & 2 deletions nimber.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nimber
version: 0.1.2
version: 0.1.3
synopsis: Finite nimber arithmetic
description:
The finite nimbers, 'Nimber', are a quadratically closed field of
Expand Down Expand Up @@ -28,4 +28,4 @@ source-repository head
source-repository this
type: git
location: https://github.com/andersk/haskell-nimber
tag: 0.1.2
tag: 0.1.3

0 comments on commit 3e72bce

Please sign in to comment.