我试过编写一个函数来做到这一点,但无法让GHCI理解我的代码。我来自OOP背景,所以函数式编程对我来说是一个全新的领域。在Haskell中检测猪拉丁文
checkPigLatin :: String -> String
checkPigLatin sentence (x:xs)
| check == "true" = "This is Pig Latin"
| otherwise = "Not Pig Latin"
where check = if (x `elem` "aeiouAEIOU", '-' `elem` xs, snd(break('a'==) xs) == 'a', snd(break('a'==) xs) == 'y') then "true"
什么是你想的'if'里面做?你似乎正在构建一个三元组:这是行不通的。 'if'后面的表达式需要评估为'Bool'。你也错过了'else'部分。 – 2012-03-02 20:05:11