0

Digging through the source:

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

stumbled upon the signature of get:

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

and ventured into psci:

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

Focusing on the tail part of return type, how is:

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

matched against Respondable a from the first signature -- a from Respondable a => Affjax e a? Zilch of the instances of Respondable:

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. Waat's going on?!

Elucidate the lone rabbit how to dig herself out of similar deep holes in the future. Tnx!

levant pied
  • 3,886
  • 5
  • 37
  • 56

1 Answers1

2

I'm not sure if I fully understand your question but I think that your problem rised from the fact that psci expands type aliases. Let's try to do this manually and check if it has done good job. You can find these type aliases in the same file where get is defined:

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

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

So given that get has type:

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

we can try to substitute all it's aliases. I'm using vertical formatting here for readability. Let's use first alias for Affjax a e:

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

And now second for AffjaxResponse a:

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