Skip to content

Missing error message for trying to define generic unions #257

@HalflingHelper

Description

@HalflingHelper
union TwoList<K, V> {
  nil
  vnode(V, TwoList)
  knode(K, TwoList)
}


postulate tl_induction : all T: type, E : type.
  all P : fn TwoList<T, E> -> bool.
  if P(nil) and (all k : T, tl : TwoList<T, E>. if P(tl)  then P(knode(k, tl)))
  then all x : TwoList<T, E>. P(x)

I ran into this while working on induction stuff, ignore the weird theorem, the error is

Exception: /home/calvin/Documents/Programming/343/deduce/blah.pf:38.75-38.77: expected a term of type TwoList
but got term tl of type TwoList<T,E>

        in context of call knode(k, tl)
        function type: (fn <K,V> K, TwoList -> TwoList<K,V>)
        inferred type arguments: K := T, V := E

The solution of course is to change the TwoList in the union declaration to TwoList<K, V>. Maybe it is important to have the ability to not instantiate types, but I would hazard a guess that this shouldn't be allowed. If so we should probably catch this error at the union declaration instead of when typechecking theorems.

It's also possible to do stuff where we swap the order of type parameters, making it impossible(?) to create a recursive function on the union.

union TwoList<K, V> {
  nil
  vnode(V, TwoList<V, K>)
  knode(K, TwoList<K, V>)
}

Again I'm not sure if we should do something about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions