Learning functional/Clojure programming – practical exercises? [closed]

4clojure was launched recently. It takes a lot of inspiration from Functional Koans, and several of the puzzles from 99 Lisp Problems; but it improves on both by providing a learning experience for which you need only your browser. Problems vary in difficulty from language tutorials like What is the second element of this list? … Read more

SOLID for functional programming

As far as I know (I’m no expert), SOLID principles do not tell anything about state. They should be applicable as well in a functional programming languages. They’re more advice about how to achieve modularity. Some of them are rather obvious or at least well-known. Single-responsibility is the UNIX principle “do one thing and do … Read more

Why is the use of Maybe/Option not so pervasive in Clojure? [closed]

Clojure is not statically typed, so doesn’t need the strict this/that/whatever type declarations that are necessary in haskell (and, I gather, Scala). If you want to return a string, you return a string; if you return nil instead, that’s okay too. “Functional” does not correspond exactly to “strict compile-time typing”. They are orthogonal concepts, and … Read more

What is the “pin” operator for, and are Elixir variables mutable?

The data in Elixir is still immutable, but there are couple of shorthands, that let you type less or don’t worry about finding new names. In Erlang, you could often see code like this: SortedList = sort(List), FilteredList = filter(SortedList), List3 = do_something_with(FilteredList), List4 = another_thing_with(List3) In Elixir, you could just write: list = sort(list) … Read more

How do I implement graphs and graph algorithms in a functional programming language?

You might check out how Martin Erwig’s Haskell functional graph library does things. For instance, its shortest-path functions are all pure, and you can see the source code for how it’s implemented. Another option, like fmark mentioned, is to use an abstraction which allows you to implement pure functions in terms of state. He mentions … Read more

What are the performance impacts of ‘functional’ Rust?

TL;DR A functional implementation can be faster than your original procedural implementation, in certain cases. Why is the functional style so much slower than the imperative style? Is there some problem with the functional implementation which is causing such a huge slowdown? As Matthieu M. already pointed out, the important thing to note is that … Read more

Why is the raising of an exception a side effect?

Purity is only violated if you observe the exception, and make a decision based on it that changes the control flow. Actually throwing an exception value is referentially transparent — it is semantically equivalent to non-termination or other so-called bottom values. If a (pure) function is not total, then it evaluates to a bottom value. … Read more