1
1
module Data.Int.AtLeast
2
- ( IntAL -- Constructor not exported. Use fromInt, fromInt' or clamp
2
+ ( IntAL -- Constructor not exported. Use fromInt, fromInt' or pullUp
3
3
, fromInt
4
4
, fromInt'
5
+ , pullUp
5
6
, fromMin
6
7
, clamp
7
8
, fromLength
@@ -21,6 +22,7 @@ module Data.Int.AtLeast
21
22
, divide
22
23
, weaken
23
24
, strengthen
25
+ , pullUp'
24
26
, gcd
25
27
, lcm
26
28
, lengthArray
@@ -40,6 +42,7 @@ import Data.Reflectable (class Reflectable, reflectType)
40
42
import Partial (crashWith )
41
43
import Prim.Int (class Add , class Compare , class Mul )
42
44
import Prim.Ordering (LT )
45
+ import Prim.TypeError (class Warn , Text )
43
46
import Test.QuickCheck.Arbitrary (class Arbitrary )
44
47
import Test.QuickCheck.Gen (chooseInt , elements , oneOf )
45
48
import Type.Proxy (Proxy (..))
@@ -97,13 +100,27 @@ fromInt' i =
97
100
else crashWith $
98
101
" Cannot convert Int " <> show i <> " to IntAL " <> show minInt
99
102
103
+ -- | Convert an `Int` to an `IntAL`, increasing the value to the type-level
104
+ -- | minimum if required
105
+ pullUp :: ∀ (min :: Int ). Reflectable min Int => Int -> IntAL min
106
+ pullUp i =
107
+ let
108
+ minInt = reflectType (Proxy :: _ min )
109
+ in
110
+ IntAL $ if i >= minInt then i else minInt
111
+
100
112
-- | Construct an `IntAL` equal to its type-level minimum
101
113
fromMin :: ∀ (min :: Int ). Reflectable min Int => IntAL min
102
114
fromMin = IntAL $ reflectType (Proxy :: _ min )
103
115
104
116
-- | Convert an `Int` to an `IntAL`, increasing the value to the type-level
105
117
-- | minimum if required
106
- clamp :: ∀ (min :: Int ). Reflectable min Int => Int -> IntAL min
118
+ clamp
119
+ :: ∀ (min :: Int )
120
+ . Warn (Text " `clamp` is deprecated in favor of `pullUp`" )
121
+ => Reflectable min Int
122
+ => Int
123
+ -> IntAL min
107
124
clamp i =
108
125
let
109
126
minInt = reflectType (Proxy :: _ min )
@@ -212,6 +229,15 @@ strengthen
212
229
-> Maybe (IntAL min_to )
213
230
strengthen (IntAL i) = fromInt i
214
231
232
+ -- | Increase the type-level minimum value, increasing the runtime value if
233
+ -- | necessary
234
+ pullUp'
235
+ :: ∀ (min_from :: Int ) (min_to :: Int )
236
+ . Reflectable min_to Int
237
+ => IntAL min_from
238
+ -> IntAL min_to
239
+ pullUp' (IntAL i) = pullUp i
240
+
215
241
-- | The greatest common divisor of two IntAL values with possibly different
216
242
-- | type-level minimums. Limited to types with strictly positive type-level
217
243
-- | minimums. Returns an IntAL 1
0 commit comments