Skip to content

Instantly share code, notes, and snippets.

@ondrap
Last active May 3, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondrap/a23a41162c536ea64f35ab677add6259 to your computer and use it in GitHub Desktop.
Save ondrap/a23a41162c536ea64f35ab677add6259 to your computer and use it in GitHub Desktop.
Priklad Haskell JSON
{-# 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)
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