首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这种类型是如何推断的?

这种类型是如何推断的?
EN

Stack Overflow用户
提问于 2017-12-22 15:32:54
回答 1查看 59关注 0票数 0

通过消息来源进行挖掘:

https://github.com/slamdata/purescript-affjax/blob/v5.0.0/src/Network/HTTP/Affjax.purs#L92

偶然发现了get的签名

代码语言:javascript
复制
get :: forall e a. Respondable a => URL -> Affjax e a

并冒险进入psci:

代码语言:javascript
复制
> import Network.HTTP.Affjax
> :t get
forall e a.
  Respondable a => String
                   -> Aff
                        ( ajax :: AJAX
                        | e
                        )
                        { status :: StatusCode
                        , headers :: Array ResponseHeader
                        , response :: a
                        }

集中于返回类型的尾部部分,如何:

代码语言:javascript
复制
Respondable a =>
{ status :: StatusCode
, headers :: Array ResponseHeader
, response :: a
}

与第一个签名中的Respondable a匹配--来自Respondable a => Affjax e aaRespondable实例的Zilch

代码语言:javascript
复制
instance responsableBlob :: Respondable Blob where
instance responsableDocument :: Respondable Document where
instance responsableForeign :: Respondable Foreign where
instance responsableString :: Respondable String where
instance responsableUnit :: Respondable Unit where
instance responsableArrayBuffer :: Respondable A.ArrayBuffer where
instance responsableJson :: Respondable Json where

matche Record.瓦特在继续吗!

阐明了独行兔今后如何从类似的深孔中挖出自己。Tnx!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-22 21:37:07

我不确定我是否完全理解您的问题,但我认为您的问题是因为psci扩展了类型别名这一事实。让我们尝试手动完成这项工作,并检查它是否做得很好。您可以在定义get的同一文件中找到这些类型别名:

代码语言:javascript
复制
type Affjax e a = 
  Aff
    (ajax :: AJAX | e)
    (AffjaxResponse a)

type AffjaxResponse a =
  { status :: StatusCode
  , headers :: Array ResponseHeader
  , response :: a
  }

因此,考虑到get有类型:

代码语言:javascript
复制
get :: forall e a
  . Respondable a
  => URL
  -> Affjax e a

我们可以试着用所有的化名来代替。为了提高可读性,我在这里使用垂直格式。让我们为Affjax a e使用第一个别名

代码语言:javascript
复制
-- using first alias
get :: forall e a
  . Respondable a
  => URL
  -> Aff
      (ajax :: AJAX | e)
      (AffjaxResponse a)

现在AffjaxResponse a排名第二

代码语言:javascript
复制
get :: forall e a
  . Respondable a
  => URL
  -> Aff
      (ajax :: AJAX | e)
      { status :: StatusCode
      , headers :: Array ResponseHeader
      , response :: a
      }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47943917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档