fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.08k stars 373 forks source link

proposal: fully-qualified type representatives #315

Open davidchambers opened 5 years ago

davidchambers commented 5 years ago

This is an issue in spirit rather than a pull request. I am submitting the proposal in pull request form to facilitate threaded discussions and to allow changes to be made and tracked via Git.

The proposal is, I believe, sufficiently detailed, so I won't repeat myself here.

I asked @Avaq to review the proposal earlier today. He noted that this approach solves rpominov/fantasy-land#3. Aldwin has many ideas on this topic, which I hope he will share here. :)

/cc @alexandru, @robotlolita, @rpominov

Avaq commented 5 years ago

I believe this to be an alternative to (if not an extension of) #286 which solves the problem described in https://github.com/rpominov/fantasy-land/issues/3 with the proposed type representative constructors.

Perhaps it could be worked into his fork of Fantasy Land, closing https://github.com/rpominov/fantasy-land/issues/3 and unblocking progress towards #286. Although this fork also introduces TypeScript types, which I think not everyone (including myself) would agree with.


The only idea that I think is worth sharing, is the idea of using a Symbol instead of a String ('fantasy-land') to associate values with their type representative. A Symbol would have the following benefits:

davidchambers commented 5 years ago

[Symbols] would enable us to associate Type Representatives directly with String, Number, etc, without the need for a function like the proposed typeRep

That would work for nullary types, but we would still provide typeRep because the type representative of [1, 2, 3] should be Array (Number) rather than Array (Unknown).

davidchambers commented 5 years ago

I'm going to move ahead with this proposal. Expect a substantial pull request in the coming weeks. :)