[Haskell-cafe] Functors and the Visitor Pattern

Tom.Amundsen tomamundsen at gmail.com
Wed Jun 3 09:10:30 EDT 2009

So, last night, I was having this problem with my Java code where I couldn't
figure out for the life of me how to write a piece of code without a big if
{} else if {} else if {} ... else {} structure. I was Googling "Java
Reflection" to try to determine how to "cast to the most concerete subclass
at runtime." Then it dawned on me that what I was trying to do has already
been solved by using the Visitor design pattern.

Then, after reading the Visitor design pattern page on Wiki, it said that
the visitor pattern is essentially an implementation of a functor. Aha! It
totally clicked. The Visitor pattern allows you to collect code for similar
operations, while spreading apart code for similar objects. Now that really
sounds like a functor!

Although, now I'm second guessing myself, because I can't figure out how we
could create some design pattern that simulates an applicative functor. I'm
pretty sure the Visitor pattern doesn't take you this far (but I am willing
to be corrected). So, is there a way to create applicative functors in
non-functional languages? What would that pattern look like?

- Tom
View this message in context: http://www.nabble.com/Functors-and-the-Visitor-Pattern-tp23851113p23851113.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list