[racket] Typed Racket vs. Haskell

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Tue Sep 18 13:51:20 EDT 2012

At Tue, 18 Sep 2012 09:55:36 -0700,
John Clements wrote:
> On Sep 18, 2012, at 8:30 AM, thorsopia at lavabit.com wrote:
> 
> > Hi,
> > 
> > I'm a beginner, but I have some experience with Scheme and Haskell.
> > 
> > Haskell is famous for its strict type system. Is it possible to achieve
> > this in a Lisp-like language? Is Typed Racket as strict as Haskell?
> > 
> > I'd like to see a comparison between the two.
> 
> Both Haskell and Typed Racket come from the Programming Languages
> community, and their type systems both arise from the same chain of
> research. They are both "type safe" systems (unlike, say, C), in that
> they produce proofs that some set of "bad things" can't happen.

Common Lisp falls in roughly the same category as C here. The compiler
does some compile-time checking and can detect some type errors, but it
errs on the side of trusting the programmer, which can lead to type
errors that other type systems would prevent.

> With that said, Haskell and Typed Racket represent two different
> "attitudes" within that design space: Haskell takes the attitude that
> the type system is a fundamental part of the program design, and typed
> Racket takes the attitude that the program comes first, and the type
> system's job is to check that nothing is going to go wrong.

It's also possible to write Typed Racket programs "types first", like
one would in Haskell, and I sometimes do. The "sums-of-products"
programming style of Haskell and ML can be expressed easily with Typed
Racket's structs and union types. You can also mix and match between
"Haskell" and "Racket" styles of programming, and it will all work.

You can even take this "mix and match" approach even further, and mix
typed and untyped code. Typed Racket modules can interact with untyped
Racket modules and contract checks at the boundary will prevent untyped
code from breaking the typed code. This is very handy, and is probably
the Typed Racket feature I find myself missing the most when programming
in Haskell or ML.

Some Typed Racket features provide flexibility that Haskell cannot
express, while keeping everything safe. For example, Typed Racket
supports variable arity functions (like Racket's `+', `list', `map',
etc.), dynamic type checks, optional and keyword arguments, etc.

Of course, Haskell also provides type system features that Typed Racket
does not, such as type classes or type-level programming.

Vincent

Posted on the users mailing list.