4 ms·
Great argument as to why C++, though it works for functional programming in some technical sense, is far less than ideal.
by cgranade 16y ago
Great argument as to why C++, though it works for functional programming in some technical sense, is far less than ideal.
- Niten 16y agoIf you want to be picky, you might even say this doesn't really implement Church numerals in C++ (it implements them in the C++ compiler), since the conversion between integers and Church numerals takes place in compile time template expansion. What happens if you want to throw a new integer at this program at runtime? > You might have to pass -ftemplate-depth-1024 to g++ to get this compiled. Yeah, no kidding. Semantic arguments aside, this made my head hurt, and I've actually done a reasonable amount of C++ programming. For comparison, here are what Church numerals look like in Clojure, another language that (like Haskell) has first-class higher order functions: (defn church [n] (cond (= n 0) (fn [f x] x) (> n 0) (fn [f x] (f ((church (dec n)) f x))))) (defn unchurch [n] (n inc 0)) And it works at runtime.