functional programming & c++

Post on 18-Feb-2017

204 Views

Category:

Software

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Functional Programming

2016/3

C++

y = cos x/3

Functional?

Differences from Imperative

in C++

Agenda

Functional?

declarative code

higher-order function

static binding

lazy evaluation

Functional Programming is

C/C++ (Imperative)

Declarative code

std::function(), , , callback ,

DI, etc.

Higher-order function

Static binding

(eager evaluation)

C/C++

Lazy evaluation

PROS!

IO

CONS"

That is…

C/C++

Imperative vs. Functional

C++ Haskell

Imperative vs. Functional

https://msdn.microsoft.com/ja-jp/library/bb669144.aspx

Programming Paradigms

http://docs.python.jp/3/howto/functional.html

Imperative vs. Functional

Imperative & Functional

C++Haskell

💎💎

💎

💎 💎

💎

💎

Training in FP, with C++

Immutable

const / const&

const

const (mutating)

Immutable

FP

UI In/Out

FP

Immutable

lambda

API

vector<int> function_name([xxx,] vector<int> &array);

result = filter_prime(sort(take3(array)));

vector<int> function_name([xxx,] vector<int> &array);

result = take3(filter_prime(sort(array)));

OK

Program is …

disposable code

long life code

immutable

immutable

mutable

Recap

C/C++

Recap

Try! FP

top related