cruxlang / crux

Crux Programming Language
http://cruxlang.org
Other
51 stars 2 forks source link

mutable type should be quantified and instantiated #171

Open chadaustin opened 7 years ago

chadaustin commented 7 years ago

This program fails to typecheck:

fun f() {
  return mutable []
}

fun main() {
  let a = f()
  a->append("hello")
  let b = f()
  b->append(1)
}

@andyfriesen any ideas?

andyfriesen commented 7 years ago

I think this is safe.

chadaustin commented 7 years ago

@andyfriesen Any gut sense as to why the type checker fails this program?

andyfriesen commented 7 years ago

Since the array is mutable, the type variable isn't being universally quantified. It's being made weakly polymorphic. This is the machinery that prevents us from making a forall a. IORef (Maybe a).

We need to think for a bit to really understand what the rules for weak polymorphism are if we want this case to work.