on master help sign in
Ensure that basic examples are buildable
commit9e1f311a99482b9f81d1ac42bdb6cd91a52a29b0 authorBryan O'Sullivan <bos@serpentine.com> dateWed 27 May 2015, 09:37 (11 years ago) parent1e71cee
5 files changed+28−5
.hgignore+1−1 aeson.cabal+1 examples/Generic.hs−3 examples/Simplest.hs+6−1 examples/aeson-examples.cabal+20
.hgignore+1−1
@@ -1,6 +1,6 @@
11.*\.(?:aux|h[ip]|o|orig|out|pdf|prof|ps|rej)$
22^(?:dist|\.DS_Store)$
3−^benchmarks/dist$
3+^(?:benchmarks|examples)/dist$
44^tests/(?:qc)
55
66syntax: glob
aeson.cabal+1
@@ -68,6 +68,7 @@ extra-source-files:
6868 benchmarks/Typed/*.hs
6969 benchmarks/json-data/*.json
7070 changelog.md
71+ examples/*.cabal
7172 examples/*.hs
7273 examples/Twitter/*.hs
7374
examples/Generic.hs−3
@@ -2,9 +2,6 @@
22-- GHC's builtin generics instead of explicit instances of ToJSON and
33-- FromJSON.
44
5−-- This example only works with GHC 7.2 or newer, as it uses the
6−-- datatype-generic programming machinery introduced in 7.2.
7−
85-- We enable the DeriveGeneric language extension so that GHC can
96-- automatically derive the Generic class for us.
107
examples/Simplest.hs+6−1
@@ -1,7 +1,8 @@
1−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
22
33import Control.Applicative ((<$>), (<*>), empty)
44import Data.Aeson
5+import Data.Monoid
56import qualified Data.ByteString.Lazy.Char8 as BL
67
78data Coord = Coord { x :: Double, y :: Double }
@@ -13,6 +14,10 @@ instance ToJSON Coord where
1314 toJSON (Coord xV yV) = object [ "x" .= xV,
1415 "y" .= yV ]
1516
17+ toEncoding Coord{..} = series $
18+ "x" .= x <>
19+ "y" .= y
20+
1621-- A FromJSON instance allows us to decode a value from JSON. This
1722-- should match the format used by the ToJSON instance.
1823
examples/aeson-examples.cabalnew file+20
@@ -0,0 +1,20 @@
1+name: aeson-examples
2+version: 0
3+build-type: Simple
4+cabal-version: >=1.8
5+
6+executable aeson-example-generic
7+ main-is: Generic.hs
8+ ghc-options: -Wall
9+ build-depends:
10+ aeson >= 0.10,
11+ base,
12+ bytestring
13+
14+executable aeson-example-simplest
15+ main-is: Simplest.hs
16+ ghc-options: -Wall
17+ build-depends:
18+ aeson >= 0.10,
19+ base,
20+ bytestring