2
これにMaybe [int]を組み込みたいと思います。Intのリストへの文字列
コードは文字列を取り、空白をフィルタリングして整数のリストに変換し、文字がNothingを返すようにする必要があります。
text2digits :: String -> [Int]
text2digits s = case s of
[] -> []
x:xs
|isDigit x -> digitToInt x :text2digits (filter (/= ' ') xs)
|otherwise -> undefined
input "1233 5687" output: [1,2,3,3,5,6,8,7]
input "a89" required output : Nothing
current output: undefined
私はこれを試してみましたが、それはあなたがtext2digits :: String -> Maybe [Int]
のために指定したコードを、と間違っている何のエラー
text2digits :: String -> Maybe [Int]
text2digits s = case s of
[] -> Just []
x:xs
|isDigit x -> Just digitToInt x :text2digits (filter (/= ' ') xs)
|otherwise -> Nothing
現在のコードに何が問題なのかを指定します。入力と期待される出力の例を提供する。 –
'otherwise'の場合、' Nothing'を返します。ただし、 'isDigit'の場合と' [] 'の場合の戻り値の型を 'Maybe [Int]'に変更する必要があります。あなたは 'Just'を使ってそれを行うことができます。 –
'Nothing'をリストにマージすることはできません... –