Functional languages: Is anyone using them?


(Marc Cooper) #21

Thanks, Dave. I’ll keep that in mind. Hopefully, I will be sufficiently conversant with FP by then to benefit :smile:


(Marc Cooper) #22

“pure functional” is an interesting idea, and I know what you mean. I take a pragmatic attitude to all things computing, so I’m always happy to break with purity if it helps get me to where I want to go and reduces cognitive load.

A pragmatic step that elixir takes – bearing in mind its built on top of erlang – is the idea of “soft immutability”, so-called rebinding of variables. You can reassign a variable in elixir (or so it seems) which makes your code a lot more readable than when you maintain “purity”. It’s a purely pragmatic choice that’s enabled by syntactic sugar. There’s a lot of pragmatism in elixir, and I highly recommend taking a peek at it.


(Andy Wootton) #23

It’s funny that this should come back to life. I’ve just built myself a ‘Lisp machine’ on my 2*Pi. I’ve installed the new Raspbian Jesse which comes pre-loaded with Sun’s JVM now and I’ve added Leiningen and Clojure. There was even a brief moment when I considered trying emacs again. I think I must be ill.

I quite like Clojure’s approach to immutability (having never seen any other.) It appears to have an ‘about to do something dirty’ tube where it chucks stuff through to Java. :slight_smile:


(Marc Cooper) #24

Something else for you to try: Using all your CPUs - Elixir on Raspberry Pi 2 :sunglasses:


(Andy Wootton) #25

I’ve just checked if it has a stupid phrase. I’ve already learned that you can’t take a functional language seriously without one. I thought it was ‘Elixir of the rapid mind’ but that turned out to be World of Warcraft.


(Alastair McGowan-Douglas) #26

I will have to try to remember about elixir if I ever get an opportunity to think about it. Hopefully this forum can list my liked posts.


(Daniel Hollands) #27

https://talk.birmingham.io/users/altreus/activity/likes-given


(Andy Wootton) #28

I thought I should explain my “stupid phrases” comment:

I’m reading a book called “Clojure for the brave and true” and
Leinengen is “for automating Clojure projects without setting your hair on fire”

You can also:
“Learn you an Agda and achieve enlightenment” or
"Learn you a Haskell for Great Good!"

or go back in Lisp tradition to Scheme and ‘the Wizard Book’.

I’m not saying you have to be mad to think recursively but it obviously isn’t any disadvantage.

Not wanting to forget Elixir & Erlang I found this:
https://pragprog.com/articles/erlang which points out that it uses the same model of concurrency as occam which I got very interested in early in my career. That was based on Tony Hoare’s work on Communicating Sequential Processes which I recently read is now available free.


(Marc Cooper) #29

As I’m getting deeper into exploring and understanding the erlang “infrastructure” on which elixir is built, I’m often finding myself laughing at how it solves so many of the details that comprise a modern web app and a lot more besides.

At the top level, it has built in clustering, so you can just throw nodes at it to scale. Alone, that would create headaches, but it has its own supervisors that can be configured into a hierarchy with rules to self-heal all the way down to a “process” which might be only a single spawned function. Yet each parent can also supervise its children; you decide. Building that out of traditional components would be hard work.

Erlang also has its own in memory k/v store (ETS), which also replicates across the cluster, and which can be supervised. The store has a permissions system allowing you to control which processes have access to which data. Then there are two more data stores (Dets, and Mnesia), one disk based, which again self-manage.

I’ve only scratched the surface so far. I grabbed the phoenix (elixir’s web framework) book from the pragprog book sale and hope to get started with it this weekend.


(Andy Wootton) #30

ClojureScript tonight. @paulspencerwilliams has asked for RSVPs for pizza reasons.

Clojure runs on the Java JVM, .Net and now/soon on JavaScript.


(Andy Wootton) #31

There’s a Functional Programming Meetup tomorrow at Black Cat. It’s about the new Lambda functions in Java 8.

I’ve wasted half of the last day trying to understand what monoids and monads are. I think Clojure has taken me too far into the gravitational field of Haskell and it’s sucking me in but this morning I may have understood a joke about vowels I heard yesterday, so I must be making progress.

I think I’ve worked out that Clojure uses this magik but protects me from needing to know much yet, so I can get on with stuff. I think they’re why Rich Hickey tells me to stick to the built-in data structures. They ‘Just Work’ because monoids, maybe?


