有没有办法自动上下班?
我已经写了一个程序来将
从一对中拉出:
deMaybe :: (a, Maybe b) -> Maybe (a, b)
deMaybe (_, Nothing) = Nothing
deMaybe (x,Just y) = Just (x, y)
我知道也许
是单数,(,)a
是函数(除其他类型)。我想知道我是否缺少一个更高级别的功能,例如:
commute :: (Functor f, Monad m) => f (m a) -> m (f a)
我的问题是:我可以用更通用的类型签名编写 demaybe
,例如假设 colmute
,承认我试图使一个函子通过另一个函子?可以使用诸如 fmap
,>> =
, pure
,& c。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以与 ,但这需要
traverable
。对于t〜(b,)
和m〜也许
,因此起作用:a
traverable
是可以转换的数据结构的类型到具有相同形状的项目。我们需要它来构造一个2键盘(或列表,或类似的东西)。或者我们可以使用 AS @chepner说,这更一般,因为所有
MONAD
s均为appricative
s:s::You can work with
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
, but this requires aTraversable
. Fort ~ (b, )
andm ~ Maybe
, this thus works as:A
Traversable
is a typeclass for data structures that can be transformed to an item with the same shape. We need this to construct thus a 2-tuple (or list, or something similar).or we can use
sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a)
as @chepner says, which is more general since allMonad
s are alsoApplicative
s: