Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this injective type family not actually injective?

I tried this:

{-# LANGUAGE TypeFamilyDependencies #-}
module Injective where

type family F (a :: *) = (fa :: *) | fa -> a

convert :: F a ~ F b => a -> b
convert x = x

GHC 8.6.4 gave me this error

    • Could not deduce: a ~ b
      from the context: F a ~ F b
        bound by the type signature for:
                   convert :: forall a b. (F a ~ F b) => a -> b
        at Injective.hs:6:1-30

Why? Surely the whole point of injectivity is that one can deduce a ~ b from F a ~ F b?

like image 780
Ashley Yakeley Avatar asked Apr 05 '19 21:04

Ashley Yakeley


1 Answers

It turns out this is a known issue in GHC. Apparently it's because it hasn't been proven sound.

like image 164
Ashley Yakeley Avatar answered Nov 11 '22 09:11

Ashley Yakeley