Say I wanted to create a wrapper for UTCTime:
data CustomDateStamp = CustomDateStamp
{
stampValue :: UTCTime
} deriving (Show, Eq, Ord, Typeable)
Now say I wanted to construct a default for that to "now", e.g.
instance Default CustomDateStamp where
def = CustomDateStamp getCurrentTime def
This (obviously) fails with:
• Couldn't match expected type ‘UTCTime’
with actual type ‘IO UTCTime’
• In the first argument of ‘CustomDateStamp’, namely ‘getCurrentTime’
In the expression: CustomDateStamp getCurrentTime def
In an equation for ‘def’: def = CustomDateStamp getCurrentTime def
|
98 | def = CustomDateStamp getCurrentTime def
| ^^^^^^^^^^^^^^
My question is, how can I use sideeffecty operations inside instance definitions? Is this even possible? What's the preferred approach to this sort of situation?