[Grace-core] Should Grace abandon "gradual typing" for "like typing"?

Kim Bruce kbbruce47 at gmail.com
Thu Jul 28 05:58:43 PDT 2016


I think it is pretty clear we will use simple type inference for if
expressions.
On Wed, Jul 27, 2016 at 7:17 PM James Noble <kjx at ecs.vuw.ac.nz> wrote:

>
> > On 28/07/2016, at 5:02AM, Andrew P. Black <black at cs.pdx.edu> wrote:
> >
> > The object generated by the above code has dynamic type
> >
> >       interface {
> >               x -> Boolean
> >       }
>
> No, it has type
>
> >       interface {
> >               x -> Unknown
> >       }
>
> because the declaration of "if" has no declared return type.
> more simply, given the definition
>
> method min(a, b) {
>     if (a < b) then { a } else { b }
> }
>
> then any def (or indeed anything) that gets the value of min will have the
> Unknown (dynamic) type.  We could do a bit better by writing:
>
> method min[[T]](a : T, b : T) -> T {
>     if (a < b) then { a } else { b }
> }
>
> but if we call it as "min(1,2)" the resulting type is again Unknown.
> To get a return type of Number we'd have to write "min[[Number]](1,2)"
> We can statically infer that x should have type "Number", say,
> but at that point type inference is changing the behaviour of the program:
> the type inference algorithm is changing the dynamic types of objects in
> the program.
>
> James
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20160728/ee04ac7c/attachment.html>


More information about the Grace-core mailing list