在哈斯克尔中等于(=)Vs左箭头(< - )符号

栏目: JavaScript · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/28624408/equal-vs-left-arrow-symbols-in-haskell

工作代码:

import System
main = do
     [file1, file2] <- getArgs
     --copy file contents
     str <- readFile file1
     writeFile file2 str

崩溃代码:

import System
main = do
       [file1, file2] = getArgs
       str = readFile file1
       writeFile file2 str

当我尝试,它抛出一个错误:

a.hs:6:18: parse error on input ‘=’

那么<- from =

要了解真正的区别,你必须了解僧侣在他们的答案中描述的monads,以及亵渎的描述.

对于IO monad的具体情况,与您的getArgs示例一样,粗略但有用的直觉可以如下进行:

> x<- 操作运行IO操作,获取其结果,并将其绑定到x

> let x = action定义x等于action,但不运行任何东西.稍后,您可以使用y<- x表示y - - 动作.

来自允许关闭的命令式语言的 程序员 可能会用Javascript进行粗略的并行比较:

var action = function() { print(3); return 5; }

// roughly equivalent to x <- action
print('test 1')
var x = action()  // output:3
// x is 5

// roughly equivalent to let y = action
print('test 2')
var y = action    // output: nothing
// y is a function

// roughly equivalent to z <- y
print('test 3')
var z = y()       // output:3
// z is 5

再次:这个比较只关注于IO.对于其他monads,您需要检查>> =实际上是什么,并考虑对do的否定.

http://stackoverflow.com/questions/28624408/equal-vs-left-arrow-symbols-in-haskell


以上所述就是小编给大家介绍的《在哈斯克尔中等于(=)Vs左箭头(< - )符号》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

交互设计

交互设计

. / 刘晓晖、张景 / 电子工业出版社 / 2003-6 / 39.00元

一起来看看 《交互设计》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具