Hacker News new | past | comments | ask | show | jobs | submit login
Dynamic Dispatch in Haskell (two-wrongs.com)
73 points by runeks on May 11, 2017 | hide | past | favorite | 5 comments



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.



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...

<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.


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.


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

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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: