作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
许多限制似乎汇集在一起。让我们把这些抽象出来。
type MonadNumState a m = (MonadState a m, Num a)
MonadNumState
只是一个约束的同义词,所以我在每次使用时都能获得函数依赖的好处,并且可以轻松抛出
MonadNumState a m
进入一个上下文。现在,假设我希望将其抽象为一个约束族:
class Iterator t where
type MonadIter t a m :: Constraint
next :: (MonadIter t a m) => m t
...
instance Iterator Foo where
type MonadIter Foo a m = (MonadState a m, Num a)
...
instance Iterator Bar where
type MonadIter Bar a m = (MonadRandom m, MonadSplit a m, RandomGen a)
...
a
不是功能依赖。
next
从
a
开始几乎无法使用无法推断。我能做些什么?好吧,我当然可以使用类型族来代替。
MonadState
是使用fundeps编写的,但是将fundeps转换为类型族应该很容易。
instance (MonadState s m) => MonadStateFamily m where
type St m = s
get' = get
...
instance (MonadStateFamily m) => MonadState (St m) m where
get = get'
...
Foo.hs:25:3:
The RHS of an associated type declaration mentions type variable `s'
All such variables must be bound on the LHS
s
.如果没有明确的字典传递,我还没有找到任何方法来做到这一点。
最佳答案
您可以考虑使用独立类型族而不是关联类型
type family StateType (m:: * -> *)
class MonadStateFamily m where
get' :: m (StateType m)
instance (MonadState s m, s ~ StateType m) => MonadStateFamily m where
get' = get
type instance StateType (State s) = s
getState :: State s s
getState = get'
关于haskell - 约束家庭的基金,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16960219/
我已经标记了 PickerViews 1 和 2,但我在 func titleForRow 上收到“不会被执行”的消息,我该如何解决这个问题? @IBOutlet weak var shoeDetai
我是一名优秀的程序员,十分优秀!