Last active
January 9, 2019 14:01
-
-
Save RyanGlScott/e03734d6388bb6ffe3f29ca61ca39e1b to your computer and use it in GitHub Desktop.
Can you implement `foo` without `coerce`?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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