代码之家  ›  专栏  ›  技术社区  ›  hgiesel

种类签名和类型族

  •  6
  • hgiesel  · 技术社区  · 7 年前

    我希望

    type family Rep a
    

    type family Rep :: * -> *
    

    是一样的,但似乎有区别

    type family   Rep a
    type instance Rep Int  = Char
    -- ok
    
    type family   Rep :: * -> *
    type instance Rep Int  = Char
    -- Expected kind * -> *, but got 'Int' instead
    

    1 回复  |  直到 7 年前
        1
  •  13
  •   chi    7 年前

    是的,有一个微妙的区别。

    type family F a :: *->* 比如说, F Int 类构造函数类型 [] , Maybe

    type family F a :: * -> *
    
    -- these three examples can be removed / changed, if wished
    type instance F Int = []
    type instance F Char = Maybe
    type instance F Bool = (,) String
    
    foo :: (F Int a :~: F Int b) -> (a :~: b)
    foo Refl = Refl
    

    为了进行上述类型检查,编译器利用了以下事实: F Int a ~ F Int b 暗示 a ~ b

    type family F a b :: * F整数

    type family F a b :: *
    type instance F Int a = ()