robkuz
robkuz

Reputation: 9924

How to define the type signature on this Affjax call

I am having this simple program using Affjax and launchAff.

import Network.HTTP.Affjax as Affjax
import Control.Monad.Aff (launchAff)

test1 = launchAff $ do Affjax.get "/api"

this gives me the following error

 58  test1 = launchAff $ do Affjax.get "/api"
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 No type class instance was found for

 Network.HTTP.Affjax.Response.Respondable _0

 The instance head contains unknown type variables. Consider adding a type annotation.

 in value declaration test1

 where _0 is an unknown type

I understand that Respondable needs to be be defined here but I really dont get how to do it exactly.

Any help is greatly appreciated.

Thx

Upvotes: 3

Views: 356

Answers (1)

Christoph Hegemann
Christoph Hegemann

Reputation: 1434

You'll need to annotate your test1 function to let the compiler know what you expect to get back from that ajax call.

test1 = launchAff do
  Affjax.get "/api" :: Affjax _ Foreign

You can choose any one of these instances for your return type, or if you expect your own datatype to be returned, write a Respondable instance for it.

EDIT: I edited the source code. The provided codesnippet isn't very useful though, since you're not doing anything with the AJAX response. Since Affjax operates inside Aff you can use do notation to bind the result of the GET call to a variable and proceed to use it from there.

Upvotes: 3

Related Questions