Friday, July 11, 2014

A Category Theory Program for Concrete Thinkers

Finally some Haskellish content!

Anyway, it's taken me a few times of tilting at the Category Theory windmill to finally start to grasp it. One of my friends requested that I let him in on what finally worked for me, so this is for him. These videos by Steve Awodey were what really broke the logjam for me. Steve is good lecturer, and his presentation of the material works from the ground up. The best thing about those videos is that he gives examples of all of the concepts and explains what they are good for. I wish there were more of them; they don't cover a lot of ground.

Sunday, June 29, 2014

Handling Exceptions in C++ Testing

More C++ content.  Maybe I need to rename this blog.  

The other day I was writing some throwaway code, and I ran into a situation I've seen before:  some of my test code was (correctly) throwing an exception.  My immediate reaction was the wrap it in a try block.  But that only led to more try blocks, and some pretty smelly code.  So I whipped up a  template that would take a lambda as a argument, and would crash the program if the lambda didn't emit an exception when called.

Sunday, May 25, 2014

Composing Lambdas in C++14 -- and Functions, Too!

In my most recent post, I mentioned the interesting lambda changes coming in C++14 (aka C++1y). This post will follow up on that, and provides some methods for exploiting those new lambdas. The C++14 lambda functionality is already available in Clang 3.4; all the code in this post was tested with that compiler.

Last time, I gave a shout out to this blog post by Sumant Tambe, who listed a number of very interesting things enabled by the draft standard. There's one significant new usage that Sumant didn't remark on, though, and that is composition. The new feature that enables these usages is generic lambdas, which are declared with a type of auto. The compiler uses template argument deduction to build the actual type of a generic lambda; that actual type is an anonymous template.

Tuesday, May 6, 2014

The New C++14 Lambdas

This post isn't directly Haskell related, but should be of interest to C++ programmers who like Haskell.
So I've had a look at the new C++14 Lambdas. I'm still absorbing them, but they definitely are a big improvement over the C++11 version. See this blog post by Sumant Tambe for a first taste.
A clear win here is that std::bind, that gawdawful mess, is a thing of the past. You can assign lambdas to auto variables, you can return them directly -- they are darn near really and truly first class. There's a way to define 'id' and some ways to make it useful. You can compose functions, too. Though you have to define the composition operator yourself, and I suspect that you will get template error hell if you mismatch your types. We will have to see what Clang can do about that.
It doesn't look like the standard itself adds any support for function composition, maps/folds, and such. But it does look like those are all attainable, so I fully expect to see some supporting libraries coming out from the likes of Boost. With luck, they will even be in the Standard Library for C++17 or C++20.
Next up, typeclasses!
Sadly joking about that last one. Concepts Lite seems to have been put off until at least C++17.