据我所知,Haskell中的do块只是一元绑定运算符的某种语法糖。例如,人们可以转换
main = do f <- readFile "foo.txt"
print f
print "Finished"
至
main = readFile "foo.txt" >>= print >> print "Finished"
所有do块都能转换成绑定语法吗?例如,在这个块中多次使用f如何:
main = do f <- readFile "foo.txt&
如何访问D3回调中的当前选择?
group.selectAll('.text')
.data(data)
.enter()
.append('text')
.text((d) => d)
.attr('class', 'tick')
.attr('y', (d) => {
// console.log(this) <-- this gives me window :( but I want the current selection or
在我学习箭头的过程中,我无意中发现了一个随着时间而变得不清晰的点:
从John的论文“把Monads推广到arrow”中,我注意到下面(例一)是不可能的,因为箭头 f in参数不能在箭头过程的本地范围内使用。
-- case I
proc (f,x) -> returnA <- f -< x --- here the f is illegal
如果我们在其他地方定义了另一个箭头otherArrow,我们可以这样做:
-- case II
proc (f,x) -> returnA <- otherArrow -< x
我理解对-<的需求,
我正在尝试用解析一个XML文件。在下面的代码中,我需要使用从外部标记中的属性获得的额外参数来解析内部元素。但是i在第二行不可用(第二个箭头?)。如何将i传递给getTerminal
getSentence = atTag "s" >>>
proc x -> do
i <- getAttrValue "id" -< x
ts <- listA (getTerminal i) <<< atTag "terminals" -< x
returnA
我希望将函数isLoggedIn传递给子组件HandleArticle作为支柱。即使由于this问题,我使用箭头函数,TypeError: this.isLoggedIn is not a function也会出现。
class HandleNews extends React.Component {
isLoggedIn = () => {
if (!this.props.isSignedIn) {
history.push("/");
} else {
return <div>hello</div>;
我在1.1.0版(快照)上使用Eclipse和Tern IDE für ES6支持。我得到了箭头函数和const-导出的验证错误,如这个屏幕截图所示:
我研究了这些描述,但错误不会消失:
不过,我不知道Tern插件真正支持什么,但是根据的文档,Tern应该支持自0.14以来的箭头函数。然而,github上的IDE页面只提到了类、导入和承诺支持(在我看来,支持ES6的插件超出了基本支持)。
是否有人正在使用Eclipse开发ES6,并提供(或多或少)全功能支持?我有点像独角兽..。