Created
March 20, 2013 08:35
-
-
Save dtchepak/5203180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Referential Transparency (RT), from http://dl.dropbox.com/u/7810909/docs/what-does-fp-mean/index.html | |
Program 1: | |
X x = function(args); | |
R r1 = arbitrary(x); | |
R r2 = arbitrary(x); | |
Program 2: | |
R r1 = arbitrary(function(args)); | |
R r2 = arbitrary(function(args)); | |
If 1 and 2 produce the same outcome then x is RT. | |
*/ | |
Func<string,Action> writeLine = s => () => Console.WriteLine(s); | |
Func<Func<string,Action>,Action> arbitrary = f => f("Hello"); | |
//First case: | |
var x = writeLine; | |
var r1 = arbitrary(x); // r1() will print "Hello" | |
var r2 = arbitrary(x); // r2() will print "Hello" | |
//Second case: | |
var r1 = arbitrary(writeLine); // r1() will print "Hello" | |
var r2 = arbitrary(writeLine); // r1() will print "Hello" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment