Presentation is loading. Please wait.

Presentation is loading. Please wait.

Industrial Use of a Functional Language

Similar presentations


Presentation on theme: "Industrial Use of a Functional Language"— Presentation transcript:

1 Industrial Use of a Functional Language
Thomas Arts Industrial Use of a Functional Language Thomas Arts Ericsson Computer Science Laboratory Stockholm, Sweden

2 Switches, routers, base-stations Networks Mobile telephones
Thomas Arts Telecom industry Switches, routers, base-stations Networks Mobile telephones

3 Computer Science Laboratory
Thomas Arts Computer Science Laboratory Founded 1983 Research on implementation tools, methods and techniques for telecommunication applications Intermediate between universities and Ericsson product units

4 Telecom requirements Requirements of telecom software Concurrency
Thomas Arts Telecom requirements Requirements of telecom software Concurrency Distribution Soft real-time Robust Non-stop system External interfaces

5 Thomas Arts A good language? Experiments in the 80s with Ada, C, ML, CML, Prolog... large programs (million lines) change code in running system fast message passing low memory overhead no memory fragmentation/leaks recover from errors

6 Thomas Arts Erlang/OTP A functional language successfully used for programming large real-time control systems. OTP is the set of libraries that is used with Erlang for product development

7 Erlang/OTP www.erlang.org Erlang/OTP develop/maintenance
Thomas Arts Erlang/OTP Erlang/OTP develop/maintenance Erlang consultancy & courses Erlang used many systems, e.g. ATM switch and new GSM network (GPRS) Erlang Open Source

8 Erlang sequential program
Thomas Arts Erlang sequential program -module(math). -export([fac/1]). fac(N) when N>0 -> N*fac(N-1); fac(N)-> 1.

9 Erlang datatypes atoms (true,foo,’Hello’) numbers (1212864187154)
Thomas Arts Erlang datatypes atoms (true,foo,’Hello’) numbers ( ) floats ( ) tuples ({a,123}) lists ([1,123,2,56]) process identifiers ...

10 dynamically typed language poor mechanism to build your own datatypes
Thomas Arts Erlang datatypes dynamically typed language poor mechanism to build your own datatypes

11 Erlang control structures
Thomas Arts Erlang control structures Matching case X of {ok,List} -> hd(List); {resend,Data} -> submit; error -> exit(error); _ -> retry(X) end

12 Erlang control structures
Thomas Arts Erlang control structures Guards f(....) when guard -> ... If f(X) -> if guard1 -> ...; guard2 -> ... end

13 Erlang control structures
Thomas Arts Erlang control structures Higher order functions f(F,X) -> F(X); map(F,[1,2,3,4]). List comprehensions [ X || {X,Y}<-Set, guard(X)]

14 Erlang control structures
Thomas Arts Erlang control structures Naming of objects/data f(X) -> Dev = update_device(X), {Date,Time} = now(), h({Dev,Date}).

15 Erlang control structures
Thomas Arts Erlang control structures Sequence f(X) -> action1(X), action2(X); update(X) -> log(X,”myfile”), new(X). side-effects

16 Erlang control - concurrency/distribution
Thomas Arts Erlang control - concurrency/distribution Creating a process Pid = spawn(F,[Arg1,...,ArgN]); B = spawn(F,Args); P2 P1 P2 F(Arg1,...,ArgN)

17 Erlang control - concurrency/distribution
Thomas Arts Erlang control - concurrency/distribution Sending messages Pid ! Message; B!{self(),hej}; {P1,hej} P1 P2 {P1,hej}

18 Erlang control - concurrency/distribution
Thomas Arts Erlang control - concurrency/distribution Receiving messages receive Pattern -> ...; end; Distrubution has same communication mechanism Hence, concurrency or distribution is transparant for user P1 P2 {P1,hej} receive {From,Msg} -> From ! {ok,Msg} end P1 ! {ok,hej}

