HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehedgehog-1.7Haskell2010

Hedgehog.Internal.Range

  • 2 types
  • 23 values
  • Packagehedgehog-1.7
  • Exports25
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRange.hs

Size

1 declaration
newtypenewtype Size
#

Tests are parameterized by the size of the randomly-generated data. The meaning of a Size value depends on the particular generator used, but it must always be a number between 0 and 99 inclusive.

Constructors

Instances8Enum, Eq, Integral, Num, Ord, Read, …
  • Enum SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Eq SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Integral SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Num SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Ord SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Read SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Real SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
  • Show SizeDefined in hedgehog-1.7 · Hedgehog.Internal.Range

Range

5 declarations
datadata Range a
#

A range describes the bounds of a number to generate, which may or may not be dependent on a Size.

The constructor takes an origin between the lower and upper bound, and a function from Size to bounds. As the size goes towards 0, the values go towards the origin.

Constructors

Instances1Functor
  • Functor RangeDefined in hedgehog-1.7 · Hedgehog.Internal.Range
valueorigin :: Range a -> a
#

Get the origin of a range. This might be the mid-point or the lower bound, depending on what the range represents.

The bounds of a range are scaled around this value when using the linear family of combinators.

When using a Range to generate numbers, the shrinking function will shrink towards the origin.

valuebounds :: Size -> Range a -> (a, a)
#

Get the extents of a range, for a given size.

Constant

4 declarations
valuesingleton :: a -> Range a
#

Construct a range which represents a constant single value.

Example1 expression
bounds x $ singleton 5(5,5)
Example1 expression
origin $ singleton 55
valueconstant :: a -> a -> Range a
#

Construct a range which is unaffected by the size parameter.

A range from 0 to 10, with the origin at 0:

Example1 expression
bounds x $ constant 0 10(0,10)
Example1 expression
origin $ constant 0 100
valueconstantFrom
  1. :: a

    Origin (the value produced when the size parameter is 0).

  2. -> a

    Lower bound (the bottom of the range when the size parameter is 99).

  3. -> a

    Upper bound (the top of the range when the size parameter is 99).

  4. -> Range a
#

Construct a range which is unaffected by the size parameter with a origin point which may differ from the bounds.

A range from -10 to 10, with the origin at 0:

Example1 expression
bounds x $ constantFrom 0 (-10) 10(-10,10)
Example1 expression
origin $ constantFrom 0 (-10) 100

A range from 1970 to 2100, with the origin at 2000:

Example1 expression
bounds x $ constantFrom 2000 1970 2100(1970,2100)
Example1 expression
origin $ constantFrom 2000 1970 21002000
valueconstantBounded :: (Bounded a, Num a) => Range a
#

Construct a range which is unaffected by the size parameter using the full range of a data type.

A range from -128 to 127, with the origin at 0:

Example1 expression
bounds x (constantBounded :: Range Int8)(-128,127)
Example1 expression
origin (constantBounded :: Range Int8)0

Linear

5 declarations
valuelinear :: Integral a => a -> a -> Range a
#

Construct a range which scales the second bound relative to the size parameter.

Example1 expression
bounds 0 $ linear 0 10(0,0)
Example1 expression
bounds 50 $ linear 0 10(0,5)
Example1 expression
bounds 99 $ linear 0 10(0,10)
valuelinearFrom
  1. :: Integral a
  2. => a

    Origin (the value produced when the size parameter is 0).

  3. -> a

    Lower bound (the bottom of the range when the size parameter is 99).

  4. -> a

    Upper bound (the top of the range when the size parameter is 99).

  5. -> Range a
#

Construct a range which scales the bounds relative to the size parameter.

Example1 expression
bounds 0 $ linearFrom 0 (-10) 10(0,0)
Example1 expression
bounds 50 $ linearFrom 0 (-10) 20(-5,10)
Example1 expression
bounds 99 $ linearFrom 0 (-10) 20(-10,20)
valuelinearFrac :: (Fractional a, Ord a) => a -> a -> Range a
#

Construct a range which scales the second bound relative to the size parameter.

This works the same as linear, but for fractional values.

valuelinearBounded :: (Bounded a, Integral a) => Range a
#

Construct a range which is scaled relative to the size parameter and uses the full range of a data type.

Example1 expression
bounds 0 (linearBounded :: Range Int8)(0,0)
Example1 expression
bounds 50 (linearBounded :: Range Int8)(-64,64)
Example1 expression
bounds 99 (linearBounded :: Range Int8)(-128,127)

Exponential

5 declarations
valueexponential :: Integral a => a -> a -> Range a
#

Construct a range which scales the second bound exponentially relative to the size parameter.

Example1 expression
bounds 0 $ exponential 1 512(1,1)
Example1 expression
bounds 11 $ exponential 1 512(1,2)
Example1 expression
bounds 22 $ exponential 1 512(1,4)
Example1 expression
bounds 77 $ exponential 1 512(1,128)
Example1 expression
bounds 88 $ exponential 1 512(1,256)
Example1 expression
bounds 99 $ exponential 1 512(1,512)
valueexponentialFrom
  1. :: Integral a
  2. => a

    Origin (the value produced when the size parameter is 0).

  3. -> a

    Lower bound (the bottom of the range when the size parameter is 99).

  4. -> a

    Upper bound (the top of the range when the size parameter is 99).

  5. -> Range a
#

Construct a range which scales the bounds exponentially relative to the size parameter.

Example1 expression
bounds 0 $ exponentialFrom 0 (-128) 512(0,0)
Example1 expression
bounds 25 $ exponentialFrom 0 (-128) 512(-2,4)
Example1 expression
bounds 50 $ exponentialFrom 0 (-128) 512(-11,22)
Example1 expression
bounds 75 $ exponentialFrom 0 (-128) 512(-39,112)
Example1 expression
bounds 99 $ exponentialFrom x (-128) 512(-128,512)
valueexponentialBounded :: (Bounded a, Integral a) => Range a
#

Construct a range which is scaled exponentially relative to the size parameter and uses the full range of a data type.

Example1 expression
bounds 0 (exponentialBounded :: Range Int8)(0,0)
Example1 expression
bounds 50 (exponentialBounded :: Range Int8)(-11,11)
Example1 expression
bounds 99 (exponentialBounded :: Range Int8)(-128,127)
valueexponentialFloat :: (Floating a, Ord a) => a -> a -> Range a
#

Construct a range which scales the second bound exponentially relative to the size parameter.

This works the same as exponential, but for floating-point values.

Example1 expression
bounds 0 $ exponentialFloat 0 10(0.0,0.0)
Example1 expression
bounds 50 $ exponentialFloat 0 10(0.0,2.357035250656098)
Example1 expression
bounds 99 $ exponentialFloat 0 10(0.0,10.0)
valueexponentialFloatFrom :: (Floating a, Ord a) => a -> a -> a -> Range a
#

Construct a range which scales the bounds exponentially relative to the size parameter.

This works the same as exponentialFrom, but for floating-point values.

Example1 expression
bounds 0 $ exponentialFloatFrom 0 (-10) 20(0.0,0.0)
Example1 expression
bounds 50 $ exponentialFloatFrom 0 (-10) 20(-2.357035250656098,3.6535836249197002)
Example1 expression
bounds 99 $ exponentialFloatFrom x (-10) 20(-10.0,20.0)

Internal

5 declarations

These functions are exported in case you need them in a pinch, but are not part of the public API and may change at any time, even as part of a minor update.

valueclamp :: Ord a => a -> a -> a -> a
#

Truncate a value so it stays within some range.

Example1 expression
clamp 5 10 1510
Example1 expression
clamp 5 10 05