Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not all that difficult, since io-streams has attoparsec support and aeson is an attoparsec parser... coded directly in the input box, I don't have io-streams installed so I can't see if this typechecks:

    import Control.Applicative
    import Data.Aeson
    import Data.ByteString
    import System.IO.Streams
    import System.IO.Streams.Attoparsec (parseFromStream)

    parseJSONFromStream :: FromJSON a => InputStream ByteString -> IO a
    parseJSONFromStream = parseJSON <$> parseFromStream json'


I started looking at attoparsec after the post. Thanks, I'll look closer and see if I can figure it out.


Found this: https://github.com/RobinKrom/Mtgox/blob/master/src/Mtgox/Htt...

receiveResponse con (\_ i -> parseFromStream json i))

This seems to work but without the benefit of being marshalled into my type.


The `parseJSON <$>` bit in my sample converts it to your type. If you don't like the infix applicative it could be written as:

    receiveResponse con (fmap parseJSON . parseFromStream json)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: