2016-09-09 4 views
7

に私のように、コードを持っていない:ハスケル:変数がスコープ

main = interact $ show . maxsubseq . map read . words 

maxsubseq :: (Ord a,Num a) => [a] -> (a,[a]) 
maxsubseq = snd . foldl f ((0,[]),(0,[])) where 
f ((h1,h2),sofar) x = (a,b) where 
a = max (0,[]) (h1 + x ,h2 ++ [x]) 
b = max sofar a 

しかし、私はエラーを取得しています:なぜ把握する

maxSub.hs:6:17: error: Variable not in scope: h1 

maxSub.hs:6:22: error: Variable not in scope: x 

maxSub.hs:6:25: error: Variable not in scope: h2 :: [t1] 

maxSub.hs:6:32: error: Variable not in scope: x 

maxSub.hs:7:9: error: Variable not in scope: sofar :: (t, [t1]) 

ことができません?

ありがとうございました。本当に重要Haskellでは

答えて

12
main = interact $ show . maxsubseq . map read . words 

maxsubseq :: (Ord a,Num a) => [a] -> (a,[a]) 
maxsubseq = snd . foldl f ((0,[]),(0,[])) where 
f ((h1,h2),sofar) x = (a,b) where 
    a = max (0,[]) (h1 + x ,h2 ++ [x]) 
    b = max sofar a 

フォーマット...

は、おそらくこれは良く見える:私は今noobのように感じてい

main = interact $ show . maxsubseq . map read . words 

maxsubseq :: (Ord a,Num a) => [a] -> (a,[a]) 
maxsubseq = snd . foldl f ((0,[]),(0,[])) where 
    f ((h1,h2),sofar) x = (a,b) 
     where { 
     a = max (0,[]) (h1 + x ,h2 ++ [x]); 
     b = max sofar a; 
       } 
+0

。どうもありがとう。できます!! –