If the add function did access z, it would no longer be pure. Notice that the add function does NOT touch the z variable. Add function works equally well for both lists of integers and lists of strings. Notice that the add function does NOT touch the z variable. If the add function did access z, it would no longer be pure.
So the add function looks the same:. Notice that the add function does NOT touch the z variable. Notice that the add function does NOT touch the z variable. 完成后,我们将使用Add函数 返回的promise在console.log中显示一条消息。 Once that is done, we will use the promise returned by the Add function to display a message in the console. log. 因为add函数 只接收到了两个参数中的一个,所以错误的计算结果传入mult5。 Because the add function is only getting 1 of its 2 parameters here then its incorrect results are passed to mult5. 如果add函数 确实访问了变量z,那么它就不再是纯函数了。 If the add function did access z, it would no longer be pure. 如果add函数 使用了一些外部值,那么你永远无法预测它的行为。 If the add function used some outside value, then you couldnever predict its behavior. 在上面的代码,我们分配add函数 ,三个不同的变量,me,you,和someoneElse。 In the code above we assign the add function to three different variables, me, you, and someoneElse. 因为在这里add函数 只接受了两个参数中的一个,然后错误结果再被传入mult5函数,结果也是错的。 Because the add function is only getting 1 of its 2 parameters here then its incorrect results are passed to mult5. 计数器受匿名函数范围的保护,只能使用add函数 进行更改。 The counter is protected by the scope of the anonymous function, and can only be changed using the add function . 现在,你可能想知道在Elm中这个add函数 要如何重写。 At this point, you may be wondering how to rewrite the add function in Elm. 计数器被这个匿名函数的作用域保护,并且只能使用add函数 来修改。 The counter is protected by the scope of the anonymous function, and can only be changed using the add function . If we wanted to, we could write an add function with the following signature:. Now we can add functionality to the Add method:. 看到这里,你可能会想知道在Elm里怎么来改写这个add函数 。 At this point, you may be wondering how to rewrite the add function in Elm. 这个版本的add函数 现在就只接收一个参数,之后再接收另外一个参数。 This version of add is a function that takes one parameter now and then another one later. 现在我们就可以使用这个版本的add 函数来构建一个mult5AfterAdd10函数 的可运行版本:. Now we can use this version of add to build a working version of mult5AfterAdd10 :. The implementation of add function originally looks like:. 如果函数add 确实访问了_z_,该函数将不再是纯函数了。 If the add function did access z, it would no longer be pure. This way add becomes a function . The variable add is assigned the return value of a self-invoking function . The is_letter() function is even simpler:. (int,int)=gt;int的这种标记方法也被称作为add 函数的类型签名。 The notation(int, int)=gt; int is also called the(type) signature of add . 然后我们部分地调用定义好的二元函数add 函数来创建一元函数plus5:. Then we partially call the binary function add to create the unary function plus5:.
Display more examples
Results: 29 ,
Time: 0.0173