|
|
Line 985: |
Line 985: |
|
yellow lab, not trained |
|
yellow lab, not trained |
|
trained collie, but doesn't catch frisbee</pre> |
|
trained collie, but doesn't catch frisbee</pre> |
|
|
|
⚫ |
|
|
|
|
|
⚫ |
Example uses [https://hackage.haskell.org/package/binary <tt>binary</tt>] package. Since Haskell doesn't directly support OO-style inheritance, we use a sum type instead: |
|
|
|
|
⚫ |
<lang haskell>{-# LANGUAGE DeriveGeneric #-} |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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) |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
| IndividualContributor String String |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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])</lang> |
|
|
|
|
|
|
=={{header|Groovy}}== |
|
=={{header|Groovy}}== |
Line 1,073: |
Line 1,043: |
|
[lists, are, serializable] |
|
[lists, are, serializable] |
|
Schroeder</pre> |
|
Schroeder</pre> |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
Example uses [https://hackage.haskell.org/package/binary <tt>binary</tt>] package. Since Haskell doesn't directly support OO-style inheritance, we use a sum type instead: |
|
|
|
|
⚫ |
<lang haskell>{-# LANGUAGE DeriveGeneric #-} |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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) |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
| IndividualContributor String String |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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])</lang> |
|
|
|
|
|
=={{header|J}}== |
|
=={{header|J}}== |