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中将函数从LET迁移到WHERE_Haskell - Fatal编程技术网

在Haskell中将函数从LET迁移到WHERE

在Haskell中将函数从LET迁移到WHERE,haskell,Haskell,为了提高我的Haskell技能,我决定阅读一些示例代码,并尝试以不同的方式重写 以下是初始函数: quicksort :: (Ord a) => [a] -> [a] quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort [a | a <- xs, a <= x] biggerSorted = quicksort [a | a <- xs, a

为了提高我的Haskell技能,我决定阅读一些示例代码,并尝试以不同的方式重写

以下是初始函数:

quicksort :: (Ord a) => [a] -> [a]  
quicksort [] = []  
quicksort (x:xs) =   
    let smallerSorted = quicksort [a | a <- xs, a <= x]  
        biggerSorted = quicksort [a | a <- xs, a > x]  
    in  smallerSorted ++ [x] ++ biggerSorted  
quicksort :: (Ord a) => [a] -> [a]  
quicksort [] = []  
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted 
    where smallerSorted = quicksort [a | a <- xs, a <= x]  
        biggerSorted = quicksort [a | a <- xs, a > x]  

非常感谢

您需要匹配
where
子句中表达式的缩进,例如

quicksort :: (Ord a) => [a] -> [a]  
quicksort [] = []  
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted 
    where smallerSorted = quicksort [a | a <- xs, a <= x]  
          biggerSorted = quicksort [a | a <- xs, a > x]  
快速排序::(Ord a)=>[a]->[a]
快速排序[]=[]
快速排序(x:xs)=小排序+++[x]++大排序
其中smallerSorted=快速排序[a | a[a]
快速排序[]=[]
快速排序(x:xs)=小排序+++[x]++大排序
哪里

smallerSorted=quicksort[a | a通常在寻求帮助时,你应该说明你认为它不起作用的原因。如果代码没有编译,你应该粘贴错误消息。如果代码生成错误的输出,你应该给我们输入和输出示例,并告诉我们你认为输出应该是什么。
quicksort :: (Ord a) => [a] -> [a]  
quicksort [] = []  
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted 
    where smallerSorted = quicksort [a | a <- xs, a <= x]  
          biggerSorted = quicksort [a | a <- xs, a > x]  
quicksort :: (Ord a) => [a] -> [a]  
quicksort [] = []  
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted 
    where
        smallerSorted = quicksort [a | a <- xs, a <= x]  
        biggerSorted = quicksort [a | a <- xs, a > x]