In this code (snippet) I get an error:
• 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
......................
the code:
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
I tried toCache @ResourcesM....
(which is wrong from my point of view). but the error is same. How to fix it?
EDIT 1
Adding to a parameter (m::Msg)
to the class Cached
fixed the problem.
To be able to write toCache @'ResourcesM...
the type class of the toCache
must have a type parameter of a kind Msg
, if to add it:
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
everything becomes OK, now type "argument" m
is "declared" in the scope of the class and can be passed with type application @'SOMETHING
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.