purescript-safe-coerce
purescript-safe-coerce copied to clipboard
Add visible type vars to `coerce`
See https://github.com/purescript/purescript/pull/4235#discussion_r829263552 once that PR gets merged.
Perhaps a few other functions should be added here. A few variants would be:
- a suffix indicating how many containers to keep the same, which indicates the number of kinds to bypass.
-
coerce @(Array a) @(Array b)becomescoerce1 @a @bsince the container type doesn't change. -
coerce @(Array (Maybe a)) @(Array (Maybe b))becomescoerce2 @a @bsince the nested container type doesn't change.
-
- a "Wrap" suffix indicating the type should be wrapped in some newtype.
coerceWrapis the same asData.Newtype.wrapbut the shared suffix means we could use the same naming convention forcoerce1/coerce2.-
coerce @a @(Disj a)becomescoerceWrap @Disj. -
coerce @(Array a) @(Array (Disj a))becomescoerce1Wrap @Disj. -
coerce @(Array (Maybe a)) @(Array (Maybe (Disj a)))becomescoerce2Wrap @Disj.
-
- a "Unwrap" suffix indicates a newtyped value should be unwrapped.
coerceUnwrapis the same asData.Newtype.unwrapbut the shared suffix means we could use the same naming convention forcoerce1/coerce2.-
coerce @(Disj a) @abecomescoerceUnwrap @Disj. -
coerce @(Array (Disj a)) @(Array a)becomescoerce1Unwrap @Disj. -
coerce @(Array (Maybe (Disj a))) @(Array (Maybe a))becomescoerce2Unwrap @Disj.
-
coerce1 :: forall f @a @b. Coercible (f a) (f b) => f a -> f b
coerce1 = coerce @(f a) @(f b)
coerce2 :: forall f g @a @b. Coercible (f (g a)) (f (g b)) => f (g a) -> f (g b)
coerce2 = coerce @(f (g a)) @(f (g b))
coerce1Wrap :: forall f @n a. Newtype n a => Coercible (f a) (f (n a)) => f a -> f (n a)
coerce1Wrap = coerce @(f a) @(f (n a))