First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
commit
1e05ecd7ee
781 changed files with 9080 additions and 0 deletions
24
Task/JSON/Haskell/json.hs
Normal file
24
Task/JSON/Haskell/json.hs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Attoparsec (parseOnly)
|
||||
import Data.Text
|
||||
import qualified Data.ByteString.Lazy.Char8 as B
|
||||
import qualified Data.ByteString.Char8 as S
|
||||
|
||||
testdoc = object [
|
||||
"foo" .= (1 :: Int),
|
||||
"bar" .= ([1.3, 1.6, 1.9] :: [Double]),
|
||||
"baz" .= ("some string" :: Text),
|
||||
"other" .= object [
|
||||
"yes" .= ("sir" :: Text)
|
||||
]
|
||||
]
|
||||
|
||||
main = do
|
||||
let out = encode testdoc
|
||||
B.putStrLn out
|
||||
case parseOnly json (S.concat $ B.toChunks out) of
|
||||
Left e -> error $ "strange error re-parsing json: " ++ (show e)
|
||||
Right v | v /= testdoc -> error "documents not equal!"
|
||||
Right v | otherwise -> print v
|
||||
Loading…
Add table
Add a link
Reference in a new issue