Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
WebサーバーからJSON文字列を取得して解析する単純なhaskellプログラムを作成しようとしています。
Network.CurlのcurlGetStringメソッドを使用しています。
このメソッドには、次の型シグネチャがあります
curlGetString :: URLString -> [CurlOption] -> IO (CurlCode, String)
私の質問は:出力を(CurlCode、String)からStringに変換するにはどうすればよいですか?
ありがとう!
応答本体は、タプルの2番目の要素にすぎません。最初curlGetStringにIOモナドの結果をバインドし、次にsndパターンマッチングを使用します。
curlGetString
IO
snd
main = do (code, body) <- curlGetString "http://foo.example.com/" [...] case code of CurlOK -> putStr body _ -> putStrLn $ "Error: " ++ show code
Hoogle検索でタイプ別に関数を見つけることができることを忘れないでください。