I’ve tried to write a function to do this but can’t get GHCI to understand my code. I’m coming from an OOP background so functional programming is completely new territory for me.
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"
Several issues here:
String -> String, so it should only have one argument, while your definition has two arguments,sentenceand(x:xs)."true"and"false". Use booleans. That’s what they’re for.ifmust be a boolean. If you want several conditions to hold, use(&&)orandto combine them.if-expression must have both athenand anelse. You can think ofif x then y else zlike the ternaryx ? y : zoperator in some other languages.'a'and'y'have typeChar, so you can’t compare them against strings with==. Compare with"a"and"y"instead.However, there is no point in writing
if something then True else False. Instead, just use the boolean expression directly.