bluefin-internal 0.8.2.0 → 0.9.0.0
raw patch · 3 files changed
+26/−10 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Bluefin.Internal.OneWayCoercible: unsafeOneWayCoerce :: OneWayCoercible a b => a -> b
- Bluefin.Internal: class Handle (h :: Effects -> Type)
+ Bluefin.Internal: class forall (e :: Effects) (es :: Effects). e <: es => OneWayCoercible h e h es => Handle (h :: Effects -> Type)
Files
- bluefin-internal.cabal +1/−1
- src/Bluefin/Internal.hs +12/−9
- src/Bluefin/Internal/OneWayCoercible.hs +13/−0
bluefin-internal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: bluefin-internal-version: 0.8.2.0+version: 0.9.0.0 license: MIT license-file: LICENSE author: Tom Ellis
src/Bluefin/Internal.hs view
@@ -18,12 +18,12 @@ OneWayCoercibleD, OneWayCoercion, gOneWayCoercible,- oneWayCoerce, oneWayCoercible, oneWayCoercion, trans3D, unsafeCoercionOfOneWayCoercion, unsafeOneWayCoercible,+ unsafeOneWayCoerce, ) import Bluefin.Internal.Vault (Vault) import Bluefin.Internal.Vault qualified as Vault@@ -412,7 +412,10 @@ -- -- Please note the "handle" nomeclature is legacy and will probably -- change to "capability" in the future. See "Bluefin.Capability".-class Handle (h :: Effects -> Type) where+class+ (forall e es. (e <: es) => OneWayCoercible (h e) (h es)) =>+ Handle (h :: Effects -> Type)+ where handleImpl :: HandleD h -- | This was previously a method of class 'Handle' using which you@@ -444,7 +447,7 @@ -- oneWayCoercibleImpl = 'oneWayCoercibleTrustMe' $ \\h -> \<mapHandle definition\> -- @ mapHandle :: forall h e es. (Handle h, e <: es) => h e -> h es-mapHandle = case handleDictImpl @h of MkHandleDict -> oneWayCoerce+mapHandle = unsafeOneWayCoerce withHandle :: forall h r.@@ -452,7 +455,7 @@ -- | ͘ ((forall e es. (e <: es) => OneWayCoercible (h e) (h es)) => r) -> r-withHandle r = case handleDictImpl @h of MkHandleDict -> r+withHandle r = r type HandleDict :: (Effects -> Type) -> Type data HandleDict h where@@ -514,13 +517,13 @@ handleOneWayCoercible = MkHandleD (unsafeCoerce (MkHandleDict @h)) instance (Handle h) => Handle (Rec1 h) where- handleImpl = withHandle @h handleOneWayCoercible+ handleImpl = handleOneWayCoercible instance (Handle h) => Handle (M1 i t h) where- handleImpl = withHandle @h handleOneWayCoercible+ handleImpl = handleOneWayCoercible instance (Handle h1, Handle h2) => Handle (h1 :*: h2) where- handleImpl = withHandle @h1 (withHandle @h2 handleOneWayCoercible)+ handleImpl = handleOneWayCoercible -- | It is not always possible to derive an instance of -- 'OneWayCoercible'. In such cases write a definition of@@ -1735,7 +1738,7 @@ mapHandleReader = case coerceH of Coercion -> coerce where oneWayCoerceH :: OneWayCoercion (h e) (h es)- oneWayCoerceH = withHandle @h oneWayCoercion+ oneWayCoerceH = oneWayCoercion coerceH :: Coercion (h e) (h es) coerceH = unsafeCoercionOfOneWayCoercion oneWayCoerceH@@ -1777,7 +1780,7 @@ runHandleReader h k = do runReader (mapHandle h) $ \(st :: Reader (h es) e) -> do let oneWayCoerceH :: OneWayCoercion (h es) (h (e :& es))- oneWayCoerceH = withHandle @h oneWayCoercion+ oneWayCoerceH = oneWayCoercion let coerceH :: Coercion (h es) (h (e :& es)) coerceH = unsafeCoercionOfOneWayCoercion oneWayCoerceH
src/Bluefin/Internal/OneWayCoercible.hs view
@@ -1,3 +1,13 @@+-- | 'OneWayCoercible' morally belongs to GHC as erased,+-- compiler-checked evidence of representational "castability"+-- (i.e. conversion in one direction only), just like 'Coercible` is+-- evidence of representational equality (i.e. "castability" in both+-- directions). But such a feature is missing in GHC and Bluefin+-- simulates it with an ordinary class. To obtain zero-cost+-- conversions it must trust the evidence without evaluating its+-- dictionary, introducing potential unsafety when 'OneWayCoercible'+-- instances are not valid.+ {-# OPTIONS_HADDOCK not-home #-} module Bluefin.Internal.OneWayCoercible@@ -45,6 +55,9 @@ oneWayCoerce :: forall a b. (OneWayCoercible a b) => a -> b oneWayCoerce = oneWayCoerceWith (oneWayCoercion @a @b)++unsafeOneWayCoerce :: forall a b. (OneWayCoercible a b) => a -> b+unsafeOneWayCoerce = unsafeCoerce oneWayCoerceWith :: OneWayCoercion a b -> a -> b oneWayCoerceWith (MkOneWayCoercion Coercion) = coerce