1-- We can use Template Haskell (TH) to generate instances of the
2-- FromJSON and ToJSON classes automatically. This is the fastest way
3-- to add JSON support for a type.
5{-# LANGUAGE TemplateHaskell #-}
7{-# LANGUAGE OverloadedStrings #-}
9import Data.Aeson (decode, encode)
10import Data.Aeson.TH (deriveJSON, defaultOptions)
11import qualified Data.ByteString.Lazy.Char8 as BL
13data Coord = Coord { x :: Double, y :: Double }
16-- This splice will derive instances of ToJSON and FromJSON for us.
18$(deriveJSON defaultOptions ''Coord)
22 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
24 let reply = Coord 123.4 20
25 BL.putStrLn (encode reply)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list