Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for generic sum types #28

Open
samhh opened this issue Sep 17, 2021 · 1 comment
Open

Support for generic sum types #28

samhh opened this issue Sep 17, 2021 · 1 comment

Comments

@samhh
Copy link
Member

samhh commented Sep 17, 2021

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

@samhh
Copy link
Member Author

samhh commented Sep 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant