- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须创建一个递归函数,它接受两个数字(n 和 k)并返回它们的二项式系数。
我必须使用 pascal::Int -> Int -> Int
老实说我不明白哪里出了问题,感谢您的帮助!
pascal :: Int -> Int -> Int
pascal n k
| k == 0 = 1
| n == n = 1
| k > n = 0
| otherwise = pascal(n-1)(k-1) + pascal(n-1) + k
以下错误是:
main.hs:7:40: error:
• Couldn't match expected type ‘Int’ with actual type ‘Int -> Int’
• Probable cause: ‘pascal’ is applied to too few arguments
In the second argument of ‘(+)’, namely ‘pascal (n - 1)’
In the first argument of ‘(+)’, namely
‘pascal (n - 1) (k - 1) + pascal (n - 1)’
In the expression: pascal (n - 1) (k - 1) + pascal (n - 1) + k
|
7 | | otherwise = pascal(n-1)(k-1) + pascal(n-1) + k
| ^^^^^^^^^^^
<interactive>:3:1: error:
• Variable not in scope: main
• Perhaps you meant ‘min’ (imported from Prelude)
最佳答案
正如异常(exception)情况所示,pascal (n-1)
没有多大意义,因为它是一个函数Int -> Int
,所以你不能添加 pascal (n-1) (k-1)
和 pascal (n-1)
在一起。
因此您需要传递一个额外的参数。例如:
pascal :: Int -> Int -> Int
pascal _ 0 = 1
pascal n k
| k == n = 1
| k > n = 0
| otherwise = pascal (n-1) (k-1) + <b>pascal (n-1) k</b>
请注意,条件n == n
始终为真,您可能想说n == k
?
关于 haskell ·帕斯卡三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58879008/
我有一个大问题,因为这段代码在 Dev-Pascal 中正确编译,但在 Lazarus 中却没有。 for k:=1 to n do begin writeln(a[k
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我有一个与 Pascal 中的 for 循环工作方式相关的问题: Program example; var i:integer; Begin i:=7; for i:=1 to i
PROGRAM RandomNumber; Var rand,count,guess : integer; LABEL correct, loop, wrong, end1; begin {Initi
我是新来的,如果我做错了什么,很抱歉! 我正在 Lazarus 中制作一个简单的 Pascal 程序,编译时出现此错误: HWE(16,18) 错误:“Char”和“Constant String”类
这个问题已经有答案了: What is the implementation of sets used in pascal? (2 个回答) 已关闭 6 年前。 我明天要去参加一个高中编程比赛,他们使
我正在用 pascal 编写一个小程序,但遇到了一个小问题。在其他语言中,有一个名为“split”或“explode”的函数,用于获取由定义的字符分隔的长字符串,并将该长字符串拆分为几个较小的字符串,
我在Pascal中找了很长时间这个算法并没有找到,我只在C++中找到了它,这令人沮丧。然后我决定将 C++ 代码翻译为 Pascal,但是有一些问题我无法解决。出现错误消息“浮点溢出”。我需要帮助才能
例如,如果我有这样的数组,如何获取具有特定索引的数组的长度 TYPE T_PERSON = PACKED RECORD Example : STRING[40]; Example2 : STR
我正在尝试使用 创建 TForm 的子类 针对某些情况的特殊构造函数,以及 将保持与当前代码的兼容性的默认构造函数。 这是我现在的代码: interface TfrmEndoscopistSear
我的插入排序算法出现此错误: insertionsort.lpr(19,17) Error: Incompatible types: got "Boolean" expected "LongInt"
我的任务是在我的屏幕上显示两个图像(两个 TImage),一个是头部,另一个是尾部(硬币),并带有一个 TButton 来随机化它们。 就是当你按下按钮时,两个图像会随机选择正面或反面。 我知道这是一
我正在编写一段代码来读取 CSV 文件并从中解析信息(目前我只有代码的开头部分,它将在文件开头的标题中读取。当我尝试编译这段代码,我在行中收到一个错误,它占用了文件中行的长度。 我收到的错误是:[Er
我正在开发一个 Java 应用程序,它是关于将 Mathcad 工作表转换为 Java 应用程序的。谁能知道/建议如何用 Java 代码编写单位(牛顿、帕斯卡、毫米、千克)? 例子:1? double
我是一名优秀的程序员,十分优秀!