Create a set of data types based upon inheritance. Each data type or class should have a print command that displays the contents of an instance of that class to standard output. Create instances of each class in your inheritance hierarchy and display them to standard output. Write each of the objects to a file named objects.dat in binary form using serialization or marshalling. Read the file objects.dat and print the contents of each serialized object.

{-# 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])