Haskellの標準単語機能を実装しようとしています。State Monad を使用して問題を解決しています。
私のコードは:
type WorS = ([String],String,String)
words' :: State WorS [String]
words' = do
(lwords, words, x:xs) <- get
case x:xs of
(' ':xs) -> (put (words:lwords, [], xs) >> words')
([]) -> return lwords
(_:xs)-> (put (lwords, words ++ [x], xs) >> words')
run_word' :: String ->[String]
run_word' x = reverse $ fst (runState words' ([], [], x))
私がする時:
run_word' "guns and roses"
次のエラーが表示されます。
Exception: Pattern match failure in do expression
コードはエラーなしで ghci にロードされています。私は何を間違っていますか?