相关疑难解决方法(0)

如何解释函数实例的bind/>> =?

我试图通过在Javascript中实现他们的函数实例来提高我对Applicatives和Monads的理解.我对Haskell的了解有限,我希望我的问题有道理.

下面是我的实现fmap,<*>以及>>=Functor,ApplicativeMonad在Javascript类型类:

const fmap = f => g => x => f(g(x)); // B combinator
const apply = f => g => x => f(x) (g(x)); // S combinator
const bind = f => g => x => g(f(x)) (x); // ?
Run Code Online (Sandbox Code Playgroud)

我不确定bindHaskell实现的正确翻译是否正确:

(>>=)  :: (r -> a) -> (a -> (r -> b)) -> r -> b

instance Monad ((->) r) …
Run Code Online (Sandbox Code Playgroud)

monads haskell functional-programming applicative

7
推荐指数
2
解决办法
235
查看次数