For example, the Visitor pattern can be naturally replaced with map and fmap in Haskell, which are far more powerful.
For example, the Visitor pattern can be naturally replaced with map and fmap in Haskell, which are far more powerful.
I guess it's all education in the end. At least now I appreciate the value of the tools I have.
class Read r where read :: String -> r
(Let's ignore parse errors for our purposes here)Haskell supports return-type polymorphism. Clojure, being dynamically typed, cannot in general support this kind of overloading.
I think it's a trade-off though. Can Haskell dispatch on a value rather than a type?
The Monad class actually depends on it too:
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
return :: a -> m a
The type of "return" can only be expressed with return-type polymorphism.This means you cannot really implement Haskell-like monads with dynamic typing. You have to implement them in a less general way.
As for dispatching on runtime values, that is ordinary pattern matching:
f (RuntimeValue1 x y) = ... case 1 ...
f (RuntimeValue2 x y) = ... case 2 ...Ahh, yeah I've heard this before. It totally slipped my mind.
>As for dispatching on runtime values, that is ordinary pattern matching
Can you extend the patterns of a function at runtime (or even across modules)?
you can do V with F
to which the reply was no, you can't do V with F
and the subsequent reply was but you can do V with M
and I pointed out that F does not imply V. Your current reply is Clojure has both F and M and can do V
which is obvious, since M implies V already, but still unrelated to what F can do.Here is the good explanation: http://www.haskell.org/pipermail/haskell-cafe/2009-June/0623... Haskell people are good at math
Since Haskell does not have sub-typing, everything has the same runtime type. However, you can easily combine different types into a single algebraic data type and then dispatch by pattern matching against that type.
This probably isn't exactly the same as double-dispatch in other languages, but it seems to be very similar and to serve the same purpose.
However, it was also about iterating an entire data structure (in the GoF example, a document hierarchy).
This creates confusion as some emphasize the former (multimethods! pattern matching!) and some emphasize the latter (fmap! map!).