[racket] Typed Racket vs. Haskell

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Tue Sep 18 16:41:31 EDT 2012

At Tue, 18 Sep 2012 16:08:29 -0400 (EDT),
thorsopia at lavabit.com wrote:
> 
> > 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.
> 
> Are you talking about this?

I'm mostly talking about different ways to structure data.

In Haskell, you would structure data like this:

    data Tree = Branch Tree Tree
              | Leaf Integer

A direct Typed Racket translation is:

    (define-type Tree (U Branch Leaf))
    (struct: Branch ([left : Tree] [right : Tree]))
    (struct: Leaf   ([val : Integer]))

The same program, written "Racket-style":

    (define-type Tree (U Branch Integer))
    (struct: Branch ([left : Tree] [right : Tree]))

Typed Racket's union types makes it possible to write this program
without the extra constructor. In this example, the savings are small,
but it can simplify code a lot in larger cases.

> > 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.
> 
> Very interesting.
> I'm going to write a library. I want it to be available for the largest
> number of people.
> Can other Lisp-like languages (e.g. Guile) use libraries written in Typed
> Racket?

Typed Racket can interact with other languages in the Racket ecosystem.
This does not include Guile.

> > Of course, Haskell also provides type system features that Typed Racket
> > does not, such as type classes or type-level programming.
> 
> Is there a need for such features in Typed Racket?
> Is it possible to implement them?
> Is there a plan to implement them?

As John said, Typed Racket has a different philosophy than Haskell. Some
of Haskell's features would not make sense in Typed Racket. Others
provide functionality that would be nice to have (e.g. type classes),
but it's unclear whether Haskell's solutions would be appropriate in our
case. Feature parity with Haskell is explicitly not a goal for Typed
Racket.

If you're looking for a cool typed language with interesting new ideas
that bring the best of typed and untyped languages together, then you'll
love Typed Racket. If you're looking for a Haskell relative, Typed
Racket may not be for you.

Vincent

Posted on the users mailing list.