Created
March 16, 2012 18:16
-
-
Save sw17ch/2051600 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 DeriveDataTypeable #-} | |
module Main where | |
-- Using strict imports so that we know where stuff comes from. | |
import Data.Generics (Data, Typeable) | |
import Text.JSON.Generic (JSValue, toJSON) | |
import Text.JSON.Pretty (render, pp_value) | |
data SuperHeroes = Batman { phrase :: String } | |
| IronMan { phrase :: String } | |
| TheIncredibleHulk { phrase :: String } | |
| Thor { phrase :: String } | |
| Spiderman { phrase :: String } | |
| RecursiveMan { phrase :: String, deeper :: SuperHeroes } | |
deriving (Show, Data, Typeable) | |
awzm :: [SuperHeroes] | |
awzm = [ Batman "my parents are deaaaaaaaaad!" | |
, IronMan "i'm rich and womanize a lot" | |
, TheIncredibleHulk "HULK SMASH!" | |
, Thor "hehehe.. thunder" | |
, Spiderman "i lack a cool catchphrase" | |
, RecursiveMan "i'm confused" $ IronMan "whaaaaaaat" | |
] | |
awzmJSON :: JSValue | |
awzmJSON = toJSON awzm | |
main :: IO () | |
main = putStrLn $ render $ pp_value awzmJSON | |
{- | |
- $ runhaskell -Wall hs_json.hs | |
- [{"Batman": {"phrase": "my parents are deaaaaaaaaad!"}}, | |
- {"IronMan": {"phrase": "i'm rich and womanize a lot"}}, | |
- {"TheIncredibleHulk": {"phrase": "HULK SMASH!"}}, | |
- {"Thor": {"phrase": "hehehe.. thunder"}}, | |
- {"Spiderman": {"phrase": "i lack a cool catchphrase"}}, | |
- {"RecursiveMan": {"phrase": "i'm confused", | |
- "deeper": {"IronMan": {"phrase": "whaaaaaaat"}}}}] | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment