-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Refinement types with static and runtime checking -- -- For an extensive introduction to the library please follow to this -- blog-post. @package refined @version 0.8 -- | This module exports the Refined type with its constructor. This -- is very risky! In particular, the Coercible instances will be -- visible throughout the importing module. It is usually better to build -- the necessary coercions locally using the utilities in -- Refined.Unsafe, but in some cases it may be more convenient to -- write a separate module that imports this one and exports some large -- coercion. module Refined.Unsafe.Type -- | A refinement type, which wraps a value of type x. newtype Refined (p :: k) x Refined :: x -> Refined (p :: k) x instance forall k (p :: k). Data.Foldable.Foldable (Refined.Unsafe.Type.Refined p) instance forall k (p :: k) x. GHC.Show.Show x => GHC.Show.Show (Refined.Unsafe.Type.Refined p x) instance forall k (p :: k) x. Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Refined.Unsafe.Type.Refined p x) instance forall k (p :: k) x. Data.Hashable.Class.Hashable x => Data.Hashable.Class.Hashable (Refined.Unsafe.Type.Refined p x) instance forall k (p :: k) x. GHC.Classes.Ord x => GHC.Classes.Ord (Refined.Unsafe.Type.Refined p x) instance forall k (p :: k) x. GHC.Classes.Eq x => GHC.Classes.Eq (Refined.Unsafe.Type.Refined p x) instance forall k x (p :: k). Language.Haskell.TH.Syntax.Lift x => Language.Haskell.TH.Syntax.Lift (Refined.Unsafe.Type.Refined p x) -- | In type theory, a refinement type is a type endowed with a predicate -- which is assumed to hold for any element of the refined type. -- -- This library allows one to capture the idea of a refinement type using -- the Refined type. A Refined p x wraps -- a value of type x, ensuring that it satisfies a type-level -- predicate p. -- -- A simple introduction to this library can be found here: -- http://nikita-volkov.github.io/refined/ module Refined -- | A refinement type, which wraps a value of type x. data Refined (p :: k) x -- | A smart constructor of a Refined value. Checks the input value -- at runtime. refine :: forall p x. Predicate p x => x -> Either RefineException (Refined p x) -- | Like refine, but discards the refinement. This _can_ be useful -- when you only need to validate that some value at runtime satisfies -- some predicate. See also reifyPredicate. refine_ :: forall p x. Predicate p x => x -> Either RefineException x -- | Constructs a Refined value at run-time, calling throwM -- if the value does not satisfy the predicate. refineThrow :: (Predicate p x, MonadThrow m) => x -> m (Refined p x) -- | Constructs a Refined value at run-time, calling fail if -- the value does not satisfy the predicate. refineFail :: (Predicate p x, MonadFail m) => x -> m (Refined p x) -- | Constructs a Refined value at run-time, calling -- throwError if the value does not satisfy the predicate. refineError :: (Predicate p x, MonadError RefineException m) => x -> m (Refined p x) -- | Like refine, but, when the value doesn't satisfy the predicate, -- returns a Refined value with the predicate negated, instead of -- returning RefineException. -- --
--   >>> isRight (refineEither @Even @Int 42)
--   True
--   
-- --
--   >>> isLeft (refineEither @Even @Int 43)
--   True
--   
refineEither :: forall p x. Predicate p x => x -> Either (Refined (Not p) x) (Refined p x) -- | Constructs a Refined value at compile-time using -- -XTemplateHaskell. -- -- For example: -- --
--   $$(refineTH 23) :: Refined Positive Int
--   Refined 23
--   
-- -- Here's an example of an invalid value: -- --
--   $$(refineTH 0) :: Refined Positive Int
--   <interactive>:6:4:
--       Value is not greater than 0
--       In the Template Haskell splice $$(refineTH 0)
--       In the expression: $$(refineTH 0) :: Refined Positive Int
--       In an equation for ‘it’:
--           it = $$(refineTH 0) :: Refined Positive Int
--   
-- -- The example above indicates a compile-time failure, which means that -- the checking was done at compile-time, thus introducing a zero-runtime -- overhead compared to a plain value construction. -- -- Note: It may be useful to use this function with the -- th-lift-instances package. refineTH :: forall p x m. (Predicate p x, Lift x, Quote m, MonadFail m) => x -> Code m (Refined p x) -- | Like refineTH, but immediately unrefines the value. This is -- useful when some value need only be refined at compile-time. refineTH_ :: forall p x m. (Predicate p x, Lift x, Quote m, MonadFail m) => x -> Code m x -- | Extracts the refined value. unrefine :: Refined p x -> x -- | A typeclass which defines a runtime interpretation of a type-level -- predicate p for type x. class (Typeable p) => Predicate p x -- | Check the value x according to the predicate p, -- producing an error RefineException if the value does not -- satisfy. -- -- Note: validate is not intended to be used directly; -- instead, it is intended to provide the minimal means necessary for -- other utilities to be derived. As such, the Maybe here should -- be interpreted to mean the presence or absence of a -- RefineException, and nothing else. validate :: Predicate p x => Proxy p -> x -> Maybe RefineException -- | Reify a Predicate by turning it into a value-level predicate. reifyPredicate :: forall p a. Predicate p a => a -> Bool -- | The negation of a predicate. -- --
--   >>> isRight (refine @(Not NonEmpty) @[Int] [])
--   True
--   
-- --
--   >>> isLeft (refine @(Not NonEmpty) @[Int] [1,2])
--   True
--   
data Not p Not :: Not p -- | The conjunction of two predicates. -- --
--   >>> isLeft (refine @(And Positive Negative) @Int 3)
--   True
--   
-- --
--   >>> isRight (refine @(And Positive Odd) @Int 203)
--   True
--   
data And l r And :: And l r -- | The conjunction of two predicates. type (&&) = And infixr 3 && -- | The disjunction of two predicates. -- --
--   >>> isRight (refine @(Or Even Odd) @Int 3)
--   True
--   
-- --
--   >>> isRight (refine @(Or (LessThan 3) (GreaterThan 3)) @Int 2)
--   True
--   
-- --
--   >>> isRight (refine @(Or Even Even) @Int 4)
--   True
--   
data Or l r Or :: Or l r -- | The disjunction of two predicates. type (||) = Or infixr 2 || -- | The exclusive disjunction of two predicates. -- --
--   >>> isRight (refine @(Xor Even Odd) @Int 3)
--   True
--   
-- --
--   >>> isLeft (refine @(Xor (LessThan 3) (EqualTo 2)) @Int 2)
--   True
--   
-- --
--   >>> isLeft (refine @(Xor Even Even) @Int 2)
--   True
--   
data Xor l r Xor :: Xor l r -- | A predicate which is satisfied for all types. Arguments passed to -- validate in validate IdPred x -- are not evaluated. -- --
--   >>> isRight (refine @IdPred @Int undefined)
--   True
--   
-- --
--   >>> isLeft (refine @IdPred @Int undefined)
--   False
--   
data IdPred IdPred :: IdPred -- | A Predicate ensuring that the value is less than the specified -- type-level number. -- --
--   >>> isRight (refine @(LessThan 12) @Int 11)
--   True
--   
-- --
--   >>> isLeft (refine @(LessThan 12) @Int 12)
--   True
--   
data LessThan (n :: Nat) LessThan :: LessThan (n :: Nat) -- | A Predicate ensuring that the value is greater than the -- specified type-level number. -- --
--   >>> isRight (refine @(GreaterThan 65) @Int 67)
--   True
--   
-- --
--   >>> isLeft (refine @(GreaterThan 65) @Int 65)
--   True
--   
data GreaterThan (n :: Nat) GreaterThan :: GreaterThan (n :: Nat) -- | A Predicate ensuring that the value is greater than or equal to -- the specified type-level number. -- --
--   >>> isRight (refine @(From 9) @Int 10)
--   True
--   
-- --
--   >>> isRight (refine @(From 10) @Int 10)
--   True
--   
-- --
--   >>> isLeft (refine @(From 11) @Int 10)
--   True
--   
data From (n :: Nat) From :: From (n :: Nat) -- | A Predicate ensuring that the value is less than or equal to -- the specified type-level number. -- --
--   >>> isRight (refine @(To 23) @Int 17)
--   True
--   
-- --
--   >>> isLeft (refine @(To 17) @Int 23)
--   True
--   
data To (n :: Nat) To :: To (n :: Nat) -- | A Predicate ensuring that the value is within an inclusive -- range. -- --
--   >>> isRight (refine @(FromTo 0 16) @Int 13)
--   True
--   
-- --
--   >>> isRight (refine @(FromTo 13 15) @Int 13)
--   True
--   
-- --
--   >>> isRight (refine @(FromTo 13 15) @Int 15)
--   True
--   
-- --
--   >>> isLeft (refine @(FromTo 13 15) @Int 12)
--   True
--   
data FromTo (mn :: Nat) (mx :: Nat) FromTo :: FromTo (mn :: Nat) (mx :: Nat) -- | A Predicate ensuring that the value is greater or equal than a -- negative number specified as a type-level (positive) number n -- and less than a type-level (positive) number m. -- --
--   >>> isRight (refine @(NegativeFromTo 5 12) @Int (-3))
--   True
--   
-- --
--   >>> isLeft (refine @(NegativeFromTo 4 3) @Int (-5))
--   True
--   
data NegativeFromTo (n :: Nat) (m :: Nat) NegativeFromTo :: NegativeFromTo (n :: Nat) (m :: Nat) -- | A Predicate ensuring that the value is equal to the specified -- type-level number n. -- --
--   >>> isRight (refine @(EqualTo 5) @Int 5)
--   True
--   
-- --
--   >>> isLeft (refine @(EqualTo 6) @Int 5)
--   True
--   
data EqualTo (n :: Nat) EqualTo :: EqualTo (n :: Nat) -- | A Predicate ensuring that the value is not equal to the -- specified type-level number n. -- --
--   >>> isRight (refine @(NotEqualTo 6) @Int 5)
--   True
--   
-- --
--   >>> isLeft (refine @(NotEqualTo 5) @Int 5)
--   True
--   
data NotEqualTo (n :: Nat) NotEqualTo :: NotEqualTo (n :: Nat) -- | A Predicate ensuring that the value is odd. -- --
--   >>> isRight (refine @Odd @Int 33)
--   True
--   
-- --
--   >>> isLeft (refine @Odd @Int 32)
--   True
--   
data Odd Odd :: Odd -- | A Predicate ensuring that the value is even. -- --
--   >>> isRight (refine @Even @Int 32)
--   True
--   
-- --
--   >>> isLeft (refine @Even @Int 33)
--   True
--   
data Even Even :: Even -- | A Predicate ensuring that the value is divisible by n. -- --
--   >>> isRight (refine @(DivisibleBy 3) @Int 12)
--   True
--   
-- --
--   >>> isLeft (refine @(DivisibleBy 2) @Int 37)
--   True
--   
data DivisibleBy (n :: Nat) DivisibleBy :: DivisibleBy (n :: Nat) -- | A Predicate ensuring that the value is IEEE "not-a-number" -- (NaN). -- --
--   >>> isRight (refine @NaN @Double (0/0))
--   True
--   
-- --
--   >>> isLeft (refine @NaN @Double 13.9)
--   True
--   
data NaN NaN :: NaN -- | A Predicate ensuring that the value is IEEE infinity or -- negative infinity. -- --
--   >>> isRight (refine @Infinite @Double (1/0))
--   True
--   
-- --
--   >>> isRight (refine @Infinite @Double (-1/0))
--   True
--   
-- --
--   >>> isLeft (refine @Infinite @Double 13.20)
--   True
--   
data Infinite Infinite :: Infinite -- | A Predicate ensuring that the value is greater than zero. type Positive = GreaterThan 0 -- | A Predicate ensuring that the value is less than or equal to -- zero. type NonPositive = To 0 -- | A Predicate ensuring that the value is less than zero. type Negative = LessThan 0 -- | A Predicate ensuring that the value is greater than or equal to -- zero. type NonNegative = From 0 -- | An inclusive range of values from zero to one. type ZeroToOne = FromTo 0 1 -- | A Predicate ensuring that the value is not equal to zero. type NonZero = NotEqualTo 0 -- | A Predicate ensuring that the value has a length which is less -- than the specified type-level number. -- --
--   >>> isRight (refine @(SizeLessThan 4) @[Int] [1,2,3])
--   True
--   
-- --
--   >>> isLeft (refine @(SizeLessThan 5) @[Int] [1,2,3,4,5])
--   True
--   
-- --
--   >>> isRight (refine @(SizeLessThan 4) @Text "Hi")
--   True
--   
-- --
--   >>> isLeft (refine @(SizeLessThan 4) @Text "Hello")
--   True
--   
data SizeLessThan (n :: Nat) SizeLessThan :: SizeLessThan (n :: Nat) -- | A Predicate ensuring that the value has a length which is -- greater than the specified type-level number. -- --
--   >>> isLeft (refine  @(SizeGreaterThan 3) @[Int] [1,2,3])
--   True
--   
-- --
--   >>> isRight (refine @(SizeGreaterThan 3) @[Int] [1,2,3,4,5])
--   True
--   
-- --
--   >>> isLeft (refine @(SizeGreaterThan 4) @Text "Hi")
--   True
--   
-- --
--   >>> isRight (refine @(SizeGreaterThan 4) @Text "Hello")
--   True
--   
data SizeGreaterThan (n :: Nat) SizeGreaterThan :: SizeGreaterThan (n :: Nat) -- | A Predicate ensuring that the value has a length which is equal -- to the specified type-level number. -- --
--   >>> isRight (refine @(SizeEqualTo 4) @[Int] [1,2,3,4])
--   True
--   
-- --
--   >>> isLeft (refine @(SizeEqualTo 35) @[Int] [1,2,3,4])
--   True
--   
-- --
--   >>> isRight (refine @(SizeEqualTo 4) @Text "four")
--   True
--   
-- --
--   >>> isLeft (refine @(SizeEqualTo 35) @Text "four")
--   True
--   
data SizeEqualTo (n :: Nat) SizeEqualTo :: SizeEqualTo (n :: Nat) -- | A Predicate ensuring that the type is empty. type Empty = SizeEqualTo 0 -- | A Predicate ensuring that the type is non-empty. type NonEmpty = SizeGreaterThan 0 -- | A Predicate ensuring that the Foldable contains elements -- in a strictly ascending order. -- --
--   >>> isRight (refine @Ascending @[Int] [5, 8, 13, 21, 34])
--   True
--   
-- --
--   >>> isLeft (refine @Ascending @[Int] [34, 21, 13, 8, 5])
--   True
--   
data Ascending Ascending :: Ascending -- | A Predicate ensuring that the Foldable contains elements -- in a strictly descending order. -- --
--   >>> isRight (refine @Descending @[Int] [34, 21, 13, 8, 5])
--   True
--   
-- --
--   >>> isLeft (refine @Descending @[Int] [5, 8, 13, 21, 34])
--   True
--   
data Descending Descending :: Descending -- | A typeclass containing "safe" conversions between refined predicates -- where the target is weaker than the source: that is, all values -- that satisfy the first predicate will be guaranteed to satisfy the -- second. -- -- Take care: writing an instance declaration for your custom predicates -- is the same as an assertion that weaken is safe to use: -- --
--   instance Weaken Pred1 Pred2
--   
--   
-- -- For most of the instances, explicit type annotations for the result -- value's type might be required. class Weaken from to weaken :: Weaken from to => Refined from x -> Refined to x -- | This function helps type inference. It is equivalent to the following: -- --
--   instance Weaken (And l r) l
--   
andLeft :: Refined (And l r) x -> Refined l x -- | This function helps type inference. It is equivalent to the following: -- --
--   instance Weaken (And l r) r
--   
andRight :: Refined (And l r) x -> Refined r x -- | This function helps type inference. It is equivalent to the following: -- --
--   instance Weaken l (Or l r)
--   
leftOr :: Refined l x -> Refined (Or l r) x -- | This function helps type inference. It is equivalent to the following: -- --
--   instance Weaken r (Or l r)
--   
rightOr :: Refined r x -> Refined (Or l r) x -- | Strengthen a refinement by composing it with another. strengthen :: forall p p' x. (Predicate p x, Predicate p' x) => Refined p x -> Either RefineException (Refined (p && p') x) -- | An exception encoding the way in which a Predicate failed. data RefineException -- | A RefineException for failures involving the Not -- predicate. RefineNotException :: !TypeRep -> RefineException -- | A RefineException for failures involving the And -- predicate. RefineAndException :: !TypeRep -> !These RefineException RefineException -> RefineException -- | A RefineException for failures involving the Or -- predicate. RefineOrException :: !TypeRep -> !RefineException -> !RefineException -> RefineException -- | A RefineException for failures involving the Xor -- predicate. RefineXorException :: !TypeRep -> !Maybe (RefineException, RefineException) -> RefineException -- | A RefineException for failures involving all other predicates -- with custom exception. RefineSomeException :: !TypeRep -> !SomeException -> RefineException -- | A RefineException for failures involving all other predicates. RefineOtherException :: !TypeRep -> !Text -> RefineException -- | Display a RefineException as String -- -- This function can be extremely useful for debugging -- RefineExceptions, especially deeply nested ones. -- -- Consider: -- --
--   myRefinement = refine
--     @(And
--         (Not (LessThan 5))
--         (Xor
--           (DivisibleBy 10)
--           (And
--             (EqualTo 4)
--             (EqualTo 3)
--           )
--         )
--      )
--     @Int
--     3
--   
--   
-- -- This function will show the following tree structure, recursively -- breaking down every issue: -- --
--   And (Not (LessThan 5)) (Xor (EqualTo 4) (And (EqualTo 4) (EqualTo 3)))
--   ├── The predicate (Not (LessThan 5)) does not hold.
--   └── Xor (DivisibleBy 10) (And (EqualTo 4) (EqualTo 3))
--       ├── The predicate (DivisibleBy 10) failed with the message: Value is not divisible by 10
--       └── And (EqualTo 4) (EqualTo 3)
--           └── The predicate (EqualTo 4) failed with the message: Value does not equal 4
--   
--   
-- -- Note: Equivalent to show -- @RefineException displayRefineException :: RefineException -> String -- | A handler for a RefineException. -- -- throwRefineOtherException is useful for defining what behaviour -- validate should have in the event of a predicate failure. -- -- Typically the first argument passed to this function will be the -- result of applying typeRep to the first argument of -- validate. throwRefineOtherException :: TypeRep -> Text -> Maybe RefineException -- | A handler for a RefineException. -- -- throwRefineSomeException is useful for defining what behaviour -- validate should have in the event of a predicate failure with a -- specific exception. throwRefineSomeException :: TypeRep -> SomeException -> Maybe RefineException -- | An implementation of validate that always succeeds. -- --

Examples

-- --
--   data ContainsLetterE = ContainsLetterE
--   
--   instance Predicate ContainsLetterE Text where
--     validate p t
--       | any (== 'e') t = success
--       | otherwise = Just $ throwRefineException (typeRep p) "Text doesn't contain letter 'e'".
--   
--   
success :: Maybe RefineException instance GHC.Generics.Generic Refined.IdPred instance GHC.Generics.Generic1 Refined.Not instance forall k (p :: k). GHC.Generics.Generic (Refined.Not p) instance forall k1 k2 (l :: k2). GHC.Generics.Generic1 (Refined.And l) instance forall k1 (l :: k1) k2 (r :: k2). GHC.Generics.Generic (Refined.And l r) instance forall k1 k2 (l :: k2). GHC.Generics.Generic1 (Refined.Or l) instance forall k1 (l :: k1) k2 (r :: k2). GHC.Generics.Generic (Refined.Or l r) instance forall k1 k2 (l :: k2). GHC.Generics.Generic1 (Refined.Xor l) instance forall k1 (l :: k1) k2 (r :: k2). GHC.Generics.Generic (Refined.Xor l r) instance GHC.Generics.Generic (Refined.SizeLessThan n) instance GHC.Generics.Generic (Refined.SizeGreaterThan n) instance GHC.Generics.Generic (Refined.SizeEqualTo n) instance GHC.Generics.Generic Refined.Ascending instance GHC.Generics.Generic Refined.Descending instance GHC.Generics.Generic (Refined.LessThan n) instance GHC.Generics.Generic (Refined.GreaterThan n) instance GHC.Generics.Generic (Refined.From n) instance GHC.Generics.Generic (Refined.To n) instance GHC.Generics.Generic (Refined.FromTo mn mx) instance GHC.Generics.Generic (Refined.EqualTo n) instance GHC.Generics.Generic (Refined.NotEqualTo n) instance GHC.Generics.Generic (Refined.NegativeFromTo n m) instance GHC.Generics.Generic (Refined.DivisibleBy n) instance GHC.Generics.Generic Refined.Odd instance GHC.Generics.Generic Refined.NaN instance GHC.Generics.Generic Refined.Infinite instance GHC.Generics.Generic Refined.Even instance GHC.Generics.Generic Refined.RefineException instance forall k x (p :: k). (GHC.Read.Read x, Refined.Predicate p x) => GHC.Read.Read (Refined.Unsafe.Type.Refined p x) instance forall k a (p :: k). (Data.Aeson.Types.FromJSON.FromJSON a, Refined.Predicate p a) => Data.Aeson.Types.FromJSON.FromJSON (Refined.Unsafe.Type.Refined p a) instance forall k a (p :: k). (Data.Aeson.Types.FromJSON.FromJSONKey a, Refined.Predicate p a) => Data.Aeson.Types.FromJSON.FromJSONKey (Refined.Unsafe.Type.Refined p a) instance forall k a (p :: k). (Data.Aeson.Types.ToJSON.ToJSON a, Refined.Predicate p a) => Data.Aeson.Types.ToJSON.ToJSON (Refined.Unsafe.Type.Refined p a) instance forall k a (p :: k). (Data.Aeson.Types.ToJSON.ToJSONKey a, Refined.Predicate p a) => Data.Aeson.Types.ToJSON.ToJSONKey (Refined.Unsafe.Type.Refined p a) instance forall k (p :: k) a. (Test.QuickCheck.Arbitrary.Arbitrary a, Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable p, Refined.Predicate p a) => Test.QuickCheck.Arbitrary.Arbitrary (Refined.Unsafe.Type.Refined p a) instance Refined.Predicate Refined.IdPred x instance forall k (p :: k) x. (Refined.Predicate p x, Data.Typeable.Internal.Typeable p, Data.Typeable.Internal.Typeable k) => Refined.Predicate (Refined.Not p) x instance forall k (l :: k) x (r :: k). (Refined.Predicate l x, Refined.Predicate r x, Data.Typeable.Internal.Typeable l, Data.Typeable.Internal.Typeable r, Data.Typeable.Internal.Typeable k) => Refined.Predicate (Refined.And l r) x instance forall k (l :: k) x (r :: k). (Refined.Predicate l x, Refined.Predicate r x, Data.Typeable.Internal.Typeable l, Data.Typeable.Internal.Typeable r, Data.Typeable.Internal.Typeable k) => Refined.Predicate (Refined.Or l r) x instance forall k (l :: k) x (r :: k). (Refined.Predicate l x, Refined.Predicate r x, Data.Typeable.Internal.Typeable l, Data.Typeable.Internal.Typeable r, Data.Typeable.Internal.Typeable k) => Refined.Predicate (Refined.Xor l r) x instance (Data.Foldable.Foldable t, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.SizeLessThan n) (t a) instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeLessThan n) Data.Text.Internal.Text instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeLessThan n) Data.ByteString.Internal.ByteString instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeLessThan n) Data.ByteString.Lazy.Internal.ByteString instance (Data.Foldable.Foldable t, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.SizeGreaterThan n) (t a) instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeGreaterThan n) Data.Text.Internal.Text instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeGreaterThan n) Data.ByteString.Internal.ByteString instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeGreaterThan n) Data.ByteString.Lazy.Internal.ByteString instance (Data.Foldable.Foldable t, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.SizeEqualTo n) (t a) instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeEqualTo n) Data.Text.Internal.Text instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeEqualTo n) Data.ByteString.Internal.ByteString instance GHC.TypeNats.KnownNat n => Refined.Predicate (Refined.SizeEqualTo n) Data.ByteString.Lazy.Internal.ByteString instance (Data.Foldable.Foldable t, GHC.Classes.Ord a) => Refined.Predicate Refined.Ascending (t a) instance (Data.Foldable.Foldable t, GHC.Classes.Ord a) => Refined.Predicate Refined.Descending (t a) instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.LessThan n) x instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.GreaterThan n) x instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.From n) x instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.To n) x instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat mn, GHC.TypeNats.KnownNat mx, mn Data.Type.Ord.<= mx) => Refined.Predicate (Refined.FromTo mn mx) x instance (GHC.Classes.Eq x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.EqualTo n) x instance (GHC.Classes.Eq x, GHC.Num.Num x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.NotEqualTo n) x instance (GHC.Classes.Ord x, GHC.Num.Num x, GHC.TypeNats.KnownNat n, GHC.TypeNats.KnownNat m) => Refined.Predicate (Refined.NegativeFromTo n m) x instance (GHC.Real.Integral x, GHC.TypeNats.KnownNat n) => Refined.Predicate (Refined.DivisibleBy n) x instance GHC.Real.Integral x => Refined.Predicate Refined.Odd x instance GHC.Float.RealFloat x => Refined.Predicate Refined.NaN x instance GHC.Float.RealFloat x => Refined.Predicate Refined.Infinite x instance GHC.Real.Integral x => Refined.Predicate Refined.Even x instance GHC.Show.Show Refined.RefineException instance GHC.Exception.Type.Exception Refined.RefineException instance (n Data.Type.Ord.<= m) => Refined.Weaken (Refined.LessThan n) (Refined.LessThan m) instance (n Data.Type.Ord.<= m) => Refined.Weaken (Refined.LessThan n) (Refined.To m) instance (n Data.Type.Ord.<= m) => Refined.Weaken (Refined.To n) (Refined.To m) instance (m Data.Type.Ord.<= n) => Refined.Weaken (Refined.GreaterThan n) (Refined.GreaterThan m) instance (m Data.Type.Ord.<= n) => Refined.Weaken (Refined.GreaterThan n) (Refined.From m) instance (m Data.Type.Ord.<= n) => Refined.Weaken (Refined.From n) (Refined.From m) instance (p Data.Type.Ord.<= n, m Data.Type.Ord.<= q) => Refined.Weaken (Refined.FromTo n m) (Refined.FromTo p q) instance (p Data.Type.Ord.<= n) => Refined.Weaken (Refined.FromTo n m) (Refined.From p) instance (m Data.Type.Ord.<= q) => Refined.Weaken (Refined.FromTo n m) (Refined.To q) -- | This module exposes unsafe refinements. An unsafe -- refinement is one which either does not make the guarantee of totality -- in construction of the Refined value or does not perform a -- check of the refinement predicate. It is recommended only to use this -- when you can manually prove that the refinement predicate holds. module Refined.Unsafe -- | A refinement type, which wraps a value of type x. data Refined (p :: k) x -- | Constructs a Refined value, completely ignoring any -- refinements! Use this only when you can manually prove that the -- refinement holds. reallyUnsafeRefine :: x -> Refined p x -- | Constructs a Refined value at run-time, calling error if -- the value does not satisfy the predicate. -- -- WARNING: this function is not total! unsafeRefine :: Predicate p x => x -> Refined p x -- | A coercion between a type and any refinement of that type. See -- Data.Type.Coercion for functions manipulating coercions. reallyUnsafeUnderlyingRefined :: Coercion x (Refined p x) -- | Reveal that x and Refined p x are -- Coercible for all x and p -- simultaneously. -- --

Example

-- --
--   reallyUnsafePredEquiv :: Coercion (Refined p x) (Refined q x)
--   reallyUnsafePredEquiv = reallyUnsafeAllUnderlyingRefined Coercion
--   
reallyUnsafeAllUnderlyingRefined :: ((forall x y p. Coercible x y => Coercible y (Refined p x)) => r) -> r -- | A coercion between two Refined types, magicking up the claim -- that one predicate is entirely equivalent to another. reallyUnsafePredEquiv :: Coercion (Refined p x) (Refined q x)