Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.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
Haskell 递归数据构造函数中的类型签名无效_Haskell - Fatal编程技术网

Haskell 递归数据构造函数中的类型签名无效

Haskell 递归数据构造函数中的类型签名无效,haskell,Haskell,因此,以下内容以及上的示例代码未能加载到ghci中: data MyStream a = MyStream a (MyStream a) intsFrom n :: MyStream Integer intsFrom n = MyStream n $ intsFrom $ n + 1 获取错误: stream.hs:3:1: Invalid type signature: intsFrom n :: MyStream Integer Should be of form <

因此,以下内容以及上的示例代码未能加载到ghci中:

data MyStream a = MyStream a (MyStream a)

intsFrom n :: MyStream Integer
intsFrom n = MyStream n $ intsFrom $ n + 1
获取错误:

stream.hs:3:1:
    Invalid type signature: intsFrom n :: MyStream Integer
    Should be of form <variable> :: <type>
Failed, modules loaded: none.

您应该在带有类型签名的行中使用函数名,而不是添加参数名。所以不是

intsFrom n :: MyStream Integer
使用

您还必须确保声明的类型与函数匹配。由于函数采用
整数
参数,因此正确的签名应为:

intsFrom :: Integer -> MyStream Integer

您应该在带有类型签名的行中使用函数名,而不是添加参数名。所以不是

intsFrom n :: MyStream Integer
使用

您还必须确保声明的类型与函数匹配。由于函数采用
整数
参数,因此正确的签名应为:

intsFrom :: Integer -> MyStream Integer

看起来您希望您的签名是这样的:

intsFrom :: Integer -> MyStream Integer

Integer
这是您的参数,
MyStream Integer
是来自
intsFrom的结果,看起来您希望您的签名是这样的:

intsFrom :: Integer -> MyStream Integer

Integer
这是您的参数,
MyStream Integer
是来自
intsFrom
的结果。啊,很抱歉类型签名被破坏了。我已经更新了这篇文章。啊,很抱歉我的签名被破坏了。我已经更新了这篇文章。