On Thu, Sep 4, 2014 at 10:00 PM, Jonathan S. Shapiro <[email protected]> wrote:
> So first, yes, there is an error in TY_ARRAY. It should be "| TY_ARRAY of
> type literal"
That's what it already is. :)
>
> But even as written it would not allow "literal literal", because "literal"
> does not contain TY_ARRAY. The syntax "|TY_ARRAY of literal" creates a type
> constructor that has arguments. Think TY_ARRAY(type /* element type */,
> literal /* index type */).
`type` was defined as:
| type oneof TY_ARRAY | literal
So, in `type literal` one could substitute `literal` for `type`,
resulting in `literal literal`.
Ah, I think I've misunderstood what you mean by `type literal`. I've
been taking it as a type application. (In SML, type applications are
written strangely, e.g., `'a list`, instead of `list `a', but I was
assuming the latter kind of syntax.) Is looks like you instead mean to
describe the tuple:
| TY_ARRAY of type * literal
(using SML syntax). In that case, I understand.
If so, the following Typed Racket program defines the types you've described:
```racket
#lang typed/racket/base
(define-type AST (U LitChar LitBool Block IfExpr expr TyArray type))
(define-type expr (U Block IfExpr literal))
(define-type type (U TyArray literal))
(define-type literal (U LitChar LitBool))
(struct LitChar ([c : Char]))
(struct LitBool ([b : Boolean]))
(struct Block ([xs : (Listof AST)]))
(struct IfExpr ([test : expr] [if-true : Block] [if-false : Block]))
(struct TyArray ([ty : type] [idx : literal]))
```
In other words, I think the only thing necessary for the behavior you
want is true union types (as opposed to sum types). I don't know what
the impact is for type inference. Typed Racket certainly can't do
complete inference, but that's the result of a number of things. I
briefly glanced at
[http://www.cis.upenn.edu/~bcpierce/papers/uipq.ps], but I don't have
time to take a proper look right now.
-Jon
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev