I'd like to be able to serialize CommandRecord
into binary to be able to save it to a file. However my naive approach of just doing:
instance Binary CommandRecord
does not work due the below error*.
What approach can I use to achieve the above? Right now my thinking would be to work around this issue by, abandoning the idea of using the thyme
library and it's UTCTime
and instead use time
library and it's UTCTime
(which has a Binary instance already defined).
I have the follow data type:
data CommandRecord = CommandRecord {
command :: Text
, timedate :: UTCTime
, path :: Text
} deriving Generic
I have the following imports:
import Data.Thyme.Clock
import Data.Binary
import Data.Binary.Orphans
I'm using the following packages:
- binary
- binary-orphans
- thyme
Error*:
/home/chris/Projects/Haskell/MoscoviumOrange/src/Main.hs:28:10-
29: error:
• No instance for (Binary UTCTime)
arising from a use of ‘binary-0.8.5.1:Data.Binary.Class
.$dmput’
There are instances for similar types:
instance Binary
time-1.8.0.2:Data.Time.Clock.Internal.UTCTim
e.UTCTime
-- Defined in ‘Data.Binary.Orphans’
• In the expression:
binary-0.8.5.1:Data.Binary.Class.$dmput @CommandRecord
In an equation for ‘put’:
put = binary-0.8.5.1:Data.Binary.Class.$dmput
@CommandRecord
In the instance declaration for ‘Binary CommandRecord’
|
28 | instance Binary CommandRecord
| ^^^^^^^^^^^^^^^^^^^^
/home/chris/Projects/Haskell/MoscoviumOrange/src/Main.hs:28:10-
29: error:
• No instance for (Binary UTCTime)
arising from a use of ‘binary-0.8.5.1:Data.Binary.Class
.$dmget’
There are instances for similar types:
instance Binary
time-1.8.0.2:Data.Time.Clock.Internal.UTCTim
e.UTCTime
-- Defined in ‘Data.Binary.Orphans’
• In the expression:
binary-0.8.5.1:Data.Binary.Class.$dmget @CommandRecord
In an equation for ‘get’:
get = binary-0.8.5.1:Data.Binary.Class.$dmget
@CommandRecord
In the instance declaration for ‘Binary CommandRecord’
|
28 | instance Binary CommandRecord
| ^^^^^^^^^^^^^^^^^^^^