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

everything #3

Merged
merged 1 commit into from
May 28, 2018
Merged

everything #3

merged 1 commit into from
May 28, 2018

Conversation

gabejohnson
Copy link
Member

Closes #1

index.js Outdated
//. Unit
//. ```
var Unit = {};
Unit.constructor = Object.create(Unit.constructor);
Copy link
Member

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?

Copy link
Member Author

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) {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

@gabejohnson gabejohnson Jun 9, 2017

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 =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

@gabejohnson
Copy link
Member Author

Thanks for looking it over @safareli!

@gabejohnson gabejohnson force-pushed the gabejohnson/everything branch 3 times, most recently from 61a86c7 to 21fc14f Compare June 8, 2017 13:14
README.md Outdated
@@ -0,0 +1,351 @@
# sanctuary-tuples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Let's remember to remove this file before merging this pull request. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. Remove the README?

Copy link
Member

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"
]
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member

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.

@gabejohnson
Copy link
Member Author

@davidchambers how do I set up CircleCI for this repo?

@davidchambers
Copy link
Member

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.

@gabejohnson
Copy link
Member Author

@davidchambers aside from removing README.md and changing the ASCII art, I think this is ready.

@gabejohnson
Copy link
Member Author

@davidchambers do you think this is good to go (minus the ASCII art)?

@davidchambers
Copy link
Member

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. :)

@davidchambers
Copy link
Member

@gabejohnson, what do you think of the idea of exporting Pair, Pair.fst, Pair.snd, … rather than P.Pair, P.fst, P.snd, …?

@gabejohnson
Copy link
Member Author

gabejohnson commented Jul 24, 2017

I think that makes sense. The current export method is a holdover from a previous implementation when we were exporting more types.

@davidchambers
Copy link
Member

We should define Pair.chainRec. As usual, I think I'll need help from you, @safareli. ;)

Makefile Outdated
@@ -45,7 +45,6 @@ lint:
--global module \
--global require \
--global self \
--rule 'max-len: [off]' \
Copy link
Member Author

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 😄

Copy link
Member

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);
Copy link
Member

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);

@davidchambers davidchambers mentioned this pull request Aug 21, 2017
12 tasks
index.js Outdated
/ / /
/______/ /
\ \ /
\______\/ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

       /*                   *\
      //                     \\
     //   @@  @@     @@  @@   \\
    //      @@       @@  @@    \\
    \\      @@       @@  @@    //
     \\   @@  @@  @    @@ @   //
      \\          /       @  //
       \*             @@@@  */

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin' good David!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//. . 'Extend ✅ ',
//. . 'Comonad ✅ ',
//. . 'Contravariant ❌ ' ]
//. ```
Copy link
Member

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.

Copy link
Member Author

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 😄

Copy link
Member

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.

Copy link
Member Author

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 😀

@davidchambers
Copy link
Member

I'm about to squash the commits. The original commits can be found at 838e48e.

Co-authored-by: Gabe Johnson <gijohnson105@gmail.com>
Co-authored-by: Matt Willhite <matthew.willhite@gmail.com>
@davidchambers davidchambers merged commit 824bbda into master May 28, 2018
@davidchambers davidchambers deleted the gabejohnson/everything branch May 28, 2018 11:37
@davidchambers
Copy link
Member

Thank you for your significant contributions, @gabejohnson and @miwillhite! 🍻

@miwillhite
Copy link
Collaborator

Woohoo, great work all!

This pull request was closed.
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