-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
everything #3
everything #3
Conversation
index.js
Outdated
//. Unit | ||
//. ``` | ||
var Unit = {}; | ||
Unit.constructor = Object.create(Unit.constructor); |
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.
Unit.constructor
on the right side is just Object
, is there some different intention?
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.
An artifact of an earlier implementation. I'll change it.
index.js
Outdated
return Z.lte(this.a, other.a) && Z.lte(this.b, other.b); | ||
}; | ||
|
||
function makePair(p, a, b) { |
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.
that's the point of this function
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.
Because Identity
inherits prototypically from Pair
it's necessary to check the type of p
when creating a new one in Pair
methods. Pair
being the ancestor shouldn't really have to worry about this, so if you have another solution I'd love to hear it.
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.
makes sense
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.
In my view the minimal code sharing afforded by implementing Identity a
in terms of Pair Unit a
is insufficient compensation for the complexity of inheritance. I'd prefer to avoid inheritance, as demonstrated in cd8a8c5.
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.
Also if someone adds some method to prototype of Pear it will be accessible on Identity too which might not be desired
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.
Code sharing wasn't the point. I noticed that fixing the first argument to Pair
to be Unit
automatically resulted in Identity
. It had been my intention to (potentially) follow PureScript in having a single tuple type (Pair
) and implement tuple3
, tuple4
, etc. in terms of it.
But whereas PureScript's tuple3(1, 2, 3)
would give Pair(1, Pair(2, Pair(3, Unit)))
mine would give Pair(Pair(Pair(Unit, 1), 2), 3)
to allow map
, ap
, etc. to work over the final argument. Consistency FTW.
That said, I'm happy to distinguish tuple1
from Identity
.
index.js
Outdated
//. > Z.toString(Pair(1, 2)) | ||
//. 'Pair(1, 2)' | ||
//. ``` | ||
Pair.prototype.inspect = |
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.
related fluture-js/Fluture#68
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.
Makes sense. I'll change it.
Thanks for looking it over @safareli! |
61a86c7
to
21fc14f
Compare
README.md
Outdated
@@ -0,0 +1,351 @@ | |||
# sanctuary-tuples |
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.
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.
Wait. Remove the README?
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.
Yes. README.md is generated as part of the release process. Note that in
https://github.com/sanctuary-js/sanctuary-tuples/blob/v/index.js#L54
there is no version number, so these links are currently broken. When we run make release-major
, though, VERSION
will be set to 1.0.0
so the links will point to the v1.0.0
tag. :)
bower.json
Outdated
"/Makefile", | ||
"/circle.yml", | ||
"/package.json" | ||
] |
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.
Let's have a white list ("files"
) rather than a blacklist ("ignore"
).
index.js
Outdated
//. [Monad]: v:fantasyland/fantasy-land#monad | ||
//. [Ord]: v:fantasyland/fantasy-land#ord | ||
//. [Semigroupoid]: v:fantasyland/fantasy-land#semigroupoid | ||
//. [Semigroup]: v:fantasyland/fantasy-land#semigroup |
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.
Nit: Semigroup should come before Semigroupoid.
test/index.js
Outdated
|
||
test('lte', function() { | ||
eq(Z.lte(Unit, Unit), true); | ||
eq(Z.lte(Unit, Object.create(Unit)), false); |
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.
I think we should remove this test case.
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.
These should actually use Object.assign
which isn't available on all of the platforms tested. It's purpose is to demonstrate that both arguments must be identical to Unit
.
index.js
Outdated
//. | ||
//. ```javascript | ||
//. > Z.ap(Pair(' there', Math.sqrt), Pair('hello', 64)) | ||
//. Pair('hello there', 8) |
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.
Haskell disagrees on the order in which the a
values should be concatenated:
> (<*>) (" there", sqrt) ("hello", 64)
(" therehello", 8.0)
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.
I think this has to do with the argument reordering FL does WRT ap
. Though I could be wrong.
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.
Haskell:
$ ghci
> :t (<*>)
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
Fantasy Land:
$ node
> const S = require('sanctuary')
> S.ap
ap :: Apply f => f (a -> b) -> f a -> f b
The type signatures are in agreement.
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.
I was referring to the change in FL < 1.0 vs > 1.0
pre 1.0
ap :: Apply f => f (a -> b) ~> f a -> f b
post 1.0
ap :: Apply f => f a ~> f (a -> b) -> f b
But I suppose we can implement it however we want as long as the signatures match.
And being consistent w/ Haskell is probably a safe bet.
test/index.js
Outdated
var Pair = Tuples.Pair; | ||
var Identity = Tuples.Identity; | ||
var fst = Tuples.fst; | ||
var snd = Tuples.snd; |
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.
The presence of fst
and snd
suggest to me that we would be better off having separate packages for Unit, Identity, and Pair. We would then have Pair.fst
and Pair.snd
, which would be much clearer. This would also prevent implementation details from leaking:
> Tuples.snd(Tuples.Identity(42))
42
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.
we would be better off having separate packages for Unit, Identity, and Pair.
I can get behind that. Though the Unit
package would be quite small (no pun intended) and sanctuary-tuples would have a dependency on it.
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.
Would you still want functions fst
and snd
? Or just have the user rely on property access?
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.
I'm very much in favour of keeping the functions. As with isNothing
and isJust
, it's nice to provide both property and function to support various use cases.
@davidchambers how do I set up CircleCI for this repo? |
I just visited https://circleci.com/gh/sanctuary-js/sanctuary-tuples and followed the project. I believe that's all that's required. |
1b2397c
to
8e54831
Compare
@davidchambers aside from removing README.md and changing the ASCII art, I think this is ready. |
@davidchambers do you think this is good to go (minus the ASCII art)? |
6745c81
to
99eebbb
Compare
I would very much like to incorporate fantasyland/fantasy-laws#1. I intend to complete and merge that pull request this weekend. In the interim, you could add fantasy-laws to package.json as a Git dependency and use it to test the lawfulness of this algebraic data type. :) |
@gabejohnson, what do you think of the idea of exporting |
I think that makes sense. The current export method is a holdover from a previous implementation when we were exporting more types. |
We should define |
Makefile
Outdated
@@ -45,7 +45,6 @@ lint: | |||
--global module \ | |||
--global require \ | |||
--global self \ | |||
--rule 'max-len: [off]' \ |
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.
@davidchambers oops! I thought the line length violation was from the link to MDN. Thanks for fixing it 😄
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.
The linting rules are actually pretty sophisticated. We ignore lines containing URLs, and we provide a pattern to match //#
lines as we don't want to wrap type signatures.
You were just one character over the limit, by the way. ;)
index.js
Outdated
//. ``` | ||
function Pair$prototype$lte(other) { | ||
if (Z.equals(this.fst, other.fst)) return Z.lte(this.snd, other.snd); | ||
return Z.lte(this.fst, other.fst); |
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.
This form makes the symmetry a little clearer:
return Z.equals(this.fst, other.fst) ? Z.lte(this.snd, other.snd)
: Z.lte(this.fst, other.fst);
index.js
Outdated
/ / / | ||
/______/ / | ||
\ \ / | ||
\______\/ */ |
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.
How about this?
/* *\
// \\
// @@ @@ @@ @@ \\
// @@ @@ @@ \\
\\ @@ @@ @@ //
\\ @@ @@ @ @@ @ //
\\ / @ //
\* @@@@ */
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.
Lookin' good David!
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.
⚡
//. . 'Extend ✅ ', | ||
//. . 'Comonad ✅ ', | ||
//. . 'Contravariant ❌ ' ] | ||
//. ``` |
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.
@gabejohnson, please review this table. I don't think it's possible to satisfy ChainRec because we'd be forced to produce a value of type Pair a d
without access to a value of type a
.
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.
Sorry it took me so long to respond to this David. I'm not certain what a ChainRec
instance would look like if we did implement it. But given the way it's defined in the spec, I don't see how we could anyway. We would have to provide a TypeRep
for Semigroup a => Pair a
.
If we develop some new technique in the future which allows for this, we can always revisit 😄
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.
Sorry it took me so long to respond to this David.
No worries. Your timing is very good. I will soon merge this pull request. :)
I would like to use the Co-authored-by
trailer so the final (squashed) commit will be jointly attributed. Are you happy for me to include your email address in the commit message? If not, I will use gabejohnson@users.noreply.github.com
instead.
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.
Using my email address is fine.
The release of these days type libraries is very exciting 😀
I'm about to squash the commits. The original commits can be found at |
838e48e
to
ff8f401
Compare
Co-authored-by: Gabe Johnson <gijohnson105@gmail.com> Co-authored-by: Matt Willhite <matthew.willhite@gmail.com>
ff8f401
to
90744d5
Compare
Thank you for your significant contributions, @gabejohnson and @miwillhite! 🍻 |
Woohoo, great work all! |
Closes #1