私はハスケル初心者ですので、事前にお詫び申し上げます。Haskellでリストをフィルタリングするにはどうすればいいですか?
HXTとhaskellを使用していくつかのHTML値(<a name="value-to-extract">
)を解析しています。
私はこれを行う場合:
print anames
を次にそれがこのリストを印刷します。
["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2H_4_0001","2HCH0001","2HCH0002","2HCH0003","2HCH0004","2HCH0005","2HCH0006","2HCH0007","2HCH0008","2HCH0009","2HCH0010","2HCH0011","2HCH0012","2HCH0013","2HCH0014","2HCH0015","2HCH0016","2HCH0017","2HCH0018","2HCH0019","2HCH0020","2HCH0021","2HCH0022","2HCH0023","2HCH0024","2HCH0025","2HCH0026","2HCH0027","2HCH0028","2HCH0029","2HCH0030","2HCH0031","2H_4_0033"]
今私がしたい私はこれを使用してa name=""
name
値のリストを取得することができます""
のすべてのエントリを削除します。
だから私は
nonEmptyANames <- filter (\s -> s /= "") anames
を試してみてくださいしかし、私はこのエラーを取得する:
• Couldn't match type ‘[]’ with ‘IO’
Expected type: IO String
Actual type: [String]
• In a stmt of a 'do' block:
nonEmptyANames <- filter (\ s -> s /= "") anames
私は、これはタイピングの問題だと思うので、私は試してみてください。
putStrLn ("type of aname is: " ++ (show (typeOf anames)))
そしてそれは私に語りましたaname
のタイプは[Char]
です。 ghciでfilterコマンドを実行すると、期待どおりに動作します。私はここで何が欠けていますか?
問題は 'filter'はモナドではないことを、もっと... –
書き込み'てみましょうnonEmptyANames =フィルタ(\ sは - > S/= "")であるanames' –