在这段代码(片段)中,我得到一个错误:
• Expected a type, but ‘'ResourcesM’ has kind ‘Msg’
• In the type ‘'ResourcesM’
In the expression:
toCache
@'ResourcesM undefined undefined (AnyMsgPkt GetResourcesMP)
undefined
In an equation for ‘fff’:
fff
= toCache
......................
代码:
data MsgPkt (m::Msg) (d::MsgDir) where
GetResourcesMP :: MsgPkt 'ResourcesM 'AskMD
MyResourcesMP :: MyResources -> MsgPkt 'ResourcesM 'AnsMD
......
data AnyMsgPkt (d::MsgDir) = forall (m::Msg). AnyMsgPkt (MsgPkt m d)
.........
class ConcrMsg (m::Msg) (d::MsgDir) where concrMsg :: AnyMsgPkt d -> Maybe (MsgPkt m d)
instance ConcrMsg 'ResourcesM d where
concrMsg (AnyMsgPkt a@GetResourcesMP{}) = Just a
concrMsg (AnyMsgPkt a@MyResourcesMP{}) = Just a
concrMsg _ = Nothing
..........
class Cached (m::Msg) a where
fromCache :: Maybe UTCTime -> IPv4 -> a -> Cache -> Hit (AnsTo a)
toCache :: UTCTime -> IPv4 -> a -> AnsTo a -> Cache -> Cache
instance forall (m::Msg).
(ConcrMsg m 'AnsMD, Cacheable (MsgPkt m 'AskMD) ~ 'Yes)
=> Cached (AnyMsgPkt 'AskMD) where
fromCache mbExpir ip v cst = do
Val valExpir dat <- M.lookup (Key ip 0 $ hash v) cst
expir <- mbExpir
False <- pure (valExpir < expir)
_ <- concrMsg @m dat
pure dat
toCache expir ip v ans cst = M.insert (Key ip 0 $ hash v) (Val expir ans) cst
fff = toCache @'ResourcesM undefined undefined (AnyMsgPkt GetResourcesMP) undefined
我试过toCache @ResourcesM ....
(从我的Angular 看是错误的)。但是错误是一样的。如何修复它?
编辑1
将参数(m::Msg)
添加到类Cached
中修复了该问题。
1条答案
按热度按时间5t7ly7z51#
为了能够写入
toCache @'ResourcesM ...
,toCache
的类型类必须具有Msg
类型的类型参数,如果要添加它:一切正常,现在类型“参数”
m
在类的作用域中被“声明”,并且可以用类型应用程序@'SOMETHING
传递