(Marc Cooper) #32

A monoid is mathematical concept used in group theory. It’s just an operator with a couple of simple properties. They’re useful for computer scientists (and discrete maths folk), but you don’t need to understand monoids when learning a programming language.

There seems to be a million explanations out there for monads. Most of which seem to say, “Monads are really simple”, then spend 10,000 words describing that simplicity :slight_smile:

They’re basically a type with some (well-defined) functions. It’s fascinating that they’ve become “a thing”, because almost every language manages fine without them. That’s not saying that some language don’t have a few monads; they just don’t make a song and dance about it.


(Andy Wootton) #33

Thanks. I’m sometimes not sure if people on the net giving explanations are really trying to help or to show how much they know. I gave my first answer on StackOverflow today because I was so cross with the over-complex explanations being given to someone who didn’t understand why a variable ‘also needed’ an identifier. Idjits. Also: “A monad is just a monoid in the category of endofunctors, what’s the issue?” :slight_smile:

The most useful explanation I found of monads was by someone who’d only just worked it out himself. I think I get that it’s about the characteristics of data structures and functions that allow them to be ‘fairly’ arbitrarily combined. The ‘joke’ was about an “a” and “e” being ‘piped together’ to make that weird combined ae character. That was an in-joke between the presenter and the interviewer that you wouldn’t understand if you needed to watch the video. I’m not sure if that’s rude or just careless.

I’ve written something aimed at kids, based on SICP page 1. I’m seriously thinking about carrying on to do a basic functional thinking demo, once I know how. I don’t think it can be undergraduate engineering algorithms, sadly. I found a free Common Lisp book today that made a CD catalogue very early on, to show that it is a language worth continuing to learn. I didn’t find ‘Clojure for the Brave and True’ did that.


(Marc Cooper) #34

It’s worth ref’ing the source: http://james-iry.blogspot.co.uk/2009/05/brief-incomplete-and-mostly-wrong.html

Yeah, monads are about combining: binding and returning, and a little bit about not having to flatten when you pull them into CS world. They’re not such a big deal given the features modern languages give us. e.g. elixir’s |> binding. I’ll take pragmatic usage over theory every time.


(Andy Wootton) #35

It probably isn’t obvious but I’m not doing this JUST to learn Clojure. Some of the detours are due to my book-writing activities, information metaphysics and development of my ideas about lean & agile. They’re part of a mutually recursive cluster of functions that will eventually create a tool that will write the book for me. Or not.

I also talk crap on the Internet whenever my muse is late with a delivery.


(Andy Wootton) #36

This was very helpful the second time I watched it: https://www.youtube.com/watch?v=ZhuHCtR3xq8
It has “DO NOT PANIC!” on the cover, in large, friendly letters. I may watch it another 5 times and make notes. It disproves the theory I repeated on Slack which says, “when you learn to understand functional programming, you learn the ability to explain it to others”.


(Andy Wootton) #37

A very good Brum AI tonight. Last speaker Felix https://www.palgrave.com/gb/book/9783319624785 mentioned that he used Lisp so I asked him which one, afterwards. This http://lfe.io/, Lisp Flavoured Erlang.
The review I just read compared it unfavourably with Clojure but if you were committed to the Erlang VM, like @auxbus or wanted a distributed Lisp…


(Michael Almyros) #38

I have used functional programming in Java and JavaScript to map, reduce and filter data along side with pure functions. This allows for implementing fluent code without side effects. If we also add Predicates then we have really good benefits especially in readability.

Also when applying functional programming strive for immutability wherever possible you are going to have match less headaches.

For the people that are new to functional programming to get it confused with Object Oriented programming they are different things but they work well together.

For Java I would suggest to watch any video from Venkat Subramaniam he is amazing at explaining the concepts.


(Andy Wootton) #39

When I was last programming, it was very obvious that all the languages (and their extensions) were stealing features from each other. I used VAX/VMS dialects of Pascal, BASIC and FORTRAN and they were almost interchangeable, apart from annoying bits of syntactic fluff. This was odd because the VAX Calling Standard meant modules in different languages could be freely mixed.

I think it’s happening again, with features like Map-Filter-Reduce and immutable data structures. I have mixed feelings about it. Big languages are harder to learn and to distinguish their core features from each other. We’re heading for a big mess of incompatible language-specific libraries, with huge overlaps.