Can I coerce type constructors to Any?
Tom Ellis <[email protected]> Wed, 21 Jan 2026 23:14:49 +0000
| Newsgroups | gmane.comp.lang.haskell.cafe |
|---|---|
| Message-ID | <aXFd6Vhrw-UMkKj0@cloudinit-builder> |
The documentation for Any says: > The type constructor Any is type to which you can unsafely coerce > any lifted type, and back. More concretely, for a lifted type t and > value x :: t, unsafeCoerce (unsafeCoerce x :: Any) :: t is > equivalent to x. https://www.stackage.org/haddock/lts-24.28/base-4.20.2.0/GHC-Base.html#t:Any Is this also true of type constructors? For example, could I coerce `f x` to `Any x`? (assuming f maps lifted types to lifted types) In particular I'm interested in things like data C f where MkC :: (forall a. Monad (f a)) => C newtype CD f = MkCD (C Any) putCD :: C f -> CD f putCD c = MkCD (unsafeCoerce c) getCD :: CD f -> C f getCD (MkCD cd) = unsafeCoerce cd Is that sound? Thanks, Tom _______________________________________________ Haskell-Cafe mailing list -- [email protected] To (un)subscribe, modify options or view archives go to: Only members subscribed via the mailman list are allowed to post.