I'm practicing sml using problems from Ullman(M97) second edition. The problem I am currently working on calls for a piglatin function that takes in a word, explodes it, and checks if the first character is a vowel (a, e, i, o u). If it is a vowel, it implodes the character list back into a string and adds "yay" at the end. If the first character is not a vowel, the function then checks the rest of the characters until it comes across the first vowel. When it does, it places all characters that came before the first vowel at the end of the character list, implodes the new character list back into a string and adds "ay" to it.
For example:
- pl "able";
val it = "ableyay" : string
- pl "stripe";
val it = "ipestray" : string
fun isVowel (c::cs) =
if c = #"a" then true
else if c = #"e" then true
else if c = #"i" then true
else if c = #"o" then true
else if c = #"u" then true
else false
fun cycle nil = nil
| cycle (h :: hs) = hs @ [h]
fun aL (h::hs) =
if isVowel(h) = true
then h :: hs
else aL (cycle (h :: hs))
fun plx (x) =
if isVowel x = true
then (implode x) ^ "yay"
else implode (aL (x)) ^ "ay"
fun pl (x) = plx (explode x)
I have most of the problem done, but I am stuck on why my plx function gives me this:
Error: operator and operand don't agree [tycon mismatch]
operator domain: char list list
operand: char list
in expression: aL x uncaught exception Error
and I am not sure how to fix it.