0
問題:
使3元組的所有組合代表名詞 - 動詞 - 名詞句子。爲了做到這一點,我決定試着讓問題更容易閱讀,因爲verbComb的未來看起來並不「乾淨」,通過玩數據類型並遇到這個問題。請幫忙!Haskell:爲什麼這是不正確的?我將一個數據類型作爲類型構造函數放在另一個數據聲明中
我的代碼:
type Letter = Char
data Word = Noun (Letter, Letter, Letter)| Verb (Letter, Letter, Letter)
deriving (Ord, Eq, Show)
data Sentence = (Word, Word, Word)
deriving (Show)
stops = "pbtdkg"
vowels = "aeiou"
vowelComb :: String -> String -> [(Char, Char, Char)]
vowelComb s v = combine s v s ++ combine (reverse s) v s ++ combine s v (reverse s)
where combine f s t = [ (x,y,z) | x <- f, y <- s, z <- t, x == 'p']
verbComb :: Word -> Word -> Sentence
verbComb = undefined
錯誤:
chp10.hs:88:21: Ambiguous occurrence ‘Word’ It could refer to either ‘Chp10.Word’, defined at chp10.hs:75:1 or ‘Prelude.Word’, imported from ‘Prelude’ at chp10.hs:28:8-12 (and originally defined in ‘GHC.Types’) Failed, modules loaded: none.
固定在當前操作後,你會得到另一個錯誤是'數據語句=(字,詞,字) '無效。你需要提供一個數據構造函數,比如'data Sentence = Sentence(Word,Word,Word)',或者像'type Letter = Char'那樣使用類型別名。 – amalloy
@amalloy等等,你是DCSS的amalloy嗎? –
@ReinHenrichs確實。 DCSS開發者和YouTuber非凡。爲什麼? – amalloy