Skip to content

Commit 3aebbc7

Browse files
committed
Update example with accumulating errors
1 parent b1099ec commit 3aebbc7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

examples/Simplest.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Prelude.Compat
88

99
import Control.Applicative (empty)
1010
import Data.Aeson
11+
import Data.Aeson.Types
1112
import Data.Monoid
1213
import qualified Data.ByteString.Lazy.Char8 as BL
1314

@@ -28,9 +29,9 @@ instance ToJSON Coord where
2829
-- should match the format used by the ToJSON instance.
2930

3031
instance FromJSON Coord where
31-
parseJSON (Object v) = Coord <$>
32-
v .: "x" <*>
33-
v .: "y"
32+
parseJSON (Object v) = liftP2 Coord
33+
(v .: "x")
34+
(v .: "y")
3435
parseJSON _ = empty
3536

3637
main :: IO ()
@@ -39,3 +40,6 @@ main = do
3940
print req
4041
let reply = Coord 123.4 20
4142
BL.putStrLn (encode reply)
43+
let asCoord :: f Coord -> f Coord
44+
asCoord = id
45+
print (asCoord (verboseDecode "{}"))

0 commit comments

Comments
 (0)