haskell 错误:应为类型,但“SOMETHING”具有种类“SomeMyKind”

nx7onnlm  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(118)

在这段代码(片段)中,我得到一个错误:

• 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中修复了该问题。

5t7ly7z5

5t7ly7z51#

为了能够写入toCache @'ResourcesM ...toCache的类型类必须具有Msg类型的类型参数,如果要添加它:

class Cached (m::Msg) a where   -- HERE, the m
  fromCache :: Maybe UTCTime -> IPv4 -> a -> Cache -> Hit (AnsTo a)
  toCache :: UTCTime -> IPv4 -> a -> AnsTo a -> Cache -> Cache

一切正常,现在类型“参数”m在类的作用域中被“声明”,并且可以用类型应用程序@'SOMETHING传递

相关问题