[racket] typed racked questions

67 views
Skip to first unread message

Bikal Gurung

unread,
Apr 30, 2012, 12:51:00 AM4/30/12
to us...@racket-lang.org
Hi All,

I am investigating typed racket. I was wondering if someone could help with answering the questions below. 

1) Can we mix/import modules written in untyped racket to a module that is used typed racket. I have experimented with a few modules using and they seem to work in general but not really sure about the mechanism that makes it work. How does racket make the untyped code and typed code work together if they do? Is this in a case by case basis, ie. module/library by library basis?

2) What is the canonical racket paradigm? use typed racket or untyped racket? Or is this more an issue of a preference/style?

3) Are typed racket programs faster than untyped ones? The documentation says so but I was wondering if there has been any benchmark or study being done on this topic.

4) Can typed racket module be used in the context of untyped racket module?

5) Is there a Hindlye/Milner style type inferencing algorithm for typed racket being worked on?

With Thanks
Bikal

Vincent St-Amour

unread,
Apr 30, 2012, 8:34:55 AM4/30/12
to Bikal Gurung, us...@racket-lang.org
At Mon, 30 Apr 2012 05:51:00 +0100,
Bikal Gurung wrote:
> 1) Can we mix/import modules written in untyped racket to a module that is
> used typed racket. I have experimented with a few modules using and they
> seem to work in general but not really sure about the mechanism that makes
> it work. How does racket make the untyped code and typed code work together
> if they do? Is this in a case by case basis, ie. module/library by library
> basis?

Contracts are applied at the boundaires between types and untyped
code. These contracts check that whathever comes from an untyped module
respects the typed module's invariants. Contracts are generated from
types, so this works for any module.

> 2) What is the canonical racket paradigm? use typed racket or untyped
> racket? Or is this more an issue of a preference/style?

It's a matter of preference, I would say.

Typed Racket was designed to make it easy to port untyped Racket code to
it. It's possible to write your programs in untyped Racket, then as the
code base grows larger, add types one module at a time.

> 3) Are typed racket programs faster than untyped ones? The documentation
> says so but I was wondering if there has been any benchmark or study being
> done on this topic.

Typed Racket does perform optimization. Whether or not they apply
depends on the program. If you want to know if your program benefits
from Typed Racket's optimizations, click the Performance Report button
in DrRacket and green highlights will appear where optimizations were
performed. You can click these highlights for more information.

As for benchmarks, check out:
http://www.ccs.neu.edu/racket/pubs/pldi11-thacff.pdf

> 4) Can typed racket module be used in the context of untyped racket module?

Yes, you can require a Typed Racket module from a Racket module.

> 5) Is there a Hindlye/Milner style type inferencing algorithm for typed
> racket being worked on?

Currently, Typed Racket performs local type inference. It can infer most
types inside function bodies, but it requires type annotations for
functions. Global type inference would be nice, but we don't know how to
do it. Several features of the type system make inference hard.

Vincent
____________________
Racket Users list:
http://lists.racket-lang.org/users

Sam Tobin-Hochstadt

unread,
Apr 30, 2012, 8:48:38 AM4/30/12
to Bikal Gurung, us...@racket-lang.org
On Mon, Apr 30, 2012 at 12:51 AM, Bikal Gurung <gbi...@gmail.com> wrote:
> Hi All,
>
> I am investigating typed racket. I was wondering if someone could help with
> answering the questions below.
>
> 1) Can we mix/import modules written in untyped racket to a module that is
> used typed racket. I have experimented with a few modules using and they
> seem to work in general but not really sure about the mechanism that makes
> it work. How does racket make the untyped code and typed code work together
> if they do? Is this in a case by case basis, ie. module/library by library
> basis?

