mirror of
https://github.com/github/semantic.git
synced 2024-12-21 05:41:54 +03:00
Rename inj'/prj' to unsafeInject/unsafeProject.
This commit is contained in:
parent
1a562e6e07
commit
ea8c694b3f
@ -72,14 +72,14 @@ infixr 5 :<
|
|||||||
data Sum (r :: [ * -> * ]) (v :: *) where
|
data Sum (r :: [ * -> * ]) (v :: *) where
|
||||||
Sum :: {-# UNPACK #-} !Int -> t v -> Sum r v
|
Sum :: {-# UNPACK #-} !Int -> t v -> Sum r v
|
||||||
|
|
||||||
inj' :: Int -> t v -> Sum r v
|
unsafeInject :: Int -> t v -> Sum r v
|
||||||
inj' = Sum
|
unsafeInject = Sum
|
||||||
{-# INLINE inj' #-}
|
{-# INLINE unsafeInject #-}
|
||||||
|
|
||||||
prj' :: Int -> Sum r v -> Maybe (t v)
|
unsafeProject :: Int -> Sum r v -> Maybe (t v)
|
||||||
prj' n (Sum n' x) | n == n' = Just (unsafeCoerce x)
|
unsafeProject n (Sum n' x) | n == n' = Just (unsafeCoerce x)
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
{-# INLINE prj' #-}
|
{-# INLINE unsafeProject #-}
|
||||||
|
|
||||||
newtype P (t :: * -> *) (r :: [* -> *]) = P { unP :: Int }
|
newtype P (t :: * -> *) (r :: [* -> *]) = P { unP :: Int }
|
||||||
|
|
||||||
@ -93,12 +93,12 @@ type (ts :<: r) = Elements ts r
|
|||||||
|
|
||||||
-- | Inject a functor into a type-aligned sum.
|
-- | Inject a functor into a type-aligned sum.
|
||||||
inject :: forall e r v. (e :< r) => e v -> Sum r v
|
inject :: forall e r v. (e :< r) => e v -> Sum r v
|
||||||
inject = inj' (unP (elemNo :: P e r))
|
inject = unsafeInject (unP (elemNo :: P e r))
|
||||||
{-# INLINE inject #-}
|
{-# INLINE inject #-}
|
||||||
|
|
||||||
-- | Maybe project a functor out of a type-aligned sum.
|
-- | Maybe project a functor out of a type-aligned sum.
|
||||||
project :: forall e r v. (e :< r) => Sum r v -> Maybe (e v)
|
project :: forall e r v. (e :< r) => Sum r v -> Maybe (e v)
|
||||||
project = prj' (unP (elemNo :: P e r))
|
project = unsafeProject (unP (elemNo :: P e r))
|
||||||
{-# INLINE project #-}
|
{-# INLINE project #-}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user