4 ms·
I know they're working on higher kinded types, i think there's some fancy template-template syntax you can use in c++ to get the same effect. It's easy to defi
by jfoutz 11y ago
I know they're working on higher kinded types, i think there's some fancy template-template syntax you can use in c++ to get the same effect.
It's easy to define a list of integers in pretty much any language,
class IntList { void addInt(){...} }
Most languages let you make a generic List,
class List<T> { void add(T){...} }
The thing that's cool about HKT, is it lets you swap the other side,
class T<Integer> { T operate(Integer) }
So you can deal with a Set or a List or an Optional or whatever might want to deliver integers. It seems a little goofy, but it's sort of like a Super Lambda. an anonymous function can only really do its one thing, but this lets you bundle a bunch of related lambdas together, so if you have, say Pay, you can group together all the different types of tax that are applied to pay, calculate total tax, etc. And it works over whatever random data structure you want
It seems a little crazy at first, but with clean syntax, it's a fantastic way to split the work apart from the way the data is represented.