Source

{-# LANGUAGE OverloadedStrings #-}importControl.Applicative((<$>),(<*>),empty)importData.AesonimportqualifiedData.ByteString.Lazy.Char8asBLdataCoord=Coord{x::Double,y::Double}deriving(Show)-- A ToJSON instance allows us to encode a value as JSON.instanceToJSONCoordwheretoJSON(CoordxVyV)=object["x".=xV,"y".=yV]-- A FromJSON instance allows us to decode a value from JSON. This-- should match the format used by the ToJSON instance.instanceFromJSONCoordwhereparseJSON(Objectv)=Coord<$>v.:"x"<*>v.:"y"parseJSON_=emptymain::IO()main=doletreq=decode"{\"x\":3.0,\"y\":-1.0}"::MaybeCoordprintreqletreply=Coord123.420BL.putStrLn(encodereply)