Mutable Hastable:实例中的非法类型同义词族应用程序
Mutable Hastable : Illegal type synonym family application in instance
我正在尝试使用此库中的 Mutable BasicHashTable: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 )
编译器抱怨我试图在类型类实例中使用 A
:
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 )
| ^^^^^^^^^^^^
我认为它很奇怪,因为 PrimState
是一个类型家族。试试这个:
import Control.Monad.ST (RealWorld)
import qualified Data.HashTable.ST.Basic as B
type A = B.HashTable Int String RealWorld
你得到的编译错误告诉我们它不能处理类型族。如果您查看哈希 table 类型的定义,您会发现它抱怨的 PrimState
用法:
import qualified Data.HashTable.ST.Basic as B
type BasicHashTable k v = IOHashTable (B.HashTable) k v
type IOHashTable tabletype k v = tabletype (PrimState IO) k v
所以你可以自己直接使用,because:
type instance PrimState IO = RealWorld
事实上。我什至会在上游提交带有修复的 PR:
- type IOHashTable tabletype k v = tabletype (PrimState IO) k v
+ type IOHashTable tabletype k v = tabletype RealWorld k v
因为没有充分的理由按照现在的方式定义它
我正在尝试使用此库中的 Mutable BasicHashTable: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 )
编译器抱怨我试图在类型类实例中使用 A
:
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 )
| ^^^^^^^^^^^^
我认为它很奇怪,因为 PrimState
是一个类型家族。试试这个:
import Control.Monad.ST (RealWorld)
import qualified Data.HashTable.ST.Basic as B
type A = B.HashTable Int String RealWorld
你得到的编译错误告诉我们它不能处理类型族。如果您查看哈希 table 类型的定义,您会发现它抱怨的 PrimState
用法:
import qualified Data.HashTable.ST.Basic as B
type BasicHashTable k v = IOHashTable (B.HashTable) k v
type IOHashTable tabletype k v = tabletype (PrimState IO) k v
所以你可以自己直接使用,because:
type instance PrimState IO = RealWorld
事实上。我什至会在上游提交带有修复的 PR:
- type IOHashTable tabletype k v = tabletype (PrimState IO) k v
+ type IOHashTable tabletype k v = tabletype RealWorld k v
因为没有充分的理由按照现在的方式定义它