Application and Composition

Haskell‘s notorious learning curve isn’t just down to the apparent need to learn advanced Category Theory before you can cogently browse the documentation. It’s also that you’re hit with a syntax that’s really unfamiliar – at least if you’re coming from the more "mainstream" languages like I am (Python, C++, Coffeescript). In particular, you’re hit…

Double Dabble Ramda

Recently at work I’ve switched from using Lodash to Ramda for functional programming extensions to Javascript/Coffeescript and I’m happier than I’ve pretty much ever been. Ramda isn’t the Javascript Holy Grail – that honor, I’m guessing, goes to PureScript – very much next in line on the list of things to learn – but it…

Understanding Applied to Double Dabble

Understanding is a funny thing. Sometimes you can trick yourself into thinking you understand something you really don’t. But most times you kinda sorta know that you don’t fully understand it, and I’m just not really sure how that works. In particular, there are two kinds of levels to "understanding." There’s that level where you…

Number System Solution

Yesterday I used a programming challenge to illustrate a use of generators. The solution to the problem given in that post was far from ideal – just a brute force hack, really. Today, let’s look at a respectable solution to the problem. Again, the problem: Imagine you are given a set of weights, each weight…

When Generators Are Brute Force Enablers

An interesting (if mysterious) programming challenge popped up in my business partner’s browser the other day. You’re given an odd set of weights which represents the series of powers of three. So, the first one is 1lb, the second 3lbs, the third 9lbs, the fourth 27lbs, etc. You also have a scale. If someone puts…

Path to Y – Y

Last time we got two important steps closer to implementing the Y Combinator in C++: How to enforce "composition" on every call – by overloading the call operator, delegating its functionality to our call member function, but only after calling compose How to pull responsibility for making our FactorialWrapper class recursive out of the class…

Path to Y – Overloading

Last time, we’d found a way to (sort of) ape function composition in C++ by using Functors … modeled as classes that bundle the function to-be-made-recursive with a private member pointer to itself. The class exposess two public methods – compose and call – which are meant to correspond to the two stages that a…

Path to Y – Shallow Composition

Last time we saw how to pass "build" functions (i.e. return a function from a function that depends on the arguments passed to the outer function) in C++, even though C++ functions don’t really "do that." The trick is to wrap the return function in a class that can set private member variables which are…

Path to Y – Functors

In yesterday’s post we showed that the first part of Y – passing a function to another function – is not only possible but fairly easy in C++. What about returning one? As you might expect, that’s just as easy, though the signature can get a little awkward if you don’t use typedefs. Let’s start…

Path to Y – Function Pointers

Most of the stuff you read on the internet about the Y combinator works in functional languages. This only makes sense: the Y combinator comes from the Lambda Calculus, and functional languages allow you to implement Lambda Calculus concepts more or less directly in that functions are first-class values in those languages. What that means…