advertisement

Functional Programming

50 %
50 %
advertisement
Information about Functional Programming
Technology

Published on October 27, 2008

Author: chriseidhof

Source: slideshare.net

advertisement

Functional Programming Chris Eidhof Eelco Lempsink Amsterdam.rb, October 27, 2008 ( tp , ui ) l

Functional programming in Ruby (1..4).collect {|i| i*i } #=> [1, 4, 9, 16] (1..10).inject {|sum, n| sum + n} #=> 55

Functional programming with Haskell (1..4).collect {|i| i*i } map (λi → i ∗ i) [1 . . 4] -- [1,4,9,16] (1..10).inject {|sum, n| sum + n} foldr (λn sum → sum + n) 0 [1 . . 10] -- 55

What is Haskell? Haskell is a • strongly typed • lazy • purely functional programming language

Everything is a function • No “assignment” • Referential transparancy • Partial application, no parentheses needed a=5 a=6 -- Invalid! squares xs = map (λx → x ∗ x) xs

Why should I learn Haskell? • Functional Programming gives you a fresh way to look at problems • Even if you don’t use a functional language • Python, Ruby, C# all use ideas from FP • Google’s Map/Reduce and Hadoop are large scale FP

Lists data [a] = [ ] | a : [a]

Some standard functions sum [ ] =0 sum (x : xs) = x + sum xs product [ ] =1 product (x : xs) = x ∗ product xs and [ ] = True and (x : xs) = x ∧ and xs

Everything is a fold! foldr (⊕) e [ ] =e foldr (⊕) e (x : xs) = x ⊕ (foldr (⊕) e xs) sum = foldr ( + ) 0 product = foldr ( ∗ ) 1 and = foldr ( ∧ ) True

Even map! map f = foldr (λx tail → (f x) : tail) [ ]

Infinite lists... primes = sieve [2 . . ] sieve (p : xs) = p : sieve [x | x ← xs , x ‘mod‘ p ≡ 0 ]

QuickSort qsort [ ] = [] qsort (x : xs) = qsort (filter (<x) xs) + [x ] + + qsort (filter ( x) xs) +

What we didn’t tell you • Function composition • Types • Purity and I/O • Monads • Foreign Function Interface • ...

Haskell in the Real World • Large applications (XMonad, Darcs, GHC, Yi) • Lots of libraries (Today on hackage: 814 libraries and programs) • Used by large companies (Credit Suisse, Galois, Microsoft, ABN Amro . . . ) • Lots of ways to learn Haskell ((free) textbooks, university courses, haskell wiki, blogs)

Functional programming • ... sharpens your brain • ... is lots of fun • ... can help you become a better programmer

More information • http://haskell.org • http://hackage.haskell.org • http://book.realworldhaskell.org/ • http://tupil.com

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Functional programming - Wikipedia, the free encyclopedia

In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats ...
Read more

Functional Programming vs. Imperative Programming

The functional programming paradigm was explicitly created to support a pure functional approach to problem solving. Functional programming is a form of ...
Read more

Funktionale Programmierung – Wikipedia

Funktionale Programmierung ist ein Programmierparadigma, ... A Functional Programming Approach. Addison Wesley 1999, ISBN 0-201-59604-0; Weblinks
Read more

Overview: Introducing F# and Functional Programming

This overview discussed different programming paradigms that you can use in F# and gave a high-level overview of what functional programming is.
Read more

Manning | Real-World Functional Programming

About the Technology. Functional programming languages are good at expressing complex ideas in a succinct, declarative way. Functional concepts such as ...
Read more

Real World Functional Programming: With Examples in F# and ...

HIGHLIGHT A crisp introduction to functional programming for .NET developers--with examples in C# and F#. DESCRIPTION Functional programming languages like ...
Read more

Functional Programming System – Wikipedia

Der Begriff Functional Programming System (abgekürzt FP-System) bezeichnet ein von John W. Backus entwickeltes Konzept funktionaler Programmiersprachen.
Read more

Functional programming: A step backward | JavaWorld

Functional programming languages will have a place in general application development when we can read their code at a glance.
Read more

Functional Programming in C# im Preisvergleich

Functional Programming in C#: Classic Programming Techniques for Modern Projects
Read more