Zna*_*atz 11 haskell ghc type-variables newtype
例如,ParsecT在其定义中有多个类型变量.
newtype ParsecT s u m a
= ParsecT {unParser :: forall b .
State s u
-> (a -> State s u -> ParseError -> m b)
-> (ParseError -> m b)
-> (a -> State s u -> ParseError -> m b)
-> (ParseError -> m b)
-> m b
}
Run Code Online (Sandbox Code Playgroud)
我们可以这样做吗?
newtype ParsecT m a s u -- Only the order of s u m a is changed to m a s u.
= ParsecT {unParser :: forall b .
State s u
-> (a -> State s u -> ParseError -> m b)
-> (ParseError -> m b)
-> (a -> State s u -> ParseError -> m b)
-> (ParseError -> m b)
-> m b
}
Run Code Online (Sandbox Code Playgroud)
我想知道在定义newtype时是否存在关于类型变量顺序的规则或原则.
app*_*ive 16
在这种情况下,a最后因为我们想ParsecT s u m __成为一个monad,这样,我们的解析器寻找的东西可以取决于他们之前发现的东西,依此类推.如果u到了最后我们无法写
instance Monad m => Monad (ParsecT s u m) where ...
Run Code Online (Sandbox Code Playgroud)
m是倒数第二,因为我们想ParsecT s u成为'monad变压器'
class MonadTrans t where
lift :: m a -> t m a
instance MonadTrans (ParsecT s u) where ...
Run Code Online (Sandbox Code Playgroud)
如果我们放第m一个,那么这个实例是不可能的.似乎没有成为的排序任何类似的理由s和u.
| 归档时间: |
|
| 查看次数: |
314 次 |
| 最近记录: |