嘿伙计们,所以我想获取一个单词列表并返回一个与其类似的列表,但每次出现连续单词时都会进行以下替换。
一个例子是you
把它变成u
我得到以下内容:
hep :: [Word] -> [Word]
type Word = String
现在给我的问题是我正在尝试使用大小写表达式,这样我就不必重复代码但我收到以下错误
Couldn't match expected type `Char' with actual type `[Char]'
In the pattern: "You"
In a case alternative: "You" -> "u" : hep xs
In the expression: case a of { "You" -> "u" : hep xs }
从以下代码
hep [] = []
hep [a:xs] = case a of
"You" -> "u":hep xs
有人告诉我问题是什么吗?
编辑:
我添加了以下代码
hep [] = [[]]
hep (a:xs) = case a of
"you" -> "u":hep xs
"are" -> "r":hep xs
"your" -> "ur":hep xs
"boyfriend" -> "bf":hep xs
"girlfriend" -> "gf":hep xs
"great" -> "gr8":hep xs
a -> a:hep xs
现在我如何能够添加一个案例,以便如果列表中包含 2 或 3 个特定单词的顺序,我可以将其转换为首字母缩略词?
前任
["By","The","way"] = ["btw"]