gpt4 book ai didi

haskell - 可变 Hastable : Illegal type synonym family application in instance

转载 作者:行者123 更新时间:2023-12-03 14:36:55 25 4
gpt4 key购买 nike

我正在尝试使用此库中的 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
所以可以自己直接使用, 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
因为没有充分的理由以现在的方式定义它

关于haskell - 可变 Hastable : Illegal type synonym family application in instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66843300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com