19 Erlang changing code in running system
Thomas Arts Erlang changing code in running system P0 loop(F) -> receive {change,G} -> loop(G); {exec,Pid,Arg} -> Pid!F(Arg), loop(F) end; loop(F) -> receive {exec,Pid,Arg} -> Pid!F(Arg), loop(F) end; Distrubution has same communication mechanism Hence, concurrency or distribution is transparant for user P1 P0 ! {exec,self(),15}, N = receive Answer -> Answer end, N = F(15),

20 Erlang fault tolerance
Thomas Arts Erlang fault tolerance Processes can be linked to each other: PidA PidB Links are created by using either: link(Pid), or spawn_link(Module, Function, Args) Links are bi-directional. They can be removed using unlink(Pid).

21 Erlang fault tolerance
Thomas Arts Erlang fault tolerance When a process terminates, an exit signal is sent to all processes the process is linked to: PidA PidA PidB A process can terminate normally, due to a run-time error, or when explicitly ordered to do so.

22 Erlang fault tolerance
Thomas Arts Erlang fault tolerance If a process terminates abnormally, the emitted exit signal will (by default) cause the recipient to terminate: The termination reason in the transmitted exit signals will be the same as in the received one (the exit signal is propagated). PidA PidB PidB PidC PidD PidD PidE

23 Erlang fault tolerance
Thomas Arts Erlang fault tolerance A process can terminate itself using exit(Reason). This will cause exit signals with termination reason Reason to be emitted. exit(error) PidB PidC error PidA

24 Erlang fault tolerance
Thomas Arts Erlang fault tolerance A process can explicitly send an exit signal to another process using exit(Pid, Reason): exit(PidB, error) PidB PidA error The calling process is not affected. The processes do not need to be linked.

25 Erlang fault tolerance
Thomas Arts Erlang fault tolerance A process can trap exit signals using: process_flag(trap_exit, true). Incoming exit signals will be transformed into messages of the form: {'EXIT', Pid, Reason} These exit messages are delivered to the process mailbox in the normal way.

26 Erlang fault tolerance
Thomas Arts Erlang fault tolerance PidC terminates with reason error, PidD is trapping exits: PidB terminates, propagating the exit signal. PidD will receive an exit message {'EXIT', PidC, error}. error error PidA PidA PidB PidB PidC PidD PidE

27 Erlang fault tolerance
Thomas Arts Erlang fault tolerance Robust systems can be made by layering.

28 Erlang fault tolerance
Thomas Arts Erlang fault tolerance supervision trees and restart strategies P1 P2 P3 P1 P4 P3 P1 P2 P3 P4 P5 P6

29 Erlang component based development
Thomas Arts Erlang component based development recognize frequently occurring patterns and transfer them into standard components. faster development uniform code (maintenance) less errors

30 Thomas Arts Erlang Developed with the application of the language constantly in mind Practical usability more priority than purity

31 AXD 301, scalable ATM switch (up to 160 GB/sec)
Thomas Arts Erlang is used AXD 301, scalable ATM switch (up to 160 GB/sec) four years work more than 500,000 lines of Erlang several hundreds of programmers

32 Erlang is used GPRS: next generation GSM network.
Thomas Arts Erlang is used GPRS: next generation GSM network. Eigth times faster internet access in mobile phones always connected development in three countries, hundreds of people

33 Erlang is used The success of the language in industry is due to
Thomas Arts Erlang is used The success of the language in industry is due to Language features Support and libraries Design patterns / architectures easy to learn close to way of thinking by building telecom products

34 Erlang is used www.erlang.org over 300 downloads per month
Thomas Arts Erlang is used over 300 downloads per month Become a user yourself! passive: make a phonecall active: download Erlang for free easy to learn close to way of thinking by building telecom products

35 The functional language for industry
Thomas Arts Erlang The functional language for industry easy to learn close to way of thinking by building telecom products nieuw onderzoek


Download ppt "Industrial Use of a Functional Language"

Similar presentations


Ads by Google