通过'type function argument'我的意思是这个
> newtype Wrapper f a = Wrapper (f a)
> :kind Wrapper
Wrapper :: (* -> *) -> * -> *
Run Code Online (Sandbox Code Playgroud)
所以f这是一个类型函数参数,所以我可以像这样构造类型
> :kind Wrapper Maybe Int
Wrapper Maybe Int :: *
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我实际使用f的是值Wrapper,我想忽略它:
> newtype Wrapper f a = Wrapper a
> :kind Wrapper
Wrapper :: * -> * -> *
Run Code Online (Sandbox Code Playgroud)
你猜怎么着!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’
Run Code Online (Sandbox Code Playgroud)
那么如何构造类型相同的way(Wrapper Maybe Int)而不需要Maybe在我的Wrapper值中具有具体的值?
结果我只需要使用语言扩展:
> {-# LANGUAGE KindSignatures #-}
> newtype Wrapper (f :: * -> *) a = Wrapper a
> :kind Wrapper
Wrapper :: (* -> *) -> * -> *
Run Code Online (Sandbox Code Playgroud)