这种类型是如何推断出来的?

How is this type inferred?

挖掘来源:

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

偶然发现 get 的签名:

get :: forall e a. Respondable a => URL -> Affjax e a

并涉足 psci:

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

关注return类型的尾部,怎么样:

Respondable a =>
{ status :: StatusCode
, headers :: Array ResponseHeader
, response :: a
}

与第一个签名中的 Respondable a 匹配 - Respondable a => Affjax e a 中的 aRespondable:

实例的 Zilch
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

匹配 Record。 Waat正在进行中?!

说明这只孤独的兔子将来如何从类似的深坑中挖出来。谢谢!

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

type Affjax e a = 
  Aff
    (ajax :: AJAX | e)
    (AffjaxResponse a)

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

假设 get 的类型为:

get :: forall e a
  . Respondable a
  => URL
  -> Affjax e a

我们可以尝试替换它的所有别名。为了便于阅读,我在这里使用垂直格式。让我们为 Affjax a e 使用第一个别名:

-- using first alias
get :: forall e a
  . Respondable a
  => URL
  -> Aff
      (ajax :: AJAX | e)
      (AffjaxResponse a)

现在 AffjaxResponse a 排名第二:

get :: forall e a
  . Respondable a
  => URL
  -> Aff
      (ajax :: AJAX | e)
      { status :: StatusCode
      , headers :: Array ResponseHeader
      , response :: a
      }