Exploring Data Abstraction and Functional Programming at Lambda Jam Sessions

Table of Contents

1. Sessions

1.1. Data, Visibility, and Abstraction - Stuart Sierra

  • Basic (low abstraction but direct)
  • QBAsic (subroutines vs. functions; IDE, debugger, immediate calling)
  • C++ (limited visibility, create your own data structures)
  • Perl (abstractions that actually helped; new generic data structures; tied data structures (array tied to Tie::File))
  • XSLT (pattern matching, recursion, immutable variables, homoiconic; transformations against)
  • Java (boilerplate with visibility)
  • Common Lisp (required new abstractions rather than just relying on builtins) http://stuartsierra.com/download/perl-in-lisp-literate-full.html
  • Rails (lambdas, flexible language; see division in Hpricot for subset)
  • Clojure (immutability, inspect-tree, lazy sequences)

1.1.1. Side Effects

As programs became more complicated there wasn't any outcomes. Using threading macros: data transformaitons with only one side effect at the end:

  (defn execute-action []
    (->
     (lookup-data)
     (lookup-data2)
     (side-effect)
     (transform-data)
     (retransform-data)
     (modify-state)))

1.2. Simile-Free Monad Recipes - Aditya Siram

http://lanyrd.com/2013/lambda-jam/scghtq/

  • Haskell
  • IO, Reader, Writer, State, Monad Transform

1.3. Monads and Macros - Chris Houser & Jonathan Claggett

http://lanyrd.com/2013/lambda-jam/scghtw/

Session that covered differences in the threading macro with the work on threading macros (more precisely sythread) vs. macros (though macros weren't covered as much as I would have expected).

https://github.com/LonoCloud/synthread http://docs.racket-lang.org/reference/stxtrans.html

1.4. The Art of Several Interpreters

Run through all of the examples to show static and dynamic scope.

Applying the Y combinator wasn't even discussed but for some reason covered an example of execution of (car (cdr '(foo bar baz))) in the interpreter.

The following is another form for Church Numerals since the lexical scope for quote wins in Scheme.

  (((lambda (quote) (lambda (x) ''''x)) add1) 0)

Work through the construction of Lamdba Calculus:

;; boolean 
(define yes (lambda (f) (lambda x) f x))
;; identity
(lambda f.0 f.0)

1.5. Clojure BOF

1.5.2. ClojureScript Channels @swannodette

core.async working with ClojureScript.

rx.js as one of the options for managing conditional activities based on async requests.

https://github.com/swannodette/async-tests/blob/master/src/async_test/robpike/core.cljs

This continues some of the work on having better composability than what is provided just through callbacks or futures.

  (defn handler [[e c]]
    (match [e]
           [{"x" x} {"y" y}]))

Requires bringing the async edges in to channels. Example was using the Google JSONP interface dumping values into a channel.

  (defn fastest []
    ())
  

This also provides precise event control when using throttle rules with timeouts.

  (defn throttle
    ([src ms]
       ())
    ([c src ms]
       ()))
  

See a comparable implementation: http://davidwalsh.name/function-debounce

  • Multiplex channels
  • event channel
  • map includes the munction to removeEventListener el
  • go blocks
  • Fan-in
  • Blocking

http://en.wikipedia.org/wiki/Communicating_sequential_processes

1.6. Functional Reactive Programming in the Netflix API - Ben Christensen

1.6.1. Use Case

Problem: Fetch a value then async conditional data request.

Research:

Looking at Futures and Observable .

Treat the contruction of Observable endpoint based on machine state, amount of work, data in memory.

1.6.2. Implementation

1.6.3. Solution

Havae a grid of movies each with metadata that, based on that data, will require a second (or more) request(s): VideoMetadata, VideoBookmark, VideoRating.

This used Groovy for the implementations against the service:

  • getVideos
  • take
  • mapMany / flatMap
  • metadata, bookmark, rating:
  • return zip(a, b, F)

1.6.4. Takeaway

Apply functions to async

Emphasize developer training re: functional and reactive programming. Initial hurdle was just in setting up the workshops, brought in a technical writer just for the documentation for the on-boarding.

Debugging and performance was the next area of improvement.

Only rule: "Don't mutate state outside of function."

1.7. Functional Async Without the Pain - Jim Powers

http://lanyrd.com/2013/lambda-jam/scghwp/

  • aync approach in nodejs and Java concurrently makes it hard to reasons about
  • Actors scale well
  • RX looks interesting but was only reviewed
  • Based on http://akka.io/
val system = ActorSystem.create()

class FooActor extends Actor { 

} 
  • Scatter/Gather

1.7.1. Transformer Functions

  • Next
  • Error
  • Empty
  • Complete

1.7.2. Videos

TBD

1.8. Functional CoffeeScript for Web UIs - Richard Feldman

Covered some of the considerations for when to use a transpiler for JavaScript.

https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS

  • Look at descructuring of the the object from data in a callback (e.g., [x, y] for point if that were the data).

1.10. Compilers From Scratch

1.10.1. Problem Statement

Starting with Lambda Calculus and BNF of SExpr, Var, Int, Bool, Binop.

1.10.2. Regular Expressions

3 basic operations.

  • symbol
  • repetion
  • concatenation

Strings in Haskell are just lists.

  • pull characters from string one at a time
  • at end of string check the match

1.10.3. Workflow

  • Define a list of tokens we want to suport
  • Define a sample program that we want to run
  (let (y (lambda f
            ((lambda x (x x))
             (lambda x (f (lambda v ((x x) v)))))))
    (let (factH (lambda partial
                  (lambda n (if (= n 0)
                           1
                         (* n (partial (- n 1)))))))
      (let (fact (y factH))
        (print (fact 5)))))
  
  • Lex the program by finding matches for types associated with If, Sub, Mul, Eq, Gt, Lt, Or, And, Let
  • Create the rules as RegExp matches
  • Running from Haskell
jwalsh:CompilersFromScratch/ (master) $ ghci SExpr
  • Provide a simple example
(let (x 1) 

2. Tasks

2.9. POC: LiveScript

This had more love than expected (possibly due to the F# contingent) but more highly regarded than at most JS conferences (e.g., the heavy push at CascadiaJS).

http://livescript.net/

As a replacement for underscore.js ; backcalls from Haskell in underscore.js.