SlideShare a Scribd company logo
Functional
                    Programming


Friday, 18 May 12
Andrew Jones @andrew_jones
                    Thom Leggett @thomleggett



Friday, 18 May 12
BrisFunctional
                          @brisfunctional
                     brisfunctional.github.com




Friday, 18 May 12
Project Euler



Friday, 18 May 12
JSON parser



Friday, 18 May 12
Noughts and Crosses
                            AI


Friday, 18 May 12
http://www.flickr.com/photos/dippy_duck/7210706592/




Friday, 18 May 12
Alligator Eggs

Friday, 18 May 12
Friday, 18 May 12
http://www.flickr.com/photos/14591708@N00/6878586390/




Friday, 18 May 12
What is Functional
                     Programming?


Friday, 18 May 12
Functional




Friday, 18 May 12
Disfunctional   Functional




Friday, 18 May 12
Disfunctional        Functional


                      C#




Friday, 18 May 12
Disfunctional        Functional


                      C#




Friday, 18 May 12
Disfunctional        Functional


                      C#    Haskell




Friday, 18 May 12
Disfunctional                     Functional


                      C#                 Haskell
                           Javascript




Friday, 18 May 12
Disfunctional                         Functional


                      C#                     Haskell
                               Javascript
                           C




Friday, 18 May 12
Disfunctional                                Functional


                             C#                     Haskell
                    Pascal            Javascript
                                  C




Friday, 18 May 12
Disfunctional          Java                    Functional


                             C#                       Haskell
                    Pascal              Javascript
                                    C




Friday, 18 May 12
Disfunctional          Java                     Functional


                             C#                        Haskell
                    Pascal              Javascript
                                    C
                                                     Erlang



Friday, 18 May 12
Disfunctional          Java                     Functional


                             C#                        Haskell
                    Pascal              Javascript
                                                       Clojure
                                    C
                                                     Erlang



Friday, 18 May 12
Disfunctional          Java          SQL        Functional


                             C#                        Haskell
                    Pascal              Javascript
                                                       Clojure
                                    C
                                                     Erlang



Friday, 18 May 12
Python

      Disfunctional          Java          SQL        Functional


                             C#                        Haskell
                    Pascal              Javascript
                                                       Clojure
                                    C
                                                     Erlang



Friday, 18 May 12
Ruby
                                          Python

      Disfunctional          Java          SQL        Functional


                             C#                        Haskell
                    Pascal              Javascript
                                                       Clojure
                                    C
                                                     Erlang



Friday, 18 May 12
Ruby
                                                Python

      Disfunctional                Java          SQL        Functional


                                   C#                        Haskell
                    Pascal                    Javascript
                                                             Clojure
                                          C
                             PHP                           Erlang



Friday, 18 May 12
http://alblue.bandlem.com/2012/03/qcon-day-3.html




Friday, 18 May 12
Immutability



Friday, 18 May 12
Friday, 18 May 12
Friday, 18 May 12
1 public class Mutable {
             2     private List<Sheep> herd;
             3
             4     public List<Sheep> getHerd() {
             5         return herd;
             6     }
             7 }




Friday, 18 May 12
1 public class Immutable {
            2     private final List<Sheep> herd;
            3
            4     public List<Sheep> getHerd() {
            5         return Collections.unmodifiableList(herd);
            6     }
            7
            8 }




Friday, 18 May 12
Referential
                    Transparency


Friday, 18 May 12
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/
http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/                  http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/
             By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL],
                                                                   via Wikimedia Commons
Friday, 18 May 12
First Class Functions



Friday, 18 May 12
http://www.flickr.com/photos/22748341@N00/2789592060/sizes/l/in/photostream/




Friday, 18 May 12
1 function shearHerd (herd) {
            2     for (var sheep in herd) {
            3         shear(sheep);
            4     }
            5 }
            6
            7 shearHerd(sheepHerd);




Friday, 18 May 12
http://www.flickr.com/photos/amypalko/3607158016/




Friday, 18 May 12
http://www.flickr.com/photos/emuphoto/206196733




Friday, 18 May 12
1       function map (herd, action) {
            2           for (var animal in herd) {
            3               action(animal);
            4           }
            5       }
            6
            7       map(sheepHerd, shear);
            8       map(cowHerd, milk);




