On Thu, 10 Dec 2015 13:18:57 -0600,
Gustavo Massaccesi wrote:
> 
> IIRC, the only numeric type that are singletons are Zero and One, so
> this also typechecks:
> 
> (+ 1 (if (= 0 (- 0 0)) 1 "x"))

There's a few more, actually, like the various floating-point zeroes.

> On a related note, the (untyped)Racket optimizer has constant folding,
> so in (untyped)Racket all these expressions are compiled to 2. I don't
> know if it's possible to add constant folding to Typed Racket.

It would be possible to add constant folding, and other optimizations to
TR. That would essentially involve redoing the same analyses and
transformations that the Racket compiler already does, though, which
would lead to (conceptual) duplication. Instead, TR's MO is to use type
info to arrange code to make the Racket compiler's job easier (e.g.,
make type-dead code obviously dead, so the Racket compiler can DCE it).

My dream is that, instead, the Racket compiler could make its own
analyses and transformations available as hooks, just as it makes other
kinds of hooks available. :) Think of it as a "cp0 [1] as a library",
that #langs and language extensions could reuse.

Vincent


[1] After Chez's first compilation pass, which does the usual
    simplification / cleanup optimizations.

> 
> Anyway, other obvious expressions like
> (lambda (x) (+ 1 (if (eq? x x) 1 "x")))
> are not reduced (currently).
> 
> Gustavo
> 
> 
> On Thu, Dec 10, 2015 at 3:12 PM, Vincent St-Amour
> <stamo...@eecs.northwestern.edu> wrote:
> > Right.
> >
> > The key distinction here is that TR is not so much reasoning about
> > constants, but about a singleton type. So TR is still working in terms
> > of types, not in terms of concrete values.
> >
> > Vincent
> >
> >
> >
> > On Thu, 10 Dec 2015 11:55:24 -0600,
> > 'John Clements' via Racket Users wrote:
> >>
> >>
> >> > On Dec 10, 2015, at 9:50 AM, George Neuner <gneun...@comcast.net> wrote:
> >> >
> >> > On Thu, 10 Dec 2015 12:35:34 -0500, Alex Knauth
> >> > <alexan...@knauth.org> wrote:
> >> >
> >> >> In typed racket (- 1 1) and (- 2 2) are equal at runtime, but the type
> >> >> checker doesn't necessarily know that at compile time. It knows that
> >> >> (- 1 1) is zero because that's a special case in the type system. But it
> >> >> doesn't have a special case for (- 2 2), so it only knows that that's a
> >> >> Fixnum.
> >> >
> >> > But in this case the type checker isn't dealing with variables.  Which
> >> > begs the question why is (- 1 1) special cased?  Shouldn't there be a
> >> > general rule: (- C C) where C is a numeric constant?
> >> > [Ok, I know equality is a problem with floating point ... but, still,
> >> > the principle remains.]
> >>
> >> Check out the numeric tower in TR: there’s a type that includes just the 
> >> number 1. The natural extension to all numbers (each number has its own 
> >> type) leads (IIUC) to a totally intractable type system.
> >>
> >> John
> >>
> >> >
> >> > George
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Racket Users" group.
> >> > To unsubscribe from this group and stop receiving emails from it, send 
> >> > an email to racket-users+unsubscr...@googlegroups.com.
> >> > For more options, visit https://groups.google.com/d/optout.
> >>
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Racket Users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an 
> >> email to racket-users+unsubscr...@googlegroups.com.
> >> For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to