June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
25
Task/Object-serialization/Haskell/object-serialization.hs
Normal file
25
Task/Object-serialization/Haskell/object-serialization.hs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import qualified Data.ByteString.Lazy as ByteString (readFile, writeFile)
|
||||
import Data.Binary (Binary)
|
||||
import qualified Data.Binary as Binary (decode, encode)
|
||||
import GHC.Generics (Generic)
|
||||
|
||||
data Employee =
|
||||
Manager String String
|
||||
| IndividualContributor String String
|
||||
deriving (Generic, Show)
|
||||
instance Binary Employee
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
ByteString.writeFile "objects.dat" $ Binary.encode
|
||||
[ IndividualContributor "John Doe" "Sales"
|
||||
, Manager "Jane Doe" "Engineering"
|
||||
]
|
||||
|
||||
bytes <- ByteString.readFile "objects.dat"
|
||||
let employees = Binary.decode bytes
|
||||
print (employees :: [Employee])
|
||||
Loading…
Add table
Add a link
Reference in a new issue