Friday, 18 May 12
Examples



Friday, 18 May 12
LZW in C



Friday, 18 May 12
1   #include    <stdio.h>
      2   #include    <stdlib.h>                                                                67       ushort prev, back;
      3   #include    <string.h>                                                                68       byte c;
      4   #include    <stdint.h>                                                                69   } lzw_dec_t;
      5   #include    <unistd.h>                                                                70
      6   #include    <fcntl.h>                                                                 71   byte* lzw_encode(byte *in, int max_bits)
      7   #include    <sys/types.h>                                                             72   {
      8   #include    <sys/stat.h>                                                              73       int len = _len(in), bits = 9, next_shift = 512;
      9                                                                                         74       ushort code, c, nc, next_code = M_NEW;
     10   /* -------- aux stuff ---------- */                                                   75       lzw_enc_t *d = _new(lzw_enc_t, 512);
     11   void* mem_alloc(size_t item_size, size_t n_item)                                      76
     12   {                                                                                     77       if (max_bits > 16) max_bits = 16;
     13       size_t *x = calloc(1, sizeof(size_t)*2 + n_item * item_size);                     78       if (max_bits < 9 ) max_bits = 12;
     14       x[0] = item_size;                                                                 79
     15       x[1] = n_item;                                                                    80       byte *out = _new(ushort, 4);
     16       return x + 2;                                                                     81       int out_len = 0, o_bits = 0;
     17   }                                                                                     82       uint32_t tmp = 0;
     18                                                                                         83
     19   void* mem_extend(void *m, size_t new_n)                                               84       inline void write_bits(ushort x) {
     20   {                                                                                     85           tmp = (tmp << bits) | x;
     21       size_t *x = (size_t*)m - 2;                                                       86           o_bits += bits;
     22       x = realloc(x, sizeof(size_t) * 2 + *x * new_n);                                  87           if (_len(out) <= out_len) _extend(out);
     23       if (new_n > x[1])                                                                 88           while (o_bits >= 8) {
     24           memset((char*)(x + 2) + x[0] * x[1], 0, x[0] * (new_n - x[1]));               89               o_bits -= 8;
     25       x[1] = new_n;                                                                     90               out[out_len++] = tmp >> o_bits;
     26       return x + 2;                                                                     91               tmp &= (1 << o_bits) - 1;
     27   }                                                                                     92           }
     28                                                                                         93       }
     29   inline void _clear(void *m)                                                           94
     30   {                                                                                     95       //write_bits(M_CLR);
     31       size_t *x = (size_t*)m - 2;                                                       96       for (code = *(in++); --len; ) {
     32       memset(m, 0, x[0] * x[1]);                                                        97           c = *(in++);
     33   }                                                                                     98           if ((nc = d[code].next[c]))
     34                                                                                         99               code = nc;
     35   #define    _new(type, n)   mem_alloc(sizeof(type), n)                                100           else {
     36   #define    _del(m)     { free((size_t*)(m) - 2); m = 0; }                            101               write_bits(code);
     37   #define    _len(m)     *((size_t*)m - 1)                                             102               nc = d[code].next[c] = next_code++;
     38   #define    _setsize(m, n) m = mem_extend(m, n)                                       103               code = c;
     39   #define    _extend(m) m = mem_extend(m, _len(m) * 2)                                 104           }
     40                                                                                        105
     41                                                                                        106           /* next new code would be too long for current table */
     42   /* ----------- LZW stuff -------------- */                                           107           if (next_code == next_shift) {
     43   typedef uint8_t byte;                                                                108               /* either reset table back to 9 bits */
     44   typedef uint16_t ushort;                                                             109               if (++bits > max_bits) {
     45                                                                                        110                   /* table clear marker must occur before bit reset */
     46   #define M_CLR      256 /* clear table marker */                                      111                   write_bits(M_CLR);
     47   #define M_EOD      257 /* end-of-data marker */                                      112
     48   #define M_NEW      258 /* new code index */                                          113                      bits = 9;
     49                                                                                        114                      next_shift = 512;
     50   /* encode and decode dictionary structures.                                          115                      next_code = M_NEW;
     51      for encoding, entry at code index is a list of indices that follow current one,   116                      _clear(d);
     52      i.e. if code 97 is 'a', code 387 is 'ab', and code 1022 is 'abc',                 117                  } else /* or extend table */
     53      then dict[97].next['b'] = 387, dict[387].next['c'] = 1022, etc. */                118                      _setsize(d, next_shift *= 2);
     54   typedef struct {                                                                     119           }
     55       ushort next[256];                                                                120       }
     56   } lzw_enc_t;                                                                         121
     57                                                                                        122       write_bits(code);
     58   /* for decoding, dictionary contains index of whatever prefix index plus trailing    123       write_bits(M_EOD);
     59       byte. i.e. like previous example,                                                124       if (tmp) write_bits(tmp);
     60        dict[1022] = { c: 'c', prev: 387 },                                             125
     61        dict[387] = { c: 'b', prev: 97 },                                               126       _del(d);
     62        dict[97]   = { c: 'a', prev: 0 }                                                127
     63       the "back" element is used for temporarily chaining indices when resolving       128       _setsize(out, out_len);
     64       a code to bytes                                                                  129       return out;
     65    */                                                                                  130   }
     66   typedef struct {



Friday, 18 May 12
LZW in Clojure



Friday, 18 May 12
1 (defn make-dict []
         2   (let [vals (range 0 256)]
         3     (zipmap (map (comp #'list #'char) vals) vals)))
         4
         5 (defn compress [#^String text]
         6   (loop [t (seq text)
         7          r '()
         8          w '()
         9          dict (make-dict)
        10          s 256]
        11     (let [c (first t)]
        12       (if c
        13         (let [wc (cons c w)]
        14           (if (get dict wc)
        15             (recur (rest t) r wc dict s)
        16             (recur (rest t) (cons (get dict w) r) (list c)
        17                (assoc dict wc s) (inc s))))
        18         (reverse (if w (cons (get dict w) r) r))))))
        19
        20 (compress "TOBEORNOTTOBEORTOBEORNOT")




Friday, 18 May 12
LZW in Haskell



Friday, 18 May 12
1        import Data.List
           2        import Data.Char
           3        import Data.Maybe
           4
           5        doLZW _ [] = []
           6        doLZW as (x:xs) = lzw (map return as) [x] xs
           7           where lzw a w [] = [fromJust $ elemIndex w a]
           8                 lzw a w (x:xs) | w' `elem` a = lzw a w' xs
           9                                 | otherwise   = fromJust (elemIndex w a) :
          10                                                            lzw (a++[w']) [x] xs
          11                      where w' = w++[x]




Friday, 18 May 12
Friday, 18 May 12
Recommended Reading



Friday, 18 May 12
Friday, 18 May 12
Closing Thought
                     One thing that makes a programming language ‘more
                    powerful’ in my opinion is the provision of more ways
                      to factor programs. Or if you prefer, more axes of
                        composition. The more different ways you can
                       compose programs out of subprograms, the more
                                    powerful a language is.

                     Reg Braithwaite - Functional Programming Matters




Friday, 18 May 12
Thanks!
                    Andrew Jones @andrew_jones
                     Thom Leggett @thomleggett




Friday, 18 May 12

More Related Content

Recently uploaded

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 

Recently uploaded (20)

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Functional Programming

  • 1. Functional Programming Friday, 18 May 12
  • 2. Andrew Jones @andrew_jones Thom Leggett @thomleggett Friday, 18 May 12
  • 3. BrisFunctional @brisfunctional brisfunctional.github.com Friday, 18 May 12
  • 6. Noughts and Crosses AI Friday, 18 May 12
  • 11. What is Functional Programming? Friday, 18 May 12
  • 13. Disfunctional Functional Friday, 18 May 12
  • 14. Disfunctional Functional C# Friday, 18 May 12
  • 15. Disfunctional Functional C# Friday, 18 May 12
  • 16. Disfunctional Functional C# Haskell Friday, 18 May 12
  • 17. Disfunctional Functional C# Haskell Javascript Friday, 18 May 12
  • 18. Disfunctional Functional C# Haskell Javascript C Friday, 18 May 12
  • 19. Disfunctional Functional C# Haskell Pascal Javascript C Friday, 18 May 12
  • 20. Disfunctional Java Functional C# Haskell Pascal Javascript C Friday, 18 May 12
  • 21. Disfunctional Java Functional C# Haskell Pascal Javascript C Erlang Friday, 18 May 12
  • 22. Disfunctional Java Functional C# Haskell Pascal Javascript Clojure C Erlang Friday, 18 May 12
  • 23. Disfunctional Java SQL Functional C# Haskell Pascal Javascript Clojure C Erlang Friday, 18 May 12
  • 24. Python Disfunctional Java SQL Functional C# Haskell Pascal Javascript Clojure C Erlang Friday, 18 May 12
  • 25. Ruby Python Disfunctional Java SQL Functional C# Haskell Pascal Javascript Clojure C Erlang Friday, 18 May 12
  • 26. Ruby Python Disfunctional Java SQL Functional C# Haskell Pascal Javascript Clojure C PHP Erlang Friday, 18 May 12
  • 31. 1 public class Mutable { 2 private List<Sheep> herd; 3 4 public List<Sheep> getHerd() { 5 return herd; 6 } 7 } Friday, 18 May 12
  • 32. 1 public class Immutable { 2 private final List<Sheep> herd; 3 4 public List<Sheep> getHerd() { 5 return Collections.unmodifiableList(herd); 6 } 7 8 } Friday, 18 May 12
  • 33. Referential Transparency Friday, 18 May 12
  • 34. http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 35. http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 36. http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 37. http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/ http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 38. http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/ http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 39. http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/ http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 40. http://www.flickr.com/photos/cradlehall/3583049156/sizes/l/in/photostream/ http://www.flickr.com/photos/cruadin/298374640/sizes/l/in/photostream/ http://www.flickr.com/photos/jsutcliffe/5916342650/sizes/l/in/photostream/ By Cstaffa (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or FAL], via Wikimedia Commons Friday, 18 May 12
  • 43. 1 function shearHerd (herd) { 2 for (var sheep in herd) { 3 shear(sheep); 4 } 5 } 6 7 shearHerd(sheepHerd); Friday, 18 May 12
  • 46. 1 function map (herd, action) { 2 for (var animal in herd) { 3 action(animal); 4 } 5 } 6 7 map(sheepHerd, shear); 8 map(cowHerd, milk); Friday, 18 May 12
  • 48. LZW in C Friday, 18 May 12
  • 49. 1 #include <stdio.h> 2 #include <stdlib.h> 67 ushort prev, back; 3 #include <string.h> 68 byte c; 4 #include <stdint.h> 69 } lzw_dec_t; 5 #include <unistd.h> 70 6 #include <fcntl.h> 71 byte* lzw_encode(byte *in, int max_bits) 7 #include <sys/types.h> 72 { 8 #include <sys/stat.h> 73 int len = _len(in), bits = 9, next_shift = 512; 9 74 ushort code, c, nc, next_code = M_NEW; 10 /* -------- aux stuff ---------- */ 75 lzw_enc_t *d = _new(lzw_enc_t, 512); 11 void* mem_alloc(size_t item_size, size_t n_item) 76 12 { 77 if (max_bits > 16) max_bits = 16; 13 size_t *x = calloc(1, sizeof(size_t)*2 + n_item * item_size); 78 if (max_bits < 9 ) max_bits = 12; 14 x[0] = item_size; 79 15 x[1] = n_item; 80 byte *out = _new(ushort, 4); 16 return x + 2; 81 int out_len = 0, o_bits = 0; 17 } 82 uint32_t tmp = 0; 18 83 19 void* mem_extend(void *m, size_t new_n) 84 inline void write_bits(ushort x) { 20 { 85 tmp = (tmp << bits) | x; 21 size_t *x = (size_t*)m - 2; 86 o_bits += bits; 22 x = realloc(x, sizeof(size_t) * 2 + *x * new_n); 87 if (_len(out) <= out_len) _extend(out); 23 if (new_n > x[1]) 88 while (o_bits >= 8) { 24 memset((char*)(x + 2) + x[0] * x[1], 0, x[0] * (new_n - x[1])); 89 o_bits -= 8; 25 x[1] = new_n; 90 out[out_len++] = tmp >> o_bits; 26 return x + 2; 91 tmp &= (1 << o_bits) - 1; 27 } 92 } 28 93 } 29 inline void _clear(void *m) 94 30 { 95 //write_bits(M_CLR); 31 size_t *x = (size_t*)m - 2; 96 for (code = *(in++); --len; ) { 32 memset(m, 0, x[0] * x[1]); 97 c = *(in++); 33 } 98 if ((nc = d[code].next[c])) 34 99 code = nc; 35 #define _new(type, n) mem_alloc(sizeof(type), n) 100 else { 36 #define _del(m) { free((size_t*)(m) - 2); m = 0; } 101 write_bits(code); 37 #define _len(m) *((size_t*)m - 1) 102 nc = d[code].next[c] = next_code++; 38 #define _setsize(m, n) m = mem_extend(m, n) 103 code = c; 39 #define _extend(m) m = mem_extend(m, _len(m) * 2) 104 } 40 105 41 106 /* next new code would be too long for current table */ 42 /* ----------- LZW stuff -------------- */ 107 if (next_code == next_shift) { 43 typedef uint8_t byte; 108 /* either reset table back to 9 bits */ 44 typedef uint16_t ushort; 109 if (++bits > max_bits) { 45 110 /* table clear marker must occur before bit reset */ 46 #define M_CLR 256 /* clear table marker */ 111 write_bits(M_CLR); 47 #define M_EOD 257 /* end-of-data marker */ 112 48 #define M_NEW 258 /* new code index */ 113 bits = 9; 49 114 next_shift = 512; 50 /* encode and decode dictionary structures. 115 next_code = M_NEW; 51 for encoding, entry at code index is a list of indices that follow current one, 116 _clear(d); 52 i.e. if code 97 is 'a', code 387 is 'ab', and code 1022 is 'abc', 117 } else /* or extend table */ 53 then dict[97].next['b'] = 387, dict[387].next['c'] = 1022, etc. */ 118 _setsize(d, next_shift *= 2); 54 typedef struct { 119 } 55 ushort next[256]; 120 } 56 } lzw_enc_t; 121 57 122 write_bits(code); 58 /* for decoding, dictionary contains index of whatever prefix index plus trailing 123 write_bits(M_EOD); 59 byte. i.e. like previous example, 124 if (tmp) write_bits(tmp); 60 dict[1022] = { c: 'c', prev: 387 }, 125 61 dict[387] = { c: 'b', prev: 97 }, 126 _del(d); 62 dict[97] = { c: 'a', prev: 0 } 127 63 the "back" element is used for temporarily chaining indices when resolving 128 _setsize(out, out_len); 64 a code to bytes 129 return out; 65 */ 130 } 66 typedef struct { Friday, 18 May 12
  • 51. 1 (defn make-dict [] 2 (let [vals (range 0 256)] 3 (zipmap (map (comp #'list #'char) vals) vals))) 4 5 (defn compress [#^String text] 6 (loop [t (seq text) 7 r '() 8 w '() 9 dict (make-dict) 10 s 256] 11 (let [c (first t)] 12 (if c 13 (let [wc (cons c w)] 14 (if (get dict wc) 15 (recur (rest t) r wc dict s) 16 (recur (rest t) (cons (get dict w) r) (list c) 17 (assoc dict wc s) (inc s)))) 18 (reverse (if w (cons (get dict w) r) r)))))) 19 20 (compress "TOBEORNOTTOBEORTOBEORNOT") Friday, 18 May 12
  • 53. 1 import Data.List 2 import Data.Char 3 import Data.Maybe 4 5 doLZW _ [] = [] 6 doLZW as (x:xs) = lzw (map return as) [x] xs 7 where lzw a w [] = [fromJust $ elemIndex w a] 8 lzw a w (x:xs) | w' `elem` a = lzw a w' xs 9 | otherwise = fromJust (elemIndex w a) : 10 lzw (a++[w']) [x] xs 11 where w' = w++[x] Friday, 18 May 12
  • 57. Closing Thought One thing that makes a programming language ‘more powerful’ in my opinion is the provision of more ways to factor programs. Or if you prefer, more axes of composition. The more different ways you can compose programs out of subprograms, the more powerful a language is. Reg Braithwaite - Functional Programming Matters Friday, 18 May 12
  • 58. Thanks! Andrew Jones @andrew_jones Thom Leggett @thomleggett Friday, 18 May 12