haskell - Mutable Hastable:实例中的非法类型同义词系列应用程序
问题描述
我正在尝试使用此库中的 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
你得到的编译错误告诉我们它不能处理类型族。如果您查看哈希表类型的定义,您会发现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
因此您可以自己直接使用它,因为:
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
因为没有充分的理由以现在的方式定义它
推荐阅读
- php - 根据循环遍历的每个数组中的值,在 php 中的 Foreach 数组中分配不同的值
- python - TypeError:列表索引必须是整数或切片,而不是使用字典时的str
- python - 使用 URL 检查推文是否存在于 Python 中
- javascript - 为什么我在移动设备和平板电脑上的着色器出现错误?
- python - 如何打印班级中的最高值?
- c++ - pow(复杂
, 2) - python - 如何在电子邮件正文中插入与每个用户一样多的链接?
- node.js - 错误:.hasMany 调用的东西不是 Sequelize.Model 的子类
- excel - 将范围从一个工作簿复制到另一个工作簿(替代复制粘贴)
- .net - 如何通过授权在 IIS 重写中添加 cors 设置?