SO是一场狗屎秀。感谢您的搭车。
问题是你的新类型只能保持一种状态,即
GameState
。变焦本质上是将状态更改为镜头目标,但由于 Hearth
不能将 Player
作为状态,因此 zoom (getPlayer handle)
不能与 Hearth
一起使用。
简单的解决方案是将新类型替换为
type Hearth = StateT GameState
并且缩放可以工作。如果您想要一个新类型,您需要将状态参数化,这是一个示例:
import Control.Lens.Internal.Zoom
newtype HearthS s m a = Hearth {
unHearth :: StateT s m a
} deriving (Functor, Applicative, Monad, MonadState s, MonadIO, MonadTrans)
type Hearth = HearthS GameState
type instance Zoomed (HearthS s m) = Focusing m
instance Monad z => Zoom (HearthS s z) (HearthS t z) s t where
zoom l (Hearth m) = Hearth (zoom l m)