sum-types icon indicating copy to clipboard operation
sum-types copied to clipboard

Support for generic sum types

Open samhh opened this issue 3 years ago • 1 comments

A tracking issue for if this ever becomes viable. In the meantime we should document the challenges faced.

samhh avatar Sep 17 '21 16:09 samhh

A new issue has arisen with this as of #45. Where the following was (maybe?) working before, the type system is now unable to determine if A constitutes the value of a nullary constructor (comparison against null here):

type X<A> = Sum.Member<'X', A>
const getX = <A>() => Sum.create<X<A>>()

const f = <A>() => {
  const X = getX<A>()
  X.mk.X // Sum.Constructor<X<A>, "X", A>
}

This extends to subtyping constraints. Changing A on f to for example A extends string makes no difference as, as far as the type system is concerned, A could be string & null.

Could this be solved by representing nullary values with a symbol and switching out to null when (de)serialising? Depends how the typechecker treats unique symbols.

samhh avatar Sep 05 '22 21:09 samhh