Yes, you can mix typed modules and untyped modules in the same
program. This is one of the most fundamental features of Typed
Racket. To use a typed module from an untyped module, just require it
-- contracts are inserted automatically to check the operation. To
use an untyped module from a typed module, use `require/typed' to
specify the type.

> 2) What is the canonical racket paradigm? use typed racket or untyped
> racket? Or is this more an issue of a preference/style?

This is very much an issue of style. I think there are a number of
advantages of type systems for maintenance, optimization,
documentation, and organization, so I encourage you to use Typed
Racket. However, if you use plain Racket, Typed Racket is designed to
make it easy to switch, a module at a time, when you decide you want
types.

> 3) Are typed racket programs faster than untyped ones? The documentation
> says so but I was wondering if there has been any benchmark or study being
> done on this topic.

Yes, Typed Racket has an optimizing compiler (by Vincent St-Amour)
which uses the type information to make your program go faster. You
can see some benchmark results in our papers
http://www.ccs.neu.edu/racket/pubs/padl12-stff.pdf and
http://www.ccs.neu.edu/racket/pubs/pldi11-thacff.pdf .

> 4) Can typed racket module be used in the context of untyped racket module?

Yes, you can just `require` the typed module, and it should work.

> 5) Is there a Hindlye/Milner style type inferencing algorithm for typed
> racket being worked on?

The Typed Racket type system contains a number of features that go
beyond what's supported in Hindley/Milner style type systems, and so
we can't use that inference system. Currently, Typed Racket uses
local type inference to infer many of the types in your program, but
we'd like to infer more of them -- this is an ongoing area of
research. However, inferring all the types in the program, the way
that ML and Haskell do, is not a goal of Typed Racket -- having type
annotations there makes the program self-documenting and easier to
understand, improves type error messages, and supports advanced type
system features.

Thanks for your interest in Typed Racket, and if you have any more
questions, please ask.
--
sam th
sa...@ccs.neu.edu

Ray Racine

unread,
Apr 30, 2012, 9:50:55 AM4/30/12
to Bikal Gurung, us...@racket-lang.org
User Testimonial.  I migrated exclusively to TR awhile back and prefer it immensely.  

On Mon, Apr 30, 2012 at 12:51 AM, Bikal Gurung <gbi...@gmail.com> wrote:

Bikal Gurung

unread,
Apr 30, 2012, 10:57:24 AM4/30/12
to Ray Racine, us...@racket-lang.org
Hi Ray,

Are you using this in your day to day programming? What sort of projects do you use this for ? Do you use untyped racket in the beginning, i.e when you are experimenting with ideas/algorithms and then migrate to typed racket ? Have you used typed racket when developing web applications with the racket web libs?

Much Thanks
Bikal

Jay McCarthy

unread,
Apr 30, 2012, 1:10:18 PM4/30/12
to Bikal Gurung, us...@racket-lang.org
On Mon, Apr 30, 2012 at 8:57 AM, Bikal Gurung <gbi...@gmail.com> wrote:
> Hi Ray,
>
> Are you using this in your day to day programming? What sort of projects do
> you use this for ? Do you use untyped racket in the beginning, i.e when you
> are experimenting with ideas/algorithms and then migrate to typed racket ?
> Have you used typed racket when developing web applications with the racket
> web libs?

FWIW, We are currently in the process of natively typing the Web libraries.

Jay

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Bikal Gurung

unread,
Apr 30, 2012, 1:30:17 PM4/30/12
to Jay McCarthy, us...@racket-lang.org
Interesting. What is the status of this project? Is this going to be in the next release.

Bikal

Bikal Gurung

unread,
Apr 30, 2012, 5:23:01 PM4/30/12
to Sam Tobin-Hochstadt, us...@racket-lang.org
Sam,

Is there a function in racket which will - given a name - display the function/variable signature in the REPL?

I am thinking about haskell prelude(REPL) that gives me the type signature when I enter :t <func name> in the repl?

With Thanks
Bikal

Vincent St-Amour

unread,
Apr 30, 2012, 5:54:40 PM4/30/12
to Bikal Gurung, us...@racket-lang.org, Sam Tobin-Hochstadt
The REPL prints types automatically:

Welcome to Racket v5.3.0.4.
-> vector-ref
- : (All (a) ((Vectorof a) Integer -> a))
#<procedure:vector-ref>
-> (define: x : String "Hello")
-> x
- : String
"Hello"
->


Is this what you had in mind?

Vincent



At Mon, 30 Apr 2012 22:23:01 +0100,
Bikal Gurung wrote:
>
> [1 <multipart/alternative (7bit)>]
> [1.1 <text/plain; ISO-8859-1 (7bit)>]
> [1.2 <text/html; ISO-8859-1 (quoted-printable)>]
>
> [2 <text/plain; us-ascii (7bit)>]

Bikal Gurung

unread,
Apr 30, 2012, 6:07:38 PM4/30/12
to us...@racket-lang.org
hmmm ... I am getting some error. My repl session below. I am using 'db' module. 

> bind-prepared-statement
. Type Checker: untyped top-level identifier lifted.474 in: bind-prepared-statement

Not sure what to make of it. My impression was the typed/untyped code mix well. Am i missing something ??

Bikal 

Bikal Gurung

unread,
Apr 30, 2012, 6:12:35 PM4/30/12
to us...@racket-lang.org
What are DrRacket and other racket libs written in ? typed/untyped racket ? 

On Mon, Apr 30, 2012 at 1:48 PM, Sam Tobin-Hochstadt <sa...@ccs.neu.edu> wrote:

Ray Racine

unread,
Apr 30, 2012, 8:47:30 PM4/30/12
to Bikal Gurung, us...@racket-lang.org
See below.

On Mon, Apr 30, 2012 at 10:57 AM, Bikal Gurung <gbi...@gmail.com> wrote:
Hi Ray,

Are you using this in your day to day programming?

Most of my home programming is in Racket. 
Work is split 75%-10%-15% Scala, R and Racket respectively.
 
What sort of projects do you use this for ?

At work I use Racket for large scripts and data massaging and manipulations.  Most of to get things collected and shaped up in a form to load it into R. :)

At home, I tend to average one multi-million dollar idea a quarter, which are explored and abandoned on a regular basis without making a dime.  I find this exercise in futility endlessly fun and Racket is great for this sort hamster wheel spinning.   The quicker you can explore, the sooner the realization of just how brain dead that brilliant idea really was is achieved.

Do you use untyped racket in the beginning, i.e when you are experimenting with ideas/algorithms and then migrate to typed racket ?

When I sit to do something there are only two possibilities Scala or (typed) Racket.  For any sort of quick exploration I use TRacket.  Typed Racket is so light weight to use, what code I write is typed.  #lang typed/racket/base first thing, every time, in every new module without hesitation.   In other words I do not code in Racket and then later go back on type the code.  Too easy to just use TR from keystroke one.

Awhile back I wrote some code to generate a Formal Concept Analysis lattice for around 100K Amazon genre ebooks with various attribution.  This was the only time I've written a modest, yet nontrivial program twice, once in TR and once in Scala.

The first effort was from the algo's paper/publication to TR.  The second effort was in Scala.  I distinctly remember expecting the Scala effort to go pretty fast, as after all I'd already written it once.

Unexpectedly, the Scala effort took more time than I thought it should.  It was not a Scala issue per se, but an OO-centric language with support for functional idioms versus a Functional-centric languge with support for OO idioms.  I much prefer the later.   

Data in structures.  Apply functions, transform data, repeat until expected output is reached.  Sometimes its just hard to keep mapping and jamming things relentlessly into classes and it is entirely too easy to paint yourself into a corner with your OO structure.

Also with TypedRacket I find I get more meta-level in my programming in a Haskell kind of way than when I did regular Racket programming, i.e.,  pass more functions, compose more functions etc.  Typed Racket allows one to just keep layering the abstractions without losing the plot.

Things like ...
(: map/try-or-else (All (T U) (Try T) (T -> U) (exn -> U) -> (Try U)))

Now Scala is hands down a BRILLIANT work in language design.  My admiration is unbounded.  And I use it willing and often, especially at work, on all kinds of stuff.

Have you used typed racket when developing web applications with the racket web libs?

Never really had a need to.  But when I need it, it is good to know that Jay, as posted in this thread, is migrating the web code to TR.

Hendrik Boom

unread,
May 1, 2012, 11:58:10 AM5/1/12
to us...@racket-lang.org
On Mon, Apr 30, 2012 at 08:48:38AM -0400, Sam Tobin-Hochstadt wrote:
>
> > 5) Is there a Hindlye/Milner style type inferencing algorithm for typed
> > racket being worked on?
>
> The Typed Racket type system contains a number of features that go
> beyond what's supported in Hindley/Milner style type systems, and so
> we can't use that inference system. Currently, Typed Racket uses
> local type inference to infer many of the types in your program, but
> we'd like to infer more of them -- this is an ongoing area of
> research. However, inferring all the types in the program, the way
> that ML and Haskell do, is not a goal of Typed Racket -- having type
> annotations there makes the program self-documenting and easier to
> understand, improves type error messages, and supports advanced type
> system features.

ML and such go too far. Don't go there. I really like having
tatically checked type annotations. They make life a lot easier.
It's types I want, not typability,

-- hendrik

Sam Tobin-Hochstadt

unread,
May 1, 2012, 12:03:49 PM5/1/12
to Hendrik Boom, us...@racket-lang.org

I agree with this. The reason that we are looking at more inference
for Typed Racket is two-fold:

1. Currently, Typed Racket requires annoying type annotations that
don't add any useful information, such as:
(map (lambda: ([x : Integer]) (+ x 4)) (list 1 2 3))
Fortunately, there are systems that solve this, while preserving the
other nice properties Typed Racket has.

2. Macro-generated code from macros that aren't typed (like `for')
often needs more inference than we currently provide, leading TR users
to have to avoid those macros, or us to have to provide alternative
implementations that don't work in all cases. I hope that improving
inference will alleviate some of this problem.

