
Dynamic Dispatch in Haskell - runeks
https://two-wrongs.com/dynamic-dispatch-in-haskell-how-to-make-code-extendable
======
Sharlin
As they say, (objects|closures) are a poor man's (closures|objects).

The pertinent point is that you don't need runtime _typing_ to implement
runtime _dispatch_. OO languages are based on associating behavior with
_types_ when all you need is to associate behavior with _values_. Or in other
words, functions that are first-class values.

------
aban
Discussion on /r/haskell:
[https://www.reddit.com/r/haskell/comments/6a5e0v/dynamic_dis...](https://www.reddit.com/r/haskell/comments/6a5e0v/dynamic_dispatch_in_haskell_or_how_can_i_make_my/)

------
agentgt
Its funny because I basically asked a question a long time ago on SO on how to
handle similar problems: [http://stackoverflow.com/questions/2807629/handling-
incremen...](http://stackoverflow.com/questions/2807629/handling-incremental-
data-modeling-changes-in-functional-programming)

<strike> And I'm thinking the gentleman that answered might actually be the
same person as the author. </strike> ... probably not but the answer reminds
me of this article.

~~~
chowells
Well, I don't know of anyone with haskell experience who hasn't used this
basic pattern occasionally. It's just how you do it.

Thjs article introduces an extra twist or two, but the basic idea doesn't
change.

------
zzalpha
Uh, this isn't dynamic dispatch (aka associating a function callsite to its
implementation at runtime):

[https://en.m.wikipedia.org/wiki/Dynamic_dispatch](https://en.m.wikipedia.org/wiki/Dynamic_dispatch)

It's just pattern matching and lamdbas. In another language you'd probably do
the same thing with a map containing commands as keys and lambdas as values.

