I have created a very useful Free Monad out of a sum data type. That abstracts access to a persistent data store:
data DataStoreF next =
Create Asset ( String -> next)
| Read String ( Asset -> next)
| Update Asset ( Bool -> next)
| UpdateAll [Asset] ( Bool -> next)
| Delete Asset ( Bool -> next)
| [...] -- etc. etc.
| Error String
type DataStore = Free DataStoreF
I would like to make DataStore
an instance of MonadError
with the error message handled as (Free (Error str))
:
instance MonadError String DataStore where
throwError str = errorDS str
catchError (Free (ErrorDS str)) f = f str
catchError x _ = x
But I am running into Overlapping Instances errors.
What is the proper way to make the DataStore
monad and instance of MonadError
?