wtfunctional/examples/00_dafunc.cpp
Oliver Rümpelein 7657c1a493 First draft of talk:
* Dafunc? concetpually almost ready
 * Started haskell introduction
2016-04-20 12:26:05 +02:00

18 lines
382 B
C++

#include <iostream>
#include <cassert>
using namespace std;
int f(int x) { return ++x;}
int g(int& x) { return ++x;}
int main() {
int x = 2;
/* f is "functional", as it has no side-effects */
f(x);
assert(x==2);
/* g changes a variable of an outer scope,
* i.e. it has a side effect
* Thus, g is not functional!
*/
g(x);
assert(x!=2);
}