I'm trying to use Mutable BasicHashTable from this lib : https://github.com/gregorycollins/hashtables
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import qualified Data.HashTable.IO as H
import Control.Monad.State.Strict
import Control.Monad.IO.Class (MonadIO)
type A = H.BasicHashTable Int String
newtype MyWrapper a = MyWrapper { runM :: StateT A IO a }
deriving (Functor, Applicative, Monad, MonadIO, MonadState A )
The compiler is complaining on my attempts to use A in a typeclass instance:
error:
• Illegal type synonym family application ‘Control.Monad.Primitive.PrimState
IO’ in instance:
MonadState A MyWrapper
• In the newtype declaration for ‘MyWrapper’
|
10 | deriving (Functor, Applicative, Monad, MonadIO, MonadState A )
| ^^^^^^^^^^^^
I think it freaks out because
PrimStateis a type family. Try this:The compilation error you get tells us that it can't handle the type family. If you look at definition of hash table type you'll find the
PrimStateusage it complains about:Therefore you can use it directly yourself, because:
In fact. I'd even submit a PR upstream with a fix:
because there is no good reason to have it defined in the way it is now