1-- This example is basically the same as in Simplest.hs, only it uses
2-- SYB generics instead of explicit instances of ToJSON and FromJSON.
4-- This mechanism is much slower than the newer generics mechanism
5-- demonstrated in Generic.hs, but it works on versions of GHC older
8-- We enable the DeriveDataTypeable language extension so that GHC can
9-- automatically derive the Typeable and Data classes for us.
11{-# LANGUAGE DeriveDataTypeable #-}
13{-# LANGUAGE OverloadedStrings #-}
15import Data.Data (Typeable, Data)
16import Data.Aeson.Generic (decode, encode)
17import qualified Data.ByteString.Lazy.Char8 as BL
19-- To decode or encode a value using the generic machinery, we must
20-- make the type an instance of the Typeable and Data classes.
22data Coord = Coord { x :: Double, y :: Double }
23 deriving (Show, Typeable, Data)
27 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
29 let reply = Coord 123.4 20
30 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