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

sentinel value for recursive types #4

Open
davidchambers opened this issue Oct 29, 2016 · 1 comment
Open

sentinel value for recursive types #4

davidchambers opened this issue Oct 29, 2016 · 1 comment

Comments

@davidchambers
Copy link
Member

Haskell:

data List a = Nil | Cons a (List a)

JavaScript:

const List = Type({Nil: [], Cons: [a, undefined]});

There's also a hack which looks better but relies on confusing JavaScript behaviour and doesn't work with const.

If we're to use a sentinel value (such as undefined), why not use one which is more descriptive? We could support one of the following:

const List = Type({Nil: [], Cons: [a, Type.Self]});
const List = Type({Nil: [], Cons: [a, Type.Recur]});
const List = Type({Nil: [], Cons: [a, Type.Recursive]});

The value of Type.Self (or whatever we were to call it) could simply be undefined, but I'd prefer something like {'@@functional/recursive-type-reference': true}.

What do you think, @JAForbes? Do you agree that one of these would be better than undefined? If so, what would you like the property to be named?

@davidchambers davidchambers mentioned this issue Oct 29, 2016
6 tasks
@JAForbes
Copy link
Member

@davidchambers I think a sentinel makes for a cleaner/clearer API. Whichever name you prefer is fine with me. I also agree an explicit value for the recursive type reference is a better choice.

Pending your decision on #6 of course, I say 👍

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

2 participants