Last active
August 29, 2015 14:02
-
-
Save maoe/e5f72c3cf3687610fe5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Monad | |
import Data.Aeson | |
import qualified Data.ByteString.Lazy as B | |
{- Generic Language extension -} | |
import GHC.Generics (Generic) | |
data Pull = Pull { | |
title :: String | |
} deriving (Show, Generic) | |
instance FromJSON Pull | |
instance ToJSON Pull | |
main = do | |
bstr <- (B.readFile "test.json") | |
loop bstr (100 :: Int) | |
where | |
loop _ 0 = return () | |
loop bstr n = do | |
case decode bstr :: Maybe [Pull] of | |
Just ps -> mapM_ (putStrLn . title) ps | |
Nothing -> putStr "can't parse test.json" | |
loop bstr $ n-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment