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

specify location of ‘empty’ method #162

Closed
wants to merge 1 commit into from

Conversation

davidchambers
Copy link
Member

Commit message:

An instance method is more flexible than a static method. It facilitates

> Identity([1, 2, 3]).empty()
Identity([])

since Identity#empty can dispatch to the inner value's empty method.

An instance method is more flexible than a static method. It facilitates

    > Identity([1, 2, 3]).empty()
    Identity([])

since Identity#empty can dispatch to the inner value's ‘empty’ method.
@scott-christopher
Copy link
Contributor

I find empty most useful when an instance is not available, so I would still want a way to obtain an empty value statically.

e.g. The typical implementation of Const.of requires an empty value of the inner type, which makes it difficult to wire up if an instance is required.

Const.of = (_) => Const(OtherType.empty())

I'd probably go a step further and prefer the empty instance to be a plain property value rather than a nullary method. A property descriptor getter function could still be used if laziness is desired.

I'm not necessarily a fan of requiring it live on the constructor property though either. Perhaps that's an indication that the static-land approach might be more suitable for things such as this.

@CrossEye
Copy link

I find empty most useful when an instance is not available, so I would still want a way to obtain an empty value statically.

That's not where I started, but it's where I ended up in the long discussion in #88. I'm afraid this is one of those square peg/round hole situations that are bound to come up when you try to merge static and dynamic typing. I don't know that there is a good solution.

@davidchambers
Copy link
Member Author

I'd probably go a step further and prefer the empty instance to be a plain property value rather than a nullary method.

This was proposed in #82. This would mean that the Identity type could not satisfy Monoid, I believe. Does this bother you, @scott-christopher?

The typical implementation of Const.of requires an empty value of the inner type, which makes it difficult to wire up if an instance is required.

Const.of = (_) => Const(OtherType.empty())

Hmm, I see the problem.

It seems we have four options:

  1. Require an instance method only, making the Const type sad. 😢
  2. Require a static method only, making the Identity type sad. 😢
  3. Continue to support both, but state that the instance method should be used if both are present.
  4. Do nothing.

Does anyone object to the third option? It's an improvement on the status quo, and shouldn't make anyone sad.

@SimonRichardson
Copy link
Member

3 sounds reasonable

On Tue, 13 Sep 2016, 13:05 David Chambers, notifications@github.com wrote:

I'd probably go a step further and prefer the empty instance to be a
plain property value rather than a nullary method.

This was proposed in #82
#82. This would mean
that the Identity type could not satisfy Monoid, I believe. Does this
bother you, @scott-christopher https://github.com/scott-christopher?

The typical implementation of Const.of requires an empty value of the
inner type, which makes it difficult to wire up if an instance is required.

Const.of = (_) => Const(OtherType.empty())

Hmm, I see the problem.

It seems we have four options:

  1. Require an instance method only, making the Const type sad. 😢
  2. Require a static method only, making the Identity type sad. 😢
  3. Continue to support both, but state that the instance method should
    be used if both are present.
  4. Do nothing.

Does anyone object to the third option? It's an improvement on the status
quo, and shouldn't make anyone sad.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#162 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACcaGGBkqQPm6KlceCvUJw_jqb34nMeuks5qppGPgaJpZM4J7gYW
.

@davidchambers
Copy link
Member Author

I'll open a new pull request shortly.

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

Successfully merging this pull request may close these issues.

4 participants