如何解决一词多义未检测到成员
我正试图在单个多义的Sem
Monad中用Hspec编写一堆语句,如下所示:
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module StorageSpec (main,spec) where
import Test.Hspec
import Storage
import Data.Aeson
import Data.Maybe(fromJust)
import qualified Data.Text as T
import qualified Database.Bloodhound as B
import qualified Database.Bloodhound.Types as B
import GHC.Generics
import Polysemy (Embed,Member,Sem,makeSem,embed,interpret,reinterpret)
import Polysemy.IO
import Polysemy.State
data Storage (d :: *) (m :: * -> *) (a :: *) where
CreateContainer :: B.IndexName -> B.IndexSettings -> Storage d m Bool
makeSem ''Storage
scenarii :: Member (Storage Book) r => Sem r (SpecWith ())
scenarii = do
indexCreation <- it "create index should work the first time" . flip shouldBe True
<$> (createContainer exampleIndex exampleMapping :: Member (Storage Book) r => Sem r Bool)
return $ indexCreation
data Book = Book { name :: String,entries :: Int } deriving (Eq,Show,Generic,FromJSON,ToJSON)
在明确指定Storage Book
Member
时,出现以下错误:
• Ambiguous use of effect 'Storage'
Possible fix:
add (Member (Storage d1) r1) to the context of
the type signature
If you already have the constraint you want,instead
add a type application to specify
'd1' directly,or activate polysemy-plugin which
can usually infer the type correctly.
• In the second argument of ‘(<$>)’,namely
‘(createContainer exampleIndex exampleMapping ::
Member (Storage Book) r => Sem r Bool)’
In a stmt of a 'do' block:
indexCreation <- it "create index should work the first time"
. flip shouldBe True
<$>
(createContainer exampleIndex exampleMapping ::
Member (Storage Book) r => Sem r Bool)
In the expression:
do indexCreation <- it "create index should work the first time"
. flip shouldBe True
<$>
(createContainer exampleIndex exampleMapping ::
Member (Storage Book) r => Sem r Bool)
return $ indexCreation
|
39 | <$> (createContainer exampleIndex exampleMapping :: Member (Storage Book) r => Sem r Bool)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我看不出有什么办法可以帮助类型检查器。
解决方法
在d
的情况下,发生CreateContainer
用作幻影类型的情况,为了解决该问题,我不得不使用type application:
createContainer @Book exampleIndex exampleMapping
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。