Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.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,我有一个名为bounds1acum的函数。这个功能非常有效 bounds1Accum :: [Integer] -> Integer -> Integer -> (Integer, Integer) bounds1Accum l min max = (minimum (min:l), maximum (max:l)) 我遇到的问题是,我需要另一个名为bounds1的函数,它只接受一个列表并返回一个minmax对。此函数应该环绕bounds1accum并首先检查传递给它的列表

我有一个名为bounds1acum的函数。这个功能非常有效

bounds1Accum ::  [Integer] -> Integer -> Integer -> (Integer, Integer)
bounds1Accum l min max = (minimum (min:l), maximum (max:l))
我遇到的问题是,我需要另一个名为bounds1的函数,它只接受一个列表并返回一个minmax对。此函数应该环绕bounds1accum并首先检查传递给它的列表是否为空。如果列表为空,它将不返回任何内容,或者只返回调用bounds1Accum函数的结果

我需要两个箱子,我有我的签名

bounds1 :: [l] -> Maybe(min,max)
bounds1 [] = Nothing (which I am unsure if this will be correct)
那么第二个案例就是我被难倒的地方 我本来有

bounds1 l  min max  = if null l then Nothing else Just $ bounds1 bounds1Accum min max
但这甚至不编译,所以如果有人能提供建议或其他方式,我可以看看这个问题,这将是伟大的。这是一个作业,所以我不想要答案,更重要的是只是指导或帮助解决问题。
谢谢

在第二种情况下,您没有
min
max
作为参数。您必须从列表中获取这些值

if
是不必要的,因为您已经在第一种情况下处理了空列表


为什么在使用
bounds1acum
之前会有
bounds1
呢?

我建议用警卫来写,而不是用if-then-else。主要是因为这看起来更像分段函数定义,这就是我们要做的。所以bounds1[]=对于第一种情况,什么都不好?大小写应该是bounds1 l=Just$bounds1 bounds1acum l min max?我把bounds1放在第一位,因为它应该环绕bounds1acum。也许我的想法是错误的。如果这更有帮助的话,我可以添加实际需要的规范。@benzo_-nerd我认为包装bounds1Accum只意味着使用正确的参数调用它。是的,第一个案例是可以的。当我试着运行它时,它告诉我案例2的参数数量和我的签名是错误的。我的案例#2看起来像这个bounds1 l=只是$bounds1 bounds1Accum l min max我也尝试过切换bounds1和bounds1Accum,结果是一样的,我不明白bounds1在bounds1Accum前面做了什么。顺便说一句,您确定bound1Accum的实现是正确的吗?它没有做它的名字所暗示的。