kongware / scriptum

Functional Programming Unorthodoxly Adjusted to Client-/Server-side Javascript
MIT License
383 stars 21 forks source link

Allow nullary type constructors for ADTs #323

Closed ivenmarquardt closed 3 years ago

ivenmarquardt commented 3 years ago

This should be possible, of course, but currently it isn't.

ivenmarquardt commented 3 years ago

Here is an example of a sorting comparator:

type("(^r. r => r => r => r) => Comparator");
type("(^r. r, r, r => r) => Comparator");
type("(^r. {lt: r, eq: r, gt: r} => r) => Comparator");

The first one is a regular sum type. The second one makes use of Javascript's multi-argument functions. The third example uses an object to mimic named arguments.

I'll probably give the last one a shot. Maybe this is the most efficient/readable encoding for all sum types, consider Option:

type("(^r. {none: r, some: a => r} => r) => Option<a>");

This looks promising and you can probably allow partially applied records as well.

ivenmarquardt commented 3 years ago

Done.