Last active
May 3, 2016 12:47
-
-
Save ondrap/a23a41162c536ea64f35ab677add6259 to your computer and use it in GitHub Desktop.
Priklad Haskell JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE DeriveAnyClass #-} | |
import Data.Aeson | |
import GHC.Generics | |
data Message = Message { uuid :: Int, content :: Int } | |
deriving (Generic, FromJSON) | |
exampleFunction :: Int -> Int -> IO () | |
exampleFunction uuid msg = print (uuid, msg) | |
main :: IO () | |
main = do | |
let jsdata = "{\"uuid\":10, \"content\":20}" | |
case eitherDecode jsdata of | |
Left err -> error err | |
Right msg -> exampleFunction (uuid msg) (content msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tst | |
version: 0.1.0.0 | |
license-file: LICENSE | |
author: XXX | |
maintainer: YYY | |
build-type: Simple | |
cabal-version: >=1.10 | |
executable tst | |
main-is: Main.hs | |
build-depends: base, aeson | |
default-language: Haskell2010 | |
ghc-options: -Wall -fwarn-incomplete-uni-patterns | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment