繁体   English   中英

错误:需要一个类型,但“SOMETHING 有一种 'SomeMyKind'

[英]Error: Expected a type, but 'SOMETHING has kind ‘SomeMyKind’

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

• 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.... (从我的角度来看这是错误的)。 但错误是一样的。 如何解决?

编辑 1

将参数(m::Msg)添加到 class Cached解决了该问题。

为了能够写入toCache @'ResourcesM... toCache 的类型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

一切正常,现在在 class 的 scope 中键入“参数” m被“声明”,并且可以使用类型 application @'SOMETHING传递

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM