2011-11-04 80 views
3

今天開始爲學校學習haskell,我碰到一個功能問題。我不明白爲什麼它不在範圍..Haskell:不在範圍內:數據構造函數

繼承人的代碼:

ff :: [[Char]] -> [[Char]] -> [Char] 
ff A B = [[x !! 0, y !! 1] | x <- A, y <- B, (x !! 1) == (y !! 0)] 

和錯誤:

md31.hs:2:4: Not in scope: data constructor `A' 

md31.hs:2:6: Not in scope: data constructor `B' 

md31.hs:2:38: Not in scope: data constructor `A' 

md31.hs:2:46: Not in scope: data constructor `B' 

感謝提前:)

+0

正如在回答指出,變量名必須是小寫。與此相關的官方文檔位於http://www.haskell.org/onlinereport/intro.html#namespaces –

回答

7

功能參數有以Haskell中的小寫字母開頭。

因此,您需要在您的函數定義中將AB小寫(ab)。

如果標識符的首字母大寫,則假定爲data constructor

6

在Haskell大寫字母表示值數據構造爲:

data Test = A | B 

如果您需要變量使用小寫:

ff a b = [[x !! 0, y !! 1] | x <- a, y <- b, (x !! 1) == (y !! 0)]