小编Nic*_*off的帖子

类型家族多态性

所以我有一个函数apply :: proxy tf -> tf Int -> tf Int,它接受一个旨在携带一个类型族的代理,并将Int应用于该类型族以确定第二个参数的类型和返回值.但是,我收到GHC的一些令人困惑的回应.

{-# LANGUAGE TypeFamilies #-}

import Data.Proxy

type family F (a :: *) :: * where
    F Int = ()

f :: Proxy F
f = Proxy

apply :: proxy tf -> tf Int -> tf Int
apply _ x = x

-- Doesn't typecheck.
test1 :: ()
test1 = apply f ()

-- Typechecks fine
test2 :: ()
test2 = let g = apply f in g () …
Run Code Online (Sandbox Code Playgroud)

polymorphism haskell type-families

8
推荐指数
1
解决办法
231
查看次数

标签 统计

haskell ×1

polymorphism ×1

type-families ×1