我在哈斯克爾編程初學者,很多時候我得到的錯誤哈斯克爾 - 格式問題
xxx.hs:30:1: parse error on input `xxx'
而且經常有一點點的格式解播放。它的代碼和它看起來一樣,但玩過之後,錯誤消失了。
此刻,我已經得到了錯誤
LookupAll.hs:30:1: parse error on input `lookupAll'
代碼後:
lookupOne :: Int -> [(Int,a)] -> [a]
lookupOne _ [] = []
lookupOne x list =
if fst(head list) == x then snd(head list) : []
lookupOne x (tail list)
-- | Given a list of keys and a list of pairs of key and value
-- 'lookupAll' looks up the list of associated values for each key
-- and concatenates the results.
lookupAll :: [Int] -> [(Int,a)] -> [a]
lookupAll [] _ = []
lookupAll _ [] = []
lookupAll xs list = lookupOne h list ++ lookupAll t list
where
h = head xs
t = tail xs
但我就在我的意見所做的一切。沒有標籤或類似的東西。總是4個空格。這個問題是否有一個通用的解決方案?我現在使用記事本++。
謝謝!
您忘記了'else'子句不是Haskell中'if'表達式的可選部分。 –