In one module, I define a class:
class Monad m => MonadTime m where
currentTime :: m UTCTime
The MonadTime is exported.
In the different module, I wanted to create an instance:
-- MonadTime is imported
instance MonadTime IO where
currentTime :: IO UTCTime
currentTime = Data.Time.Clock.getCurrentTime
However, the issue is:
‘currentTime’ is not a (visible) method of class ‘MonadTime’
If I move the instance to the first module, where class is defined, everything works. But my idea was to provide the implementation in main module.
How should I resolve this?
>Solution :
You need to export it with the method, so:
module MyModule(MonadTime(currentTime)) where
class Monad m => MonadTime m where
currentTime :: m UTCTime
and in the other module:
module MyOtherModule where
import MyModule(MonadTime(currentTime))
instance MonadTime IO where
currentTime :: IO UTCTime
currentTime = Data.Time.Clock.getCurrentTime