-
Notifications
You must be signed in to change notification settings - Fork 41
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
Does empty need to be a function? #37
Comments
There are some minor reasons for it to be a function:
And there's no much harm in it being a function. I mean I don't see there a big conceptual issue.
I'd say I'm not sure there isn't, although I can't present any. All that said maybe we make that change in the future along with other breaking changes if there will be any. |
Ok. I'll just write down here a couple arguments in favour of using a plain value. One downside of In a simple benchmark of Regarding simplicity, a dictionary is a mapping of names to values. In the current Static Land spec the values are just (artificially) limited to functions. I don't see how allowing non-functions would complicate the spec. On the contrary, one could give an arguably simpler specification for Monoid: Constants
Laws
(I just roughly deleted characters from the current Monoid spec.) Regarding Flow Static Land, related experimental libraries in various ML style languages (e.g. exhibit A and exhibit B) don't require |
Regarding performance, I think in most cases implementation of a monoid should look like this: const empty = []
const List = {
empty() {return empty},
concat(a, b) {return a.concat(b)},
} But yea, this is a bit of complication and probably still causes a perf hit, so argument stands. |
Hi @polytypic, sorry for the delay. Besides my comment here (which is admittedly a contrived example) I can't think of critical downsides. If I find some cons I'll make sure to inform you and write here |
I've been using plain values for |
I'm in favor of using plain values too. Note that you could always use lazy getters if you need a nullary function. const List = {
get empty() {
return Object.defineProperty(List, "empty", { value: [] }).empty;
},
concat: (a, b) => a.concat(b)
}; This is a contrived example, but it shows that nullary functions are equivalent to plain values when used as lazy getters. Hence, you don't sacrifice anything by using plain values. |
Currently the
empty
ofMonoid
is specified as a nullary function rather than a plain value. Is there a plausible use case that benefits fromempty
being a function or requires it to be a function?At the moment, I'm tempted to specify
empty
as a plain value in a use case of monoid.The text was updated successfully, but these errors were encountered: