Created
July 27, 2012 10:18
-
-
Save liamoc/3187282 to your computer and use it in GitHub Desktop.
Yaml example
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 OverloadedStrings #-} | |
module Main where | |
import Data.Yaml | |
import System.Environment | |
import Control.Applicative | |
data Whatever = Foo { courses :: [String], required :: Int } deriving Show | |
instance FromJSON Whatever where | |
parseJSON (Object v) = Foo <$> (v .: "courses") <*> (v .: "required") | |
parseJSON _ = fail "Fucked!" | |
printWhatever :: [Whatever] -> IO () | |
printWhatever = mapM_ print | |
main = fmap head getArgs >>= decodeFile >>= \(Just x) -> printWhatever x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment