[英]Reader Transformer Monad
newtype ReaderT r m a :: * -> (* -> *) -> * -> *
我不明白如何理解上述表达式,尤其是* -> (* -> *) -> * -> *
It should actually be 实际上应该是
ReaderT :: * -> (* -> *) -> * -> *
Loosely speaking, the type above is a the type of a function which takes an argument of type *
, another of type * -> *
, another of type *
, and produces a result of type *
. 宽泛地说,上述类型是这需要类型的参数的函数的类型
*
,另一种类型的* -> *
,另一种类型的*
,并产生类型的结果*
。 The type *
is the "type of all types". 类型
*
是“所有类型的类型”。 Eg Int :: *
, Char :: *
, etc. 例如
Int :: *
, Char :: *
等。
To avoid confusion, *
is not really called "a type" but "a kind", to reflect that it works at an higher level. 为了避免混淆,
*
并不是真正地称为“一种类型”,而是“一种类型”,以反映它在更高的层次上有效。 For instance, 'a'
has type Char
, and Char
has kind *
. 例如,
'a'
类型为Char
,而Char
类型为*
。
Finally, the kind * -> *
is the kind of unary type constructors, such as Maybe
, []
, IO
, (,) Char
, Either Bool
, etc. All of these take a type argument and return a type. 最后,kind
* -> *
是一元类型构造函数,例如Maybe
, []
, IO
, (,) Char
, Either Bool
等。所有这些都接受类型参数并返回类型。 The kind * -> *
is also the kind of any functor, applicative, or monad. * -> *
的类型也是任何仿函数,可应用程序或monad的类型。
So, if we have type r
, a type constructor m
(typically, a monad), and a type a
, we have: 因此,如果我们有类型
r
,类型构造函数m
(通常是monad)和类型a
,则我们有:
r :: *
m :: (* -> *)
a :: *
ReaderT :: * -> (* -> *) -> * -> *
ReaderT r :: (* -> *) -> * -> *
ReaderT r m :: * -> *
ReaderT r m a :: *
Hence, when all three arguments are passed, the result ReaderT rma
is a type. 因此,当所有三个参数都传递时,结果
ReaderT rma
是一个类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.