Take the 2-minute tour ×


Despite the title, this is a genuine question, not an attempt at Emacs/Vi flamewars.


I've used Haskell for a few months, and written a small ~10K LOC interpreter. In the past year, I've switched to Clojure. For quite a while, I struggled with Clojure's lack of types. Then I switched into using defrecords in Clojure, and now, switched to Clojure's defprotocols.

I really really like defprotocols. In fact, more than types.

I'm now at the point where for my Clojure functions, for it's documentation string, I just specify:

* the protocols of the inputs
* the protocols of the outputs

Using this, it appears I now have an ad-hoc type system (not compiler checked; but human checked).


I suspect there's something about types that I'm missing. What does types provide over protocols?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Protocols create interfaces and interfaces are a well, the interface to a type. they describe some aspects of a type though with much less rigor than you would come to expect in a language like Haskell.

share|improve this answer
add comment
  • machine checking
  • type inference (you don't get some of your protocols generated from docs of others)
  • parametric polymorphism (parameterised protocols / protocols with generics don't exist)
  • higher order protocols (what is the protocol for a function that returns a protocol?)
  • automatic generation of code / boilerplate
  • inter-operation with automated tools
share|improve this answer
protocols are already polymorphic. protocols support delegation so you can implement a protocol which returns something which does implement the protocol allowing you to compose protocols quite easily. Some of your other points are true and some of them are irrelevant in the context of a Lisp. –  dnolen May 23 '12 at 17:11
can you explain the polymorphism one? i've added "parametric" since in this context i think it's clear the idea is to be explicit, no? also, the "irrelevant to lisp" seems odd since the whole idea is to make something less like lisp / compare with other languages. will look at delegation, though - thanks. –  andrew cooke May 23 '12 at 17:15
add comment

Your Answer

