evaluation-strategy

Infinite random sequence loops with randomIO but not with getRandom

时光毁灭记忆、已成空白 提交于 2019-12-23 02:38:33
问题 I'm having difficulty trying to figure out a way to reason about why the following two, seemingly equivalent definitions of an infinite random number sequence ( inf and inf' ) are evaluated completely differently: import Control.Monad.Random (Rand, evalRandIO, getRandom) import System.Random (Random, RandomGen, randomIO) inf :: (RandomGen g, Random a) => Rand g [a] inf = sequence (repeat getRandom) inf' :: (Random a) => IO [a] inf' = sequence (repeat randomIO) -- OK main = do i <- evalRandIO

lambda calculus, normal order, normal form,

你离开我真会死。 提交于 2019-12-14 01:04:13
问题 In lambda calculus, if a term has normal form, normal order reduction strategy will always produce it. I just wonder how to prove the above proposition strictly? 回答1: The result you mention is a corollary of the so called standardization theorem, stating that for any reduction sequence M->N there is another "standard" one between the same terms M and N, where you execute redexes in leftmost outermost order. The proof is not so trivial, and there are several different approaches in the

If perl is call-by-reference why does this happen?

只谈情不闲聊 提交于 2019-12-13 07:58:56
问题 I've read that perl uses call-by-reference when executing subrutines. I made a simple piece of code to check this property, but it behaves like if perl was call-by-value: $x=50; $y=70; sub interchange { ($x1, $y1) = @_; $z1 = $x1; $x1 = $y1; $y1 = $z1; print "x1:$x1 y1:$y1\n"; } &interchange ($x, $y); print "x:$x y:$y\n"; This produces the following output: $ perl example.pl x1:70 y1:50 x:50 y:70 If arguments were treated in a call-by-reference way, shouldn't x be equal to x1 and y equal to

Does call-by-sharing and call-by-reference differ only while multithreading?

社会主义新天地 提交于 2019-12-04 08:27:39
If a function is called using Call-by-Reference , then any changes made to the variable inside the function are affected immediately to the caller. And for Call-by-Sharing , it is affected at the end of the function. Question 1: Does Java uses Call-by-Sharing instead of Call-by-Reference ? Question 2: I think that Call-by-Sharing differs from Call-by-Reference only while multithreading. It is created only to decrease concurrent over-writing of values while it is being used in some other thread; to provide consistency. Am I right? I would recommend that you don't use "call by sharing"

Does array changes in method?

馋奶兔 提交于 2019-11-28 10:54:40
When I write like this: public class test { void mainx() { int fyeah[] = {2, 3, 4}; smth(fyeah); System.out.println("x"+fyeah[0]); } void smth(int[] fyeah) { fyeah[0] = 22; } } It prints x22; When I write like this: public class test { void mainx() { int fyeah = 5; smth(fyeah); System.out.println("x"+fyeah); } void smth(int fyeah) { fyeah = 22; } } It doesn't print x22, but prints x5. Why, in the second version function, doesn't the value change? Does it change values only for array elements? The fyeah variable in your first example contains a reference to an array (not an array), while the

Can Scala call by reference?

让人想犯罪 __ 提交于 2019-11-28 07:32:59
I know that Scala supports call-by-name from ALGOL, and I think I understand what that means, but can Scala do call-by-reference like C#, VB.NET, and C++ can? I know that Java cannot do call-by-reference, but I'm unsure if this limitation is solely due to the language or also the JVM. This would be useful when you want to pass an enormous data structure to a method, but you don't want to make a copy of it. Call-by-reference seems perfect in this case. Java and Scala both use call by value exclusively, except that the value is either a primitive or a pointer to an object. If your object

Can Scala call by reference?

跟風遠走 提交于 2019-11-27 05:44:39
问题 I know that Scala supports call-by-name from ALGOL, and I think I understand what that means, but can Scala do call-by-reference like C#, VB.NET, and C++ can? I know that Java cannot do call-by-reference, but I'm unsure if this limitation is solely due to the language or also the JVM. This would be useful when you want to pass an enormous data structure to a method, but you don't want to make a copy of it. Call-by-reference seems perfect in this case. 回答1: Java and Scala both use call by

Does array changes in method?

我们两清 提交于 2019-11-27 03:53:46
问题 When I write like this: public class test { void mainx() { int fyeah[] = {2, 3, 4}; smth(fyeah); System.out.println("x"+fyeah[0]); } void smth(int[] fyeah) { fyeah[0] = 22; } } It prints x22; When I write like this: public class test { void mainx() { int fyeah = 5; smth(fyeah); System.out.println("x"+fyeah); } void smth(int fyeah) { fyeah = 22; } } It doesn't print x22, but prints x5. Why, in the second version function, doesn't the value change? Does it change values only for array elements?