Schrodinger’s Yacc

There was a small controversy last year about parser combinators, a convenient way of rapidly developing parsers in a functional style. Yacc is presumably chosen as the archetypal non-combinator parser generator, requiring separate external parser compiler, known for being a pain to use.

Like Schrodinger’s cat, Yacc seems to be indeterminately alive or dead (though the last article conclusively opened the box for me).

Concepts: Typeclasses for C++?

I’ve had a hypothesis for a while that C++ templates (paired at times with ADL) are an ad-hoc, unsound version of typeclasses. I’ve seen this hold for parser combinators, range base algorithms, and more. I’m also not the first to draw this comparison[1].

Concepts are supposed to bring soundness in through constrained templates. Concepts look awfully a lot like type classes; they export functions and types, and are parameterized, and act as constraints on generic functions and other concepts. I checked the draft specification [2], and it even seems to permit parameterizing concepts on type constructors, just like Haskell! (er, C++ calls them class templates, not type constructors. to-may-to, to-mah-to)

But I worried I may be mistaken about concepts, as I’ve searched through google and literature and have yet to find a single example in literature demonstrating the use of template template concepts.

In case you’re curious what this might look like, here’s an educated guess:

concept Monad<template <> class m> {
  template<typename T, typename U>
  m<U> mbind(m<T>, function<m<U>(T)>);

  template<class T>
  m<T> mreturn(T);

template <template <typename> class m,
          class T,
          class U,
          class Iter>
requires M<m>
requires InputIterator<Iter, U>
m<T> foldM(Iter begin, Iter end, T i, function<m<T>(T, U)> f)
    if(begin == end)
        return mreturn(i);
        return mbind(f(i, *begin), [=](T result){
            Iter next = begin;
            return foldM(next, end, result, f);

Have template template concepts been covered thoroughly somewhere, and I’ve just missed it?

Repls, repls, everywhere

Have a new-years resolution to try out a new programming language, but in too much of a hurry to pick only one, or install anything?

Online REPs and REPLs

Today there’s 61 different languages on that list. That many, there’s gotta be at least one that strikes your fancy.

Best batch execution site: with 50 unique languages.

Best interactive REPL site: with 16 unique languages.