Haskell:需要了解Functor的签名 [英] Haskell: need to understand signature of Functor

查看:129
本文介绍了Haskell:需要了解Functor的签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些人可以解释我Functor的签名。

  Prelude> :info Functor 
class Functor(f :: * - > *)其中
fmap ::(a - > b) - > f a - > f b
(< $):: a - > f b - > fa

我不明白 * 的意思。

解决方案> 是Haskell用于 种类



这意味着 f 是更高级的(在类型级别上考虑函数)



这里<$ c $ (第一个 * ),并产生另一个类型(第二个 *

你基本上可以忘掉所有这些,只需将其读为:

pre > class Functor f where
fmap ::(a - > b) - > f a - > f b
(< $):: a - > f b - > fa

但它是一个很好的IMO文档,有很多类更复杂, em> kind-signature 真的很有用 - 例如:

  class MonadTrans(t ::(*  - > ; *) - > *  - > *)其中
lift :: Monad m => m a - > tma
- 在`Control.Monad.Trans.Class'中定义

这里 t 将一个类型构造函数本身(Monad)与另一个类型一起使用,并重新生成一个类型。


Can some body explain me the signature of Functor.

Prelude> :info Functor
class Functor (f :: * -> *) where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a

I don't understand what * means.

解决方案

* is the syntax used by Haskell for kinds

In this case it means that f is higher-kinded (think functions on the type level)

Here f is taking one type (the first *) and is producing another type (the second *)

you can basically forget all this here and just read it as:

class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a

but it's a nice documentation IMO and there are quite a few classes that are more complicated and the kind-signature is really helpful - for example:

class MonadTrans (t :: (* -> *) -> * -> *) where
  lift :: Monad m => m a -> t m a
        -- Defined in `Control.Monad.Trans.Class'

Here t takes a type-constructor itself (the Monad) together with another type and produces a type again.

这篇关于Haskell:需要了解Functor的签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