镜头变焦模糊变量

问题描述 投票:0回答:1

SO是一场狗屎秀。感谢您的搭车。

haskell haskell-lens
1个回答
7
投票

问题是你的新类型只能保持一种状态,即

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)
© www.soinside.com 2019 - 2024. All rights reserved.