mirror of
https://github.com/tfausak/witch.git
synced 2024-11-23 00:06:27 +03:00
Fix formatting
This commit is contained in:
parent
4fc8211592
commit
634c06ca7d
@ -17,7 +17,8 @@ liftedCast
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedCast = TH.liftTyped . Utility.unsafeCast
|
||||
|
||||
@ -29,7 +30,8 @@ liftedFrom
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedFrom = liftedCast
|
||||
|
||||
@ -41,6 +43,7 @@ liftedInto
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedInto = liftedCast
|
||||
|
@ -17,7 +17,8 @@ liftedCast
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedCast s = TH.unsafeTExpCoerce $ TH.lift (Utility.unsafeCast s :: target)
|
||||
|
||||
@ -29,7 +30,8 @@ liftedFrom
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedFrom = liftedCast
|
||||
|
||||
@ -41,6 +43,7 @@ liftedInto
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Q (TH.TExp target)
|
||||
liftedInto = liftedCast
|
||||
|
@ -18,7 +18,8 @@ liftedCast
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
, TH.Quote m
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Code m target
|
||||
liftedCast = TH.liftTyped . Utility.unsafeCast
|
||||
|
||||
@ -31,7 +32,8 @@ liftedFrom
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
, TH.Quote m
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Code m target
|
||||
liftedFrom = liftedCast
|
||||
|
||||
@ -44,6 +46,7 @@ liftedInto
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
, TH.Quote m
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> TH.Code m target
|
||||
liftedInto = liftedCast
|
||||
|
@ -20,6 +20,6 @@ module Witch
|
||||
import qualified Witch.Cast
|
||||
import Witch.Instances ()
|
||||
import qualified Witch.Lift
|
||||
import qualified Witch.Utility
|
||||
import qualified Witch.TryCast
|
||||
import qualified Witch.TryCastException
|
||||
import qualified Witch.Utility
|
||||
|
@ -20,6 +20,7 @@ import qualified Witch.TryCastException as TryCastException
|
||||
|
||||
instance TryCast.TryCast [a] (NonEmpty.NonEmpty a) where
|
||||
tryCast = maybeTryCast NonEmpty.nonEmpty
|
||||
|
||||
instance Cast.Cast (NonEmpty.NonEmpty a) [a] where
|
||||
cast = NonEmpty.toList
|
||||
|
||||
@ -235,7 +236,8 @@ instance TryCast.TryCast Integer Natural.Natural where
|
||||
-- bug in GHC 9.0.1. By inlining @fromNonNegativeIntegral@ and replacing
|
||||
-- @fromIntegral@ with @fromInteger@, we can work around the bug.
|
||||
-- https://mail.haskell.org/pipermail/haskell-cafe/2021-March/133540.html
|
||||
tryCast = maybeTryCast $ \ s -> if s < 0 then Nothing else Just $ fromInteger s
|
||||
tryCast =
|
||||
maybeTryCast $ \s -> if s < 0 then Nothing else Just $ fromInteger s
|
||||
|
||||
-- Word8
|
||||
|
||||
@ -453,9 +455,8 @@ instance Integral a => Cast.Cast a (Ratio.Ratio a) where
|
||||
cast = (Ratio.% 1)
|
||||
|
||||
instance (Eq a, Num a) => TryCast.TryCast (Ratio.Ratio a) a where
|
||||
tryCast = maybeTryCast $ \ s -> if Ratio.denominator s == 1
|
||||
then Just $ Ratio.numerator s
|
||||
else Nothing
|
||||
tryCast = maybeTryCast $ \s ->
|
||||
if Ratio.denominator s == 1 then Just $ Ratio.numerator s else Nothing
|
||||
|
||||
-- Fixed
|
||||
|
||||
@ -471,14 +472,14 @@ instance Num a => Cast.Cast a (Complex.Complex a) where
|
||||
cast = (Complex.:+ 0)
|
||||
|
||||
instance (Eq a, Num a) => TryCast.TryCast (Complex.Complex a) a where
|
||||
tryCast = maybeTryCast $ \ s -> if Complex.imagPart s == 0
|
||||
then Just $ Complex.realPart s
|
||||
else Nothing
|
||||
tryCast = maybeTryCast $ \s ->
|
||||
if Complex.imagPart s == 0 then Just $ Complex.realPart s else Nothing
|
||||
|
||||
fromNonNegativeIntegral :: (Integral s, Num t) => s -> Maybe t
|
||||
fromNonNegativeIntegral x = if x < 0 then Nothing else Just $ fromIntegral x
|
||||
|
||||
maybeTryCast :: (s -> Maybe t) -> s -> Either (TryCastException.TryCastException s t) t
|
||||
maybeTryCast
|
||||
:: (s -> Maybe t) -> s -> Either (TryCastException.TryCastException s t) t
|
||||
maybeTryCast f s = case f s of
|
||||
Nothing -> Left $ TryCastException.TryCastException s
|
||||
Just t -> Right t
|
||||
|
@ -12,11 +12,7 @@ import qualified Witch.Identity as Identity
|
||||
import qualified Witch.TryCast as TryCast
|
||||
import qualified Witch.TryCastException as TryCastException
|
||||
|
||||
as
|
||||
:: forall s source
|
||||
. Identity.Identity s ~ source
|
||||
=> source
|
||||
-> source
|
||||
as :: forall s source . Identity.Identity s ~ source => source -> source
|
||||
as = id
|
||||
|
||||
from
|
||||
@ -35,7 +31,10 @@ into = Cast.cast
|
||||
|
||||
over
|
||||
:: forall t source target
|
||||
. (Identity.Identity t ~ target, Cast.Cast source target, Cast.Cast target source)
|
||||
. ( Identity.Identity t ~ target
|
||||
, Cast.Cast source target
|
||||
, Cast.Cast target source
|
||||
)
|
||||
=> (target -> target)
|
||||
-> source
|
||||
-> source
|
||||
@ -43,10 +42,13 @@ over f = Cast.cast . f . Cast.cast
|
||||
|
||||
via
|
||||
:: forall u source target through
|
||||
. (Identity.Identity u ~ through, Cast.Cast source through, Cast.Cast through target)
|
||||
. ( Identity.Identity u ~ through
|
||||
, Cast.Cast source through
|
||||
, Cast.Cast through target
|
||||
)
|
||||
=> source
|
||||
-> target
|
||||
via = Cast.cast . (\ x -> x :: through) . Cast.cast
|
||||
via = Cast.cast . (\x -> x :: through) . Cast.cast
|
||||
|
||||
tryFrom
|
||||
:: forall s target source
|
||||
@ -69,7 +71,8 @@ unsafeCast
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> target
|
||||
unsafeCast = either Exception.throw id . TryCast.tryCast
|
||||
|
||||
@ -81,7 +84,8 @@ unsafeFrom
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> target
|
||||
unsafeFrom = unsafeCast
|
||||
|
||||
@ -93,6 +97,7 @@ unsafeInto
|
||||
, Show source
|
||||
, Typeable.Typeable source
|
||||
, Typeable.Typeable target
|
||||
) => source
|
||||
)
|
||||
=> source
|
||||
-> target
|
||||
unsafeInto = unsafeCast
|
||||
|
@ -15,7 +15,10 @@ import Test.HUnit
|
||||
import Witch
|
||||
|
||||
main :: IO ()
|
||||
main = runTestTTAndExit $ "Witch" ~:
|
||||
main = runTestTTAndExit $ "Witch" ~: tests
|
||||
|
||||
tests :: [Test]
|
||||
tests =
|
||||
[ as @Int8 1 ~?= 1
|
||||
, cast (1 :: Int8) ~?= (1 :: Int16)
|
||||
, from @Int8 1 ~?= (1 :: Int)
|
||||
|
Loading…
Reference in New Issue
Block a user