Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created March 20, 2013 08:35
Show Gist options
  • Save dtchepak/5203180 to your computer and use it in GitHub Desktop.
Save dtchepak/5203180 to your computer and use it in GitHub Desktop.
/* 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