-
Notifications
You must be signed in to change notification settings - Fork 376
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
static ‘empty’ value #164
static ‘empty’ value #164
Conversation
90b4b42
to
af99843
Compare
leftIdentity: test((x) => monoid.leftIdentity(Id[of](Sum[empty]()))(equality)(Sum[of](x))), | ||
rightIdentity: test((x) => monoid.rightIdentity(Id[of](Sum[empty]()))(equality)(Sum[of](x))) | ||
leftIdentity: test((x) => monoid.leftIdentity(Sum)(equality)(x)), | ||
rightIdentity: test((x) => monoid.rightIdentity(Sum)(equality)(x)) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could someone review this change?
It's a bit strange for code in id_test.js to test the Sum type, but the Id type can no longer satisfy Monoid.
af99843
to
990533f
Compare
To my mind, this still doesn't solve the issue raised in #88. It helps, but it falls short of fixing the basic problem. I said this:
While this PR does explicitly say that the dictionaries have to exist, it also lists the canonical path to the dictionary as starting with an instance:
My concern is that we simply may not have an instance available. The example we kept mentioning in #88 was foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m What happens if that second parameter contains no instances? The trouble, of course, is that any fix to this problem would probably mean quite a radical change to FL. I haven't yet had the time to investigate StaticLand, but it's possible that it might hold a solution to this; that doesn't address the FantasyLand problem, though. So, in other words, my take is that this moves in the right direction, but not far enough. I don't know what would move us that way though. |
It seems to me one of the following types would work: foldMap :: (Foldable t, Monoid m) => m -> (a -> m) -> t a -> m foldMap :: (Foldable t, Monoid m) => { fantasy-land/empty :: m } -> (a -> m) -> t a -> m |
|
Sorry, I missed your response.
Yes, that's what I'm getting at. If you're going to need signatures like that, why not use the dictionary/type-metadata as the first parameter? (I know that the spec calls this "constructor" but that's mostly a pun from the Javascript side.) If you have access to the A radically different solution for Monoids would be simply to require the dedicated value, not a function. But this doesn't help with |
I think the difference (at least in my mind) is that |
I'm confused by your comment, @CrossEye. 😕
Does
Is this not the very change effected by this pull request? |
Not unambiguously, to me. But if that's what you intend with it, I'd be happy with this example, although not your other one.
Yes, sorry. I got so caught up in the location of |
I'd like to know why you're okay with |
If we were to remove the const Additive = (x) => ({
concat: (y) => Additive(x + y),
})
Identity.empty = Additive(0) For this to be a valid FL monoid, I would need to modify that to include the const Additive = (x) => ({
constructor: Additive,
concat: (y) => Additive(x + y),
})
Additive.empty = Additive(0) Even after doing this, we're still effectively saying in the spec that you can't guarantee I'm starting to wonder whether we do away with specifying what the names and locations of |
What if we somehow represent not Monid value but Monid type p.s. this might be a stupid idea as well :d |
Superseded by #180 |
This pull request introduces two changes:
empty
instance method; andempty
static method with anempty
value (first proposed in change Monoid#empty from nullary function to identity element itself #82).As @scott-christopher pointed out in #162 (comment) there are situations in which one has a type value and wants the type's identity element, but can't determine it because it's only available via the
empty
method of values of the type, and one doesn't know how to construct a value!As currently specified, the Monoid type class is not very useful. We're trying to have our 🍰 and eat it too, but it's not working. In order to accommodate the generalized
Monoid m =>
functions such as Scott'sConst.of
we need to know thatT.empty
will be available. The spec must therefore require this. If it's to do so, the Identity type and several others can no longer satisfy Monoid. At that point the instance method serves no purpose (beyond saving one from typing.constructor
occasionally).If we're to have a static method only we can no longer rely on run-time values, so
empty
needn't be a method. Rather than a nullary function which returns the identity element, it can simply be the identity element. Scott pointed out that one could defineempty
as a getter if one felt so inclined. 😱