Welcome to Erlang

Post on 06-Aug-2015

111 views 0 download

transcript

Welcome to Erlang

cystbearErlanger

Symfony expert

MongoDB adept

OSS doerhttps://twitter.com/1cdecoderhttps://github.com/cystbearhttp://trinity.ck.ua/

HOTCODE 2013

https://twitter.com/5hthttps://synrc.com/

Maxim Sokhatskiy

Time to change something

History

Specific use cases

Non OOP paradigm

Naive syntax

No so big community

Lack of libs

Pros / Cons

https://www.erlang-solutions.com/https://synrc.com/https://github.com/tapstershttps://github.com/erlangbureau

Low level thinking!FunctionalFastRobustExpressive syntaxEndless running appsUpdate code on a flyOwn SchedulerProcesses based architectureSupervisor treeNo shared memory

Pros / Cons

Hey, did you heard about FP?

High order functions

Lambda functions

Separation data and functions

Immutable

Lazy

Tail recursion

Algebraic data types

Pattern matching

Functional

https://twitter.com/nikitonskyhttp://tonsky.me/talks/2015-frontendconf/http://tonsky.me/talks/2015-codefest/

Performance

http://slides.com/maximsokhatsky/n2o

Scheduler

http://habrahabr.ru/post/128772/http://habrahabr.ru/post/260065/

Basics

Integer 42 Float 4.2 aka doubleAtom okBinary <<"Erlang-powa">>

Reference #Ref<0.0.0.29>Pid <0.0.42>Port #Port<0.42>Fun #Fun<erl_eval.6.82930912>

Basics2

List [<<42,1,0,90>>, 1, ok]

Tuple {<0.0.16>, 107, 42, ["madness", true]}

we can force lists type and typify turplesnamed tuples =:= records

Example

-module(fib).

-export([fib/1, tail_fib/1]).

fib(0) -> 0;

fib(1) -> 1;

fib(N) -> fib(N - 1) + fib(N - 2).

Example

tail_fib(N)-> tail_fib(N, 0, 0, 0).

tail_fib(N, Acc, Prev, PrevPrev) ->

case Acc of

N -> Prev + PrevPrev;

0 -> tail_fib(N, Acc + 1, 0, 0);

1 -> tail_fib(N, Acc + 1, 1, 0);

_ -> tail_fib(N, Acc + 1, Prev + PrevPrev, Prev)

end.

Example QuickSort

qsort([]) -> [];

qsort([X|Xs]) ->

qsort([Y || Y<-Xs, Y <= X]) ++ [X] ++ qsort([Y || Y<-Xs, Y > X]).

Application Examples

Web SitesRest ServicesVideo StreamingChats

RabbitMQRiak, CouchDB, Hibari, KAI, LeoFS, MnesiaejabberdCowboyWings 3D

PrivatBankGithub Pages / Gist

Future

Functional Thursday