5 ms·
Just for my own sanity - is "multimethod" another term for a form of pattern matching? Looking at the clojure code, it strongly reminds me of Haskell: encou
by frio 15y ago
Just for my own sanity - is "multimethod" another term for a form of pattern matching? Looking at the clojure code, it strongly reminds me of Haskell:
encounter :: Species -> Species -> Result
encounter (Bunny _) (Lion _) = RunAway
encounter (Lion _) (Bunny _) = Eat
etc. Of course, pseudocode, syntax errors, whatever - but it looks to be the same idea?
edit - formatting
- thurn 15y agoA key difference is that Haskell functions can only have one type signature, so you need to explicitly make "Bunny" and "Lion" data constructors for "Species". Multimethods operate on multiple types. You can fake multimethods in Haskell with multi-parameter type classes (with the language extensions to allow undecidable and overlapping instances).
- frio 15y agoI see. Thanks!
- Jach 15y agoRich Hickey actually commented on the difference between multimethods and pattern matching here: http://sadekdrobi.com/2009/05/27/multimethod-in-clojure-should-i-call-it-first-class-pattern-matching-or-pattern-matching-in-disguise/#comment-15412 http://sadekdrobi.com/2009/05/27/multimethod-in-clojure-shou... (Here's a pattern matching module I know of: https://github.com/brool/clojure-misc https://github.com/brool/clojure-misc )