Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Types 如何定义此Affjax调用的类型签名_Types_Purescript - Fatal编程技术网

Types 如何定义此Affjax调用的类型签名

Types 如何定义此Affjax调用的类型签名,types,purescript,Types,Purescript,我使用Affjax和launchAff编写了这个简单的程序 import Network.HTTP.Affjax as Affjax import Control.Monad.Aff (launchAff) test1 = launchAff $ do Affjax.get "/api" 这给了我以下的错误 58 test1 = launchAff $ do Affjax.get "/api" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我使用Affjax和
launchAff
编写了这个简单的程序

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

test1 = launchAff $ do Affjax.get "/api"
这给了我以下的错误

 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
我知道这里需要定义
Respondable
,但我真的不知道该怎么做

非常感谢您的帮助


Thx

您需要对test1函数进行注释,让编译器知道您希望从ajax调用中得到什么

test1 = launchAff do
  Affjax.get "/api" :: Affjax _ Foreign
您可以为返回类型选择其中任何一个,或者如果您希望返回自己的数据类型,请为其编写一个
Respondable
实例

编辑:我编辑了源代码。不过,提供的代码片段不是很有用,因为您没有对AJAX响应执行任何操作。由于
Affjax
Aff
内部运行,因此可以使用do表示法将
GET
调用的结果绑定到变量,并从那里继续使用它