[edit: apparently my sarcasm was too subtle. HOF and typeclasses are both vitally important pieces of Haskell, which are orthogonal to each other. I'm pretty sure both were in Haskell from day 1. Some code for which both are essential:
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
fail :: String -> m a
][] This statement is based purely on my own experience. I find the Haskell documentation a bit unfriendly with its "academic" style. The content is great, but the form makes it a bit hard to assimilate. Monads were especially painful.
Here's a paper introducing them.
What do you mean? From what I've seen, everyone uses typeclasses in Haskell.
interface MouseClickListener {
void mouseClicked(MouseEvent e);
}
one often uses an anonymous class to do so: void init() {
mouse.setClickListener(new MouseClickListener() {
void mouseClicked(MouseEvent e) {
println(e);
}
});
}
the exact effect could be achieved with a reference to a named function (if Java supported them, which presumably it will once "everything is an object"): void init() {
void mouseClick(MouseEvent e) { println(e); }
mouse.setClickListener(mouseClick);
}
given that interfaces are simply syntax for function routing, when you have the ability to reference functions by first-class types (i.e. you have the ability to determine function routing yourself), the set of things that you can only sensibly do with interfaces is a lot smaller.This is how C# delegates work, right? Any Java -> C# programmer want to comment on whether they rely less on interfaces now and what they use them for?
There are plenty of cases where you really need to pass an object to a function and know that the object supports multiple operations, for instance take a look at Map<K,V>: http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
There are 14 methods there, and when I write code that takes a Map object, I really mean it - I'm not just using the interface as a hack because I want a function pointer, I need an object that supports all of those methods, and I'm probably going to be using several of them.
I think both concepts are probably independent of one another.
Interfaces still serve a purpose bundling together related operations with replaceable implementations. They're just a nuisance for single-purpose functions/functors (e.g. - "run").