From 12487340c1a37fb90003f54fd910ef762fa4b17d Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 2 Mar 2022 17:28:08 +0000 Subject: docs: Add note to unsafeCoerce function that you might want to use coerce [skip ci] Fixes #15429 --- libraries/base/Unsafe/Coerce.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/base/Unsafe/Coerce.hs b/libraries/base/Unsafe/Coerce.hs index 930514ce81..ec5b793f87 100644 --- a/libraries/base/Unsafe/Coerce.hs +++ b/libraries/base/Unsafe/Coerce.hs @@ -267,6 +267,10 @@ unsafeEqualityProof = case unsafeEqualityProof @a @b of UnsafeRefl -> UnsafeRefl -- (which have different kinds!) because it's really just a newtype. -- Note: there is /no guarantee, at all/ that this behavior will be supported -- into perpetuity. +-- +-- +-- For safe zero-cost coercions you can instead use the 'Data.Coerce.coerce' function from +-- "Data.Coerce". unsafeCoerce :: forall (a :: Type) (b :: Type) . a -> b unsafeCoerce x = case unsafeEqualityProof @a @b of UnsafeRefl -> x -- cgit v1.2.1