Skip to content

type inference and mutable variables #1830

@backtracking

Description

@backtracking

Hello,

The following code does not type check:

var lst = empty
lst := link(1, lst)
print(1 + lst.first)

It complains that lst has type (List<?-1> % is-empty) and thus has no field named first.

On a related topic, I suspect that Pyret's type checker does not catch property the problem of polymorphic references (see the history of ML). For instance, the following code does type check:

fun head<a>(l :: List<a>) -> a:
  cases (List<a>) l:
    | empty => raise("head")
    | link(x, _) => x
  end
end

var lst = empty

lst := link(1, lst)
print(head(lst))

fun foo(n :: Number) -> Number: n end
lst := link(foo, lst)

print(head(lst)(1))

but it should not. Removing the second assignment leads to a runtime error (trying to apply something which is not a function).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions