3 ms·
Dynamic Dispatch in Haskell
- Sharlin 10y agoAs 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 10y agoDiscussion on /r/haskell: https://www.reddit.com/r/haskell/comments/6a5e0v/dynamic_dispatch_in_haskell_or_how_can_i_make_my/ https://www.reddit.com/r/haskell/comments/6a5e0v/dynamic_dis...
- agentgt 10y agoIts 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-incremental-data-modeling-changes-in-functional-programming 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.
- chowells 10y agoWell, 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 9y agoUh, 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.