我如何在Haskell中为这样的数据类型定义monad?它基本上是萨尔萨语翻译.我无法弄清楚回报应该是什么样的.这让我发疯了......
newtype Salsa a = Salsa {
runSalsa :: Context -> Either String (a, Context, Animation)}
instance Monad Salsa where
return a = Salsa $ ..........
instance Functor Salsa where
fmap = liftM
instance Applicative Salsa where
pure = return
(<*>) = ap
Run Code Online (Sandbox Code Playgroud)
http://ap-e2015.onlineta.org/assignments/assignment-1-salsa-interpreter.html
你需要一个Context使用lambda 的函数\con ->.
到目前为止,你没有任何失败的东西,所以你总能成功.Right.
a是通过电话提供的return.(a,.
Context是通过对lambda的调用提供的.con,.
现在你必须决定要包含的动画,我猜不会.[]).(注意我不记得那里的确切语法,但我认为这是正确的).
总而言之,你得到:
return a = Salsa $ \con -> Right (a, con, [])
Run Code Online (Sandbox Code Playgroud)
现在出现了一个复杂的情况,你必须处理bind(>>=).
| 归档时间: |
|
| 查看次数: |
176 次 |
| 最近记录: |