Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the similarities and differences between the typing features in Typed Racket and the type-like features in Clojure?

Clojure has some interesting features for representing types including but not limited to deftype, defprotocol, reify and extend.

What are the similarities and differences between the typing features in Typed Racket and the type-like features in Clojure?

like image 771
hawkeye Avatar asked Mar 04 '12 10:03

hawkeye


1 Answers

deftype and defprotocol define dynamic behavior in Clojure. In Racket, we'd do things like that with struct or struct-property, although there's nothing quite like defprotocol in Racket.

Edit: Racket now has generics, which are like Clojure protocols.

reify and extend, I think, correspond to uses of make-struct-type in Racket, which creates new structure types dynamically.

The big difference between Typed Racket, and all of these features, is that Typed Racket checks your program statically -- before trying to run it. You can't ever apply the wrong accessor in a Typed Racket program, or use a number as a function. You can't even run a program that might have an error like that.

Currently, the features of Clojure that are most like Typed Racket are the annotations it uses for performance.

Edit: There's now Typed Clojure by Ambrose Bonnaire-Sergeant, which is inspired and based on Typed Racket.

like image 79
Sam Tobin-Hochstadt Avatar answered Sep 24 '22 01:09

Sam Tobin-Hochstadt