witch 0.2.0.0 → 0.2.0.1
raw patch · 4 files changed
+25/−14 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Witch.Instances: instance Witch.Cast.Cast (Witch.TryCastException.TryCastException s t0) (Witch.TryCastException.TryCastException s t1)
+ Witch.Instances: instance Witch.Cast.Cast (Witch.TryCastException.TryCastException s u) (Witch.TryCastException.TryCastException s t)
Files
- src/lib/Witch/Instances.hs +12/−5
- src/lib/Witch/TryCastException.hs +8/−5
- src/test/Main.hs +4/−3
- witch.cabal +1/−1
src/lib/Witch/Instances.hs view
@@ -29,6 +29,7 @@ import qualified Data.Text.Lazy.Encoding as LazyText import qualified Data.Typeable as Typeable import qualified Data.Word as Word+import qualified GHC.Float as Float import qualified Numeric.Natural as Natural import qualified Witch.Cast as Cast import qualified Witch.TryCast as TryCast@@ -804,9 +805,9 @@ then if s > 0 then Left Exception.Overflow else Left Exception.Underflow else Right $ toRational s --- | Uses 'realToFrac'.+-- | Uses 'Float.double2Float'. instance Cast.Cast Float Double where- cast = realToFrac+ cast = Float.float2Double -- Double @@ -872,9 +873,9 @@ then if s > 0 then Left Exception.Overflow else Left Exception.Underflow else Right $ toRational s --- | Uses 'realToFrac'. This necessarily loses some precision.+-- | Uses 'Float.double2Float'. This necessarily loses some precision. instance Cast.Cast Double Float where- cast = realToFrac+ cast = Float.double2Float -- Ratio @@ -1076,8 +1077,12 @@ -- TryCastException -instance Cast.Cast (TryCastException.TryCastException s t0) (TryCastException.TryCastException s t1)+-- | Uses @coerce@.+instance Cast.Cast+ (TryCastException.TryCastException s u)+ (TryCastException.TryCastException s t) +-- | Uses 'show'. instance ( Show s , Typeable.Typeable s@@ -1085,6 +1090,7 @@ ) => Cast.Cast (TryCastException.TryCastException s t) String where cast = show +-- | Converts via 'String'. instance ( Show s , Typeable.Typeable s@@ -1092,6 +1098,7 @@ ) => Cast.Cast (TryCastException.TryCastException s t) Text.Text where cast = Utility.via @String +-- | Converts via 'String'. instance ( Show s , Typeable.Typeable s
src/lib/Witch/TryCastException.hs view
@@ -8,7 +8,9 @@ -- | This exception is thrown when a @TryCast@ conversion fails. It has the -- original @source@ value that caused the failure and it knows the @target@--- type it was trying to convert into.+-- type it was trying to convert into. It also has an optional+-- 'Exception.SomeException' for communicating what went wrong while+-- converting. data TryCastException source target = TryCastException source (Maybe Exception.SomeException)@@ -20,10 +22,11 @@ ) => Show (TryCastException source target) where showsPrec d (TryCastException x e) = showParen (d > 10)- $ showString "TryCastException {- "- . shows- (Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy (source -> target)))- . showString " -} "+ $ showString "TryCastException @"+ . showsPrec 11 (Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy source))+ . showString " @"+ . showsPrec 11 (Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy target))+ . showChar ' ' . showsPrec 11 x . showChar ' ' . showsPrec 11 e
src/test/Main.hs view
@@ -1643,16 +1643,17 @@ Hspec.it "needs tests" Hspec.pending Hspec.describe "Cast (TryCastException s t) String" $ do+ test $ Witch.cast (Witch.TryCastException Nothing Nothing :: Witch.TryCastException (Maybe Bool) (Maybe Int)) `Hspec.shouldBe` "TryCastException @(Maybe Bool) @(Maybe Int) Nothing Nothing" let f = Witch.cast @(Witch.TryCastException Bool Int) @String- test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` "TryCastException {- Bool -> Int -} False Nothing"+ test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` "TryCastException @Bool @Int False Nothing" Hspec.describe "Cast (TryCastException s t) Text" $ do let f = Witch.cast @(Witch.TryCastException Bool Int) @Text.Text- test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` Text.pack "TryCastException {- Bool -> Int -} False Nothing"+ test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` Text.pack "TryCastException @Bool @Int False Nothing" Hspec.describe "Cast (TryCastException s t) LazyText" $ do let f = Witch.cast @(Witch.TryCastException Bool Int) @LazyText.Text- test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` LazyText.pack "TryCastException {- Bool -> Int -} False Nothing"+ test $ f (Witch.TryCastException False Nothing) `Hspec.shouldBe` LazyText.pack "TryCastException @Bool @Int False Nothing" test :: Hspec.Example a => a -> Hspec.SpecWith (Hspec.Arg a) test = Hspec.it ""
witch.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: witch-version: 0.2.0.0+version: 0.2.0.1 synopsis: Convert values from one type into another. description: Witch converts values from one type into another.