paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

proposal: unthunk nullary data constructors #54

Closed davidchambers closed 7 years ago

davidchambers commented 7 years ago
const List = Type({Nil: [], Cons: [x => true, List]});

I would like List.Nil to be the empty list rather than a nullary function which returns the empty list. It would make the examples in the readme slightly more elegant and slightly more similar to their Haskell equivalents.

Is there are reason to favour List.Nil(), @paldepind? If not, are you open to a pull request?

paldepind commented 7 years ago

I think the reason is that it was simplest to implement. But I definitely agree that it would be much nicer to simply have it be a constant. Nullary functions are ugly and unnecessary in a pure setting.

This would be a breaking change, but I'd love a PR :+1: