我一直在尝试使以下代码工作:
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
import Data.List
format :: String -> String
format [] = []
format (a:b:xs)
| a == 'W' && b == 'U' = " " ++ format (drop 1 xs)
| otherwise = a : format (b:xs)
songDecoder :: String -> String
songDecoder xs = unwords. words . format $ xs
Run Code Online (Sandbox Code Playgroud)
当我测试时:
歌曲解码器“AWUBBWUBC”
我希望“ABC”作为输出。但是,我收到了一个不寻常的模式匹配警告:
Pattern match(es) are non-exhaustive
In an equation for ‘format’: Patterns not matched: [_]
Run Code Online (Sandbox Code Playgroud)
我不确定为什么我需要匹配 [_]
format (a:b:xs)
Run Code Online (Sandbox Code Playgroud)
请帮忙。