Functional Programming eXchange experience report

Yan Cui

I help clients go faster for less using serverless technologies.

I attended the Functional Programming eXchange 15 last Thursday and it was a thoroughly enjoyable day.

Don’t worry if you weren’t one of the lucky 100 or so that made it, most of the talks are available online on SkillsMatter’s website, and here’s a high level summary of a couple of the talks.

 

Games and 3D Graphics in Arcadia

Tim Gardner started the conference with an awesome talk on Arcadia, a live coding environment for Clojure targeting Unity3D.

Throughout the talk, Tim demoed the power of Arcadia – being able to interactively modify a virtual world in Unity3D live, by writing Clojure code in a REPL (which is then compiled to MSIL using ClojureCLR).

And just to show how far you can push it, Tim did the entire demo in an Emacs window inside the Unity3D world it’s manipulating, which is projected onto an Oculus Rift headset. Why? Because you could! 

Jokes aside, it is rather impressive, and as Claudia mentioned in a conversation with Tim afterwards, the ability to script the scene itself is very valuable. Being able to drag-and-drop and click a few boxes here and there to edit things is great but very soon you realise you need automation as the number of objects in the scene grows, and that could be the gateway drug that gets Arcadia through the door.

Another interesting feature of Arcadia is the ability to serialize and save the current state of the scene, though Tim didn’t demo this so I don’t know how it works in practice. One caveat (that has caught many people out including myself..) with Unity3D is that whilst in play mode, changes you make to the scene are lost when you go back to edit mode.

Which is frustrating, because even though you’re able to learn and discover about the virtual world you’re building by being inside it and interact with and modify it as we go, we’re not able to keep the result of our tinkering and experimentation. You could painstakingly note down or remember every change you have made and then reapply them back in the edit mode, but remember we can only keep around 7 items in our head at a time.

As things stand, the play mode is more of a tool for validating your grand design, but it’s capable of being so much more. If there’s one thing I’ve learnt from Bret Victor, is that, creators need to see rapid feedbacks from their ideas. So if Arcadia is able to save and load the current state of a world then that’d a massive deal for me.  

 

Watch the talk here.

 

The lazy programmer’s guide to writing 1000’s of tests : An introduction to property based testing

This is a new talk from Scott Wlaschin on property-based testing with FsCheck. As ever, you can expect Scott’s usual blend of great humour and insightfulness.

In this talk, Scott gave a gentle introduction to property-based testing, and then outlined some techniques for choosing properties to test (which is usually the hard part when you first start writing property-based tests), and finished off by introducing model-based testing too.

I strongly recommend this talk, and you might also be interested in checking out these two posts by Scott too:

 A colleague of mine was so inspired by this talk, that he told me afterwards he plans to rewrite all of his unit tests for our payment gateway with Python’s adaptation of QuackCheck – Hypothesis!  

 

Watch the talk here.

 

Build your own effects

In this talk Jeremy Yallop demonstrated a way to manage side-effects using a new feature in OCaml (which should be available in the next major version) called effects. In traditional stack-based model, when an exception occurs the rest of the stacks are thrown away as the exception is captured and bubbled up: fpx15 This is the same with CPS (continuation passing style) code too.

Essentially exceptions is a way to short circuit program execution (either intentionally or unintentionally). All exception can tell you is that ‘something has gone wrong’, it’s a very limited one-way conversation.

With effects, you not only get the information about the effect, but also the rest of the stack as a continuation, so we can instead model resumable exceptions like the following:

(the above is constructed based on my recollection and syntax from this paper, so it’s likely not accurate, but should still give you a flavour of what you can do)

You can also easily model other effects, such as:

  • dynamic binding, e.g. when you detect an unbound variable, perform an effect whose handler would
    • binds a default value for the variable in the current context and;
    • invoke the continuation
  • yield and concurrency as described in this paper
  • state monad where state updates are performed as an effect

The big advantage of this approach is that it simplifies composition of different effects.

With Haskell’s monads for instance, this is done through monad transformers which is limited to a specific pair of monads and adds another layer of complexity.

With effects, you just add a clause in your match…with statement to handle a new effect alongside other effects and you’re done!

 

Unfortunately this talk was not recorded, but you can still get a flavour by looking at some of the examples in this paper.

 

Due to other commitments this weekend, I’m not able to cover the other talks here, but you can still watch them here.

All the talks were pretty good and worth watching, and if you’re looking to champion the adoption of functional programming in your organization then you should definitely watch Michael Newton’s talk – Functional Programming in an Imperative World. Michael presented lots of anecdotes from his experience promoting F# at 15Below. I saw another good talk on the topic by Jay Fields at QCon London this year on how he pushed the adoption of Clojure at DRW Trading, which is sadly not available on InfoQ yet but you can watch an older version of the talk here.

 

Next stop : NDC Oslo this week where I’ll be doing two talks on Wednesday:

  • A tour of the language landscape – a whirlwind tour through some of the languages on the fringe of mainstream and look at interesting ideas I have learnt from them, including Go, Rust, Erlang, F#, Elm, Clojure and maybe Idris
  • Modelling complex game economy with Neo4j – a case study of how we used Neo4j at Gamesys Social to model our MMORPG game Here Be Monsters, and used this model to help automate the process of balancing the game economy

 

Links

Whenever you’re ready, here are 3 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
  2. I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
  3. Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.

Leave a Comment

Your email address will not be published. Required fields are marked *