refined 0.4.3 → 0.4.4
raw patch · 4 files changed
+75/−3 lines, 4 filesdep ~QuickCheckdep ~basedep ~prettyprinter
Dependency ranges changed: QuickCheck, base, prettyprinter, template-haskell
Files
- refined.cabal +21/−3
- src/Refined.hs +2/−0
- src/Refined/Internal.hs +26/−0
- test/Compiles.hs +26/−0
refined.cabal view
@@ -3,7 +3,7 @@ name: refined version:- 0.4.3+ 0.4.4 synopsis: Refinement types with static and runtime checking description:@@ -77,13 +77,13 @@ , exceptions >= 0.8 && < 0.11 , mtl >= 2.2.1 && < 2.3 , prettyprinter >= 1.1.0.1 && < 1.4- , template-haskell >= 2.9 && < 2.15+ , template-haskell >= 2.9 && < 2.16 , transformers >= 0.5 && < 0.6 if flag(aeson) build-depends: aeson >= 0.9 && < 1.5 cpp-options: -DHAVE_AESON if flag(QuickCheck)- build-depends: QuickCheck >= 2.1 && < 2.13+ build-depends: QuickCheck >= 2.1 && < 2.14 cpp-options: -DHAVE_QUICKCHECK test-suite doctest@@ -105,3 +105,21 @@ , refined , QuickCheck default-language: Haskell2010++test-suite compiles+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Compiles.hs+ build-depends:+ base+ , refined+ default-language: Haskell2010++-- test-suite doesnt-compile+-- type: exitcode-stdio-1.0+-- hs-source-dirs: test+-- main-is: DoesntCompile.hs+-- build-depends:+-- base+-- , refined+-- default-language: Haskell2010
src/Refined.hs view
@@ -58,10 +58,12 @@ -- ** Creation , refine+ , refine_ , refineThrow , refineFail , refineError , refineTH+ , refineTH_ -- ** Consumption , unrefine
src/Refined/Internal.hs view
@@ -46,6 +46,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RoleAnnotations #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-}@@ -72,10 +73,12 @@ -- ** Creation , refine+ , refine_ , refineThrow , refineFail , refineError , refineTH+ , refineTH_ -- ** Consumption , unrefine@@ -299,6 +302,13 @@ pure (Refined x) {-# INLINABLE refine #-} +-- | 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+refine_ = refine @p @x .> coerce+ -- | Constructs a 'Refined' value at run-time, -- calling 'Control.Monad.Catch.throwM' if the value -- does not satisfy the predicate.@@ -352,6 +362,22 @@ -> x -> Either RefineException (Refined p x) refineByResult = const refine+ in fix $ \loop -> refineByResult (loop undefined)+ .> either (show .> fail) TH.lift+ .> fmap TH.TExp++-- | Like 'refineTH', but immediately unrefines the value.+-- This is useful when some value need only be refined+-- at compile-time.+refineTH_ :: forall p x. (Predicate p x, TH.Lift x)+ => x+ -> TH.Q (TH.TExp x)+refineTH_ =+ let refineByResult :: (Predicate p x)+ => TH.Q (TH.TExp x)+ -> x+ -> Either RefineException x+ refineByResult = const (refine_ @p @x) in fix $ \loop -> refineByResult (loop undefined) .> either (show .> fail) TH.lift .> fmap TH.TExp
+ test/Compiles.hs view
@@ -0,0 +1,26 @@+{-# language+ AllowAmbiguousTypes+ , FlexibleInstances+ , MultiParamTypeClasses+ , OverloadedStrings+ , TemplateHaskell+ , TypeApplications+ #-}++module Main (main) where++import Refined+import Prelude (IO,putStrLn,Int)+import Data.Void (Void)++main :: IO ()+main = do+ putStrLn "refined/test/Compiles.hs: it compiles!"++id = $$(refineTH @IdPred @Int 3)+even = $$(refineTH @(Not Even) @Int 3)+odd = $$(refineTH @Odd @Int 3)++id_ = $$(refineTH_ @IdPred @Int 3)+even_ = $$(refineTH_ @(Not Even) @Int 3)+odd_ = $$(refineTH_ @Odd @Int 3)