F#中的Omega Monad [英] Omega Monad in F#
问题描述
我可以在F#中实现类似于Haskell的Omega monad吗?
Can I implement something similar to Omega monad from Haskell in F#?
http://hackage.haskell.org/package /control-monad-omega-0.3/docs/Control-Monad-Omega.html
推荐答案
是的,翻译应该很简单.欧米茄类型成为一种ADT
Yes, and it should be fairly simple to do the translation. The Omega type becomes an ADT of one type
型=列表<'a>
type Omega<'a> = RunOmega of list<'a>
和对角线只是列表上模式匹配的组合.可以直接进入Omega.bind(Haskell>> =,但在这里写为Option.bind的等效项).将其包装为计算表达式与将其相同
and diagonal is just a combination of pattern matching on lists. That gets you to Omega.bind (Haskell >>=, but here written as the equivalent of Option.bind) quite directly; wrapping it up as a computation expression is just the same as it would be for Option.
这篇关于F#中的Omega Monad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!