5 ms·
This is why I hate C++ template<template<class> class f1, template<class> class f2> struct or_combinator Incidentally, his or_combinator example is more s
by DannoHung 16y ago
This is why I hate C++
template<template<class> class f1, template<class> class f2> struct or_combinator
Incidentally, his or_combinator example is more simply expressed thusly:
or_combinator f1 f2 x = (f1 x) || (f2 x)
This has the same type signature. Anonymous functions are more useful in Haskell when you have some lexical context which needs to be captured and passed around. If partial application suffices, simply use partial application.
I suppose he was trying to demonstrate that the evaluation does not occur until the value is applied though, if the audience was more familiar with C++.
- eru 16y agoOr even simpler or_combinator = liftM2 (||) but that requires Haskell knowledge to understand. So you might see it in production code, but your version is the right one for the blog. And the original author's version may be even better for comprehension by C++ programmers.
- andymorris 16y agoWhen you get templates working, it does feel pretty good - you can get an approximation of the power of functional languages, all the while knowing that your code has been directly mapped to assembly. I don't know if it's as good as writing some neat functional code, but for me it's still fun!
- eru 16y agoIf you get a decent Haskell compiler working, say ghc, you get the same warm-fuzzy assembly-feeling.