When would you use language plait & when would you use language typed/racket?

When would you use language plait & when would you use language typed/racket ?

Typed Racket is Racket with types. If you "just" want to add types to your Racket programs, use Typed Racket.

Plait and PLAI are both typed dialects of Scheme, and seem to be teaching languages. An example of a difference seen in the docs, is that Plait lists must have a uniform type, while Typed Racket can handle something like '(a 1) via the type (List 'a One). PLAI seems to be even more restricted for teaching purposes, e.g. all modules export every single definition.

So, I'd say, don't use Plait or PLAI unless you know what they are for. Disclaimer: I don't :smiley:

1 Like

Alain De Vos via Racket Discussions
notifications@racket.discoursemail.com writes:

When would you use language plait & when would you use language typed/racket ?

Plait is designed to go with the book "Programming Languages:
Application and Interpretation" (plai.org). So the main reason to use it
would be if you were reading that book. It also has (IMHO) nicer type
inference, but that comes at the cost of being a more restricted
language. So I guess if you wanted a small language with the feel of SML
(but with more parens), then you might also like plait.

d

2 Likes

I don't mind parens but i find the type-system very important. That's why i also use ocaml.

Yes, it definitely sounds like you're looking for Typed Racket. You might also be interested in the differences between OCaml's type system and Typed Racket; occurrence typing is an interesting new thing.

1 Like

I have the book "Programming Languages: Application and Interpretation" next to me.
I'll use typed-racket for the examples.
[ The differences will not be big in comparison to "PLAIT"]

Re (& Language plait and gui): Typed Racket is a typed version of Racket, which has the type system designed for

  • safe and sound interoperability with Racket
  • typing idiomatic Racket programs, including logical types and occurrence typing
    (if (integer? x) #| integer? is not just Any -> Bool but also gives information on the type of x |#
        (+ x 3) #| x has type Integer in this branch |#
        ... #| x has type SOMETHING - {Integer}, roughly |#)
1 Like

I want to represent an abstract-syntax-tree.
I think about a union-type of structure-types.
But the element of a structure-type can be the previous defined union-type.
So i must define the two types together in order for it the be understood by racket.

Racket does not have a built-in construct for ML-style algebraic data types so neither does Typed Racket. And yes, an approach is to define a struct type for each of the variant you want and define a recursive union type just like this example:
https://docs.racket-lang.org/ts-guide/beginning.html#(part._.Datatypes_and_.Unions)

  #lang typed/racket
  (define-type Tree (U leaf node))
  (struct leaf ([val : Number]))
  (struct node ([left : Tree] [right : Tree]))
   
  (: tree-height (-> Tree Integer))
  (define (tree-height t)
    (cond [(leaf? t) 1]
          [else (max (+ 1 (tree-height (node-left t)))
                     (+ 1 (tree-height (node-right t))))]))
...
1 Like

This is my first idea for a simple-calculator.

#lang typed/racket
(struct num ([n : Number]))
(struct myop ([ o : String ]))
(define-type ExpT (U ExpTL ExpTN))
(define-type ExpTL num)
(define-type ExpTN (Pair myop (Pair ExpT ExpT)))