1-- This example is basically the same as in Simplest.hs, only it uses
2-- GHC's builtin generics instead of explicit instances of ToJSON and
5-- We enable the DeriveGeneric language extension so that GHC can
6-- automatically derive the Generic class for us.
8{-# LANGUAGE DeriveGeneric #-}
10{-# LANGUAGE OverloadedStrings #-}
12import Data.Aeson (FromJSON, ToJSON, decode, encode)
13import qualified Data.ByteString.Lazy.Char8 as BL
15-- To decode or encode a value using the generic machinery, we must
16-- make the type an instance of the Generic class.
18import GHC.Generics (Generic)
20data Coord = Coord { x :: Double, y :: Double }
21 deriving (Show, Generic)
23-- While we still have to declare our type as instances of FromJSON
24-- and ToJSON, we do *not* need to provide bodies for the instances.
25-- Default versions will be supplied for us.
27instance FromJSON Coord
32 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
34 let reply = Coord 123.4 20
35 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