--
sam th
sa...@ccs.neu.edu

Vincent St-Amour

unread,
May 1, 2012, 12:38:47 PM5/1/12
to Bikal Gurung, us...@racket-lang.org
At Mon, 30 Apr 2012 23:07:38 +0100,
Bikal Gurung wrote:
> hmmm ... I am getting some error. My repl session below. I am using 'db'
> module.
>
> > bind-prepared-statement
> . Type Checker: untyped top-level identifier lifted.474 in:
> bind-prepared-statement
> >
>
> Not sure what to make of it. My impression was the typed/untyped code mix
> well. Am i missing something ??

Did you use `require' or `require/typed'?

Vincent

Vincent St-Amour

unread,
May 1, 2012, 12:47:40 PM5/1/12
to Bikal Gurung, us...@racket-lang.org
At Mon, 30 Apr 2012 23:12:35 +0100,
Bikal Gurung wrote:
> What are DrRacket and other racket libs written in ? typed/untyped racket ?

DrRacket is written in untyped Racket, with a bit of Typed Racket.

Most libraries are untyped, but some are typed (quickly skimming the
PLaneT listing: purely functional data structures, json template, ...)
Some have typed internals and untyped interfaces (e.g. the images
collection). I'm probably forgetting some.

Vincent

Jay McCarthy

unread,
May 1, 2012, 1:49:53 PM5/1/12
to Bikal Gurung, us...@racket-lang.org
It will not be in the release. It is an undergrad's summer project.
It's in the early stages now, so nothing more to say really. A big
problem will that Typed Racket is very primitive w.r.t to Racket
features like keyword arguments and structure properties that are used
in the server.

Jay

Reply all
Reply to author
Forward
0 new messages