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.
4{-# LANGUAGE NoImplicitPrelude #-}
5{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE TemplateHaskell #-}
8module Main (main) where
12import Data.Aeson (decode, encode)
13import Data.Aeson.TH (deriveJSON, defaultOptions)
14import qualified Data.ByteString.Lazy.Char8 as BL
16data Coord = Coord { x :: Double, y :: Double }
19-- This splice will derive instances of ToJSON and FromJSON for us.
21$(deriveJSON defaultOptions ''Coord)
25 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
27 let reply = Coord { x = 123.4, y = 20 }
28 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