Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can take <em>Polymorphism a la carte</em> as <em>Polymorphism on demand</em>. </p> <p>Clojure community are proud of the term <em>Polymorphism a la carte</em> because of the fact that Clojure support multiple polymorphism strategies. Some of them are:</p> <ul> <li><p><a href="https://stackoverflow.com/questions/5024211/clojure-adding-functions-to-defrecord-without-defining-a-new-protocol">Prototype-based polymorphism</a></p></li> <li><p>Inheritance polymorphism</p> <p>This is the polymorphism strategy used by Java. Clojure support this by proxy. Useful when doing Java interop.</p></li> <li><p>Protocol </p> <p>Protocol to Clojure is as TypeClass to Haskell.</p></li> <li><p>Multimethod</p> <p>While protocols provide polymorphic dispatch based on the type of the first argument, multimethods are much more flexible which can dispatch based on any function of the method's (any) arguments. </p></li> </ul> <p><em>Polymorphism a la carte</em> means "Select whatever polymorphism strategy best for your case. They're all in your toolbox."</p> <p>You can implement <code>TypeClass</code> pattern in Scala using implicits. Read <a href="https://github.com/scalaz/scalaz" rel="noreferrer">Scalaz source</a> if you want real world examples. Scala does not support multimethods at language level, but I guess it is possible with the help of the upcoming 2.10 macro. </p> <p>As for the benefits, advanced polymorphism strategies such as TypeClass and Multimethod can help solve the <a href="http://en.wikipedia.org/wiki/Expression_problem" rel="noreferrer">Expression Problem</a>. </p> <blockquote> <p>"The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts)".</p> </blockquote> <p>BTW, this question is too big to fit into a single StackOverflow question. My suggestion is to get familiar with these concepts, and then you'll understand their usefulness. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload