Skip to content

Commit fcd1777

Browse files
committed
Added fromInt
1 parent 898f35a commit fcd1777

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- `fromInt`
1011

1112
Bugfixes:
1213

src/Data/Ring/Extra.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Data.Ring.Extra where
2+
3+
import Data.Ord ((>=))
4+
import Data.Ring (class Ring, one, negate)
5+
import Data.Monoid (power)
6+
import Data.Monoid.Additive (Additive(..))
7+
8+
fromInt :: forall a. Ring a => Int -> a
9+
fromInt x =
10+
if x >= 0
11+
then (\(Additive i) -> i) (power (Additive one) x)
12+
else negate (fromInt (negate x))

0 commit comments

Comments
 (0)