Skip to content

Instantly share code, notes, and snippets.

Last active January 9, 2019 14:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RyanGlScott/e03734d6388bb6ffe3f29ca61ca39e1b to your computer and use it in GitHub Desktop.
Can you implement `foo` without `coerce`?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Data.Coerce
type family F a
newtype T1 = MkT1 (forall a. F a)
newtype T2 = MkT2 (forall a. F a)
foo :: T1 -> T2
foo = coerce
If you try this:
foo :: T1 -> T2
foo (MkT1 x) = MkT2 x
You get this:
[1 of 1] Compiling Foo ( Bug.hs, interpreted )
Bug.hs:13:21: error:
• Couldn't match expected type ‘F a’ with actual type ‘F a0’
NB: ‘F’ is a non-injective type family
The type variable ‘a0’ is ambiguous
• In the first argument of ‘MkT2’, namely ‘x’
In the expression: MkT2 x
In an equation for ‘foo’: foo (MkT1 x) = MkT2 x
13 | foo (MkT1 x) = MkT2 x
| ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment