Class
拥有(* -> *) -> Constraint
种类?我有以下代码:
{-# LANGUAGE ConstraintKinds, TypeFamilies, RankNTypes, MultiParamTypeClasses #-}
class MonadTrans t where
type Class t
lift :: (Monad m) => m b -> t m b
generalize :: (Monad m) => t m a -> (forall m'. (Class t m') => m a)
class (Monad m) => MaybeC m where
fart :: m a
data MaybeT m a = NothingT | JustT (m a)
instance (Monad m) => Monad (MaybeT m) where
return = JustT . return
(JustT a) >>= f = a >>= f
NothingT >>= f = NothingT
instance (Monad m) => MaybeC (MaybeT m) where
fart = NothingT
instance MonadTrans MaybeT where
type Class Maybe = MaybeC --Error Is HERE
lift = JustT
generalize NothingT = fart
generalize JustT a = return a
编译器说:" Expected kind '* -> Constraint', but
MaybeC&#39;善良(* -> *) -> Constraint'</code>
&#34;但是Class
是(*->*)->Constraint
。
然后我尝试了:
{-# LANGUAGE ConstraintKinds, TypeFamilies, RankNTypes, MultiParamTypeClasses #-}
class MonadTrans t where
type Class t :: (*->*)->Constraint
lift :: (Monad m) => m b -> t m b
generalize :: (Monad m) => t m a -> (forall m'. (Class t m') => m a)
class (Monad m) => MaybeC m where
fart :: m a
data MaybeT m a = NothingT | JustT (m a)
instance (Monad m) => Monad (MaybeT m) where
return = JustT . return
(JustT a) >>= f = a >>= f
NothingT >>= f = NothingT
instance (Monad m) => MaybeC (MaybeT m) where
fart = NothingT
instance MonadTrans MaybeT where
type Class Maybe = MaybeC
lift = JustT
generalize NothingT = fart
generalize JustT a = return a
但是编译器说&#34; pad1.hs:4:37: Not in scope: type constructor or class 'Constraint'
&#34;,所以ConstraintKinds
对我没有任何作用。