我試圖做一個非常短的代碼,因爲我們有一個有利於最短代碼的reglementation。 我們必須創建一個函數,以相同的順序將列表變成一個新的升序和降序列表:例如。 [1,6,2,1,7,3,2,8,4]
,成爲[[1,6],[2,1],[7],[3,2],[8],[4]]
壓痕的位置不正確?短代碼
所以我試圖做到以下幾點:
func :: Ord a => [a] -> [[a]]
func xs = f1 d [a]
f1 [] ys = [c]
f1 xs ys | a >= b = d `f1` a:ys
| otherwise = c: d `f2` [a]
f2 [] ys = [c]
f2 xs ys | a < b = d `f2` a:ys
| otherwise = c : d `f1` [a]
where a = head xs
b = head ys
c = reverse ys
d = tail xs
但我對line "b = head ys"
得到
parse error on input '='
。
我認爲可以在where塊中定義多個函數嗎?
產生的誤差像很多
not in scope 'a'
not in scope 'b'
not in scope 'c'
not in scope 'd'
或
parse error on input 'b'
其他壓痕我不得不做出這種方式節省一些代幣/較短的代碼。
製表符?如果是的話,用火殺死他們。 –
誰問過你這麼短的代碼,爲什麼? – AndrewC