我所说的“类型函数参数”是指这个
> newtype Wrapper f a = Wrapper (f a)
> :kind Wrapper
Wrapper :: (* -> *) -> * -> *
所以这里的f
是一个类型函数参数,所以我可以像这样构造类型
> :kind Wrapper Maybe Int
Wrapper Maybe Int :: *
现在对我来说问题是我实际上在 Wrapper
的值中使用了 f
,而我想忽略它:
> newtype Wrapper f a = Wrapper a
> :kind Wrapper
Wrapper :: * -> * -> *
你猜怎么着! f
不再是类型函数,导致我之前的类型构造失败:
> :kind Wrapper Maybe Int
<interactive>:1:9: error:
• Expecting one more argument to ‘Maybe’
Expected a type, but ‘Maybe’ has kind ‘* -> *’
• In the first argument of ‘Wrapper’, namely ‘Maybe’
In the type ‘Wrapper Maybe Int’
那么如何以相同的方式构造类型(Wrapper Maybe Int
),而不需要在我的 Wrapper
值中包含具体的 Maybe
值?
最佳答案
原来我只需要使用语言扩展:
> {-# LANGUAGE KindSignatures #-}
> newtype Wrapper (f :: * -> *) a = Wrapper a
> :kind Wrapper
Wrapper :: (* -> *) -> * -> *
关于haskell - 声明具有未使用的类型函数参数的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49507964/