-
Notifications
You must be signed in to change notification settings - Fork 102
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
Adds Identity API to docs #38
Conversation
This is an amazing start! I am a little worried about this getting stale and an extra thing to remember to do. It could get out of date easily. So we may want to update the main readme to lose the hard coupling. But that is something we can fix up. |
Don't worry about updating the README, we can adjust that after the docs get a bit more fleshed out. |
docs/API.md
Outdated
|
||
## Monoids | ||
|
||
Each `Monoid` provides a means to represent a binary operation and is usually locked down to a specific type. These are great when you need to combine a list of values down to one value. In this library, any ADT that provides both an `empty` and `concat` function can be used as a `Monoid`. There are a few of the `Crocks` that are also monoidial, so be on the look out for those as well. All `Monoids` work with the point-free functions `mconcat`, `mreduce`, `mconcatMap` and `mreduceMap`. |
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.
Why get rid of the crocks
description and leave this one?
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.
Actually the more I think about it, we should probably keep all descriptions here.
So instead of removing the descriptions, we should probably add the crocks description back.
docs/API.md
Outdated
|
||
## Point-free | ||
|
||
While it can seem natural to work with all these containers in a fluent fashion, it can get cumbersome and hard to get a lot of reuse out of. A way to really get the most out of reusability in Javascript is to take what is called a point-free approach. Below is a small code same to contrast the difference between the two calling styles: |
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 may want to get rid of this one as well?
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.
Keep this and add back the crocks description.
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 not sure whether to add them here or keep them in the README, so they were purposely inconsistent for option; does your new issue #42 makes these suggestions obsolete, or what do you think?
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 would add the crocks
section. We can take it out if we need to once we cut over to these docs.
Add docs to npmignore
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.
Pointing out differences in the types of definitions. The ideas are there but the examples [looking at you, Constructor of
] might suck
docs/crocks/Identity.md
Outdated
### chain | ||
|
||
`(a -> m b) -> m 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.
Different types of instance definitions: explicit Function
vs implicit f
, and implicit m
vs (not sure what m stands for)
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.
Here m
is used to represent any Monad
:
Monad m => (a -> m b) -> m b
.
So as this is specifically an Identity, it could (and maybe should) be written as:
(a -> Identity b) -> Identity b
Although it would probably look better as:
Identity m => (a -> m b) -> m b
If that 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.
But then should all defs be prefixed by the representing monad?
docs/crocks/Identity.md
Outdated
crocks.Identity.of([1,2,10]) | ||
crocks.Identity([1,2,10]) | ||
``` | ||
|
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.
Different type of definition for constructor; here is only a definition by example
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.
of
is a very specific function that signals an Applicative
.
In many cases the normal constructor function is the same thing as of
.
We still include of
in those cases so any functions that rely on calling of
can call it.
So the constructor parameters should be represented by the type siggy in most cases.
For things like Writer
it takes a Monoid
and kicks you back a constructor that is fixed to that Monoid like: Writer (Sum b) a
Also for Maybe, it also takes an internal UnionType and if it is not the UnionType, it delegates to Maybe.of
(which is basically Maybe.Just
)
Good 👁 tho.
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.
Actually a better example to highlight the difference would be IO
.
You can only construct an IO
with a function. BUT of
will take anything you pass it and not check it at all and give you back an IO
, that when run, returns whatever it was you passed of
@rstegg This is really shaping up nicely. |
1 similar comment
docs/crocks/Identity.md
Outdated
const dinner = frozenPizza.map(microwave) //Identity "microwave pizza" | ||
dinner.value() // "microwave pizza" | ||
``` | ||
To expose the constructor and instances defined below |
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.
To expose the constructor and instances defined below to the argument ?
docs/crocks/Identity.md
Outdated
|
||
### equals | ||
|
||
`x -> Boolean` | ||
`Identity x => x -> Boolean` |
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.
❓ : does this really need to be defined here or should a top-level api define 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.
Please check out my comments, and please ask any questions if you have them!!
docs/crocks/Identity.md
Outdated
|
||
### of | ||
|
||
`Identity a => a -> Identity 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.
Should be something like:
Identity m => a -> m a
docs/crocks/Identity.md
Outdated
|
||
## Instances | ||
|
||
### 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.
inspect
should be along the lines of:
() -> String
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.
Identity () ->
?
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.
No need to call out Identity here. this function just maps unit to a string.
docs/crocks/Identity.md
Outdated
|
||
### value | ||
|
||
`() -> 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.
value
should show be all like:
`Identity m => m a ~> () => 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.
I do not understand this one, folding Identity m => m a -> 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.
value
just maps unit to whatever is inside the identity.
// `a` would be Number in this case
Identity(3)
.value() // returns 3
docs/crocks/Identity.md
Outdated
|
||
### type | ||
|
||
`() -> Identity` |
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.
type
returns a string identifier so something like:
() -> String
docs/crocks/Identity.md
Outdated
|
||
### map | ||
|
||
`Identity m => m (a -> b) -> m 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.
So map
takes a function and lifts it into the context of Identity
, and because we need to show how the mapping works, we will want to use ~>
here. So this is how it should be shown IMO:
Identity m => m a ~> (a -> b) -> m 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.
Sweet!
docs/crocks/Identity.md
Outdated
|
||
### ap | ||
|
||
`Identity m => m a ~> m (a -> b) -> m 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.
This siggy matches the Fantasy Land spec and it just so happens this is the only place in crocks
that does not match the spec (for reasons). So to get it to show how crocks
handles Apply
, it should be something like:
Identity m => m (a -> b) ~> m a -> m b
.
Notice how it is reversed.
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.
why do i feel like half of this can be thrown away?
Identity m => m (a -> b)
or Identity m => m a -> m b
? (just factoring the m, not actually defining a signature, is 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.
I don't know what you feel that.
There is a constraint that the instance that this is being called on, MUST contain a function.
So that is why m (a -> b)
is needed to the left of ~>
...We need to communicate that constraint.
Make sense? Do you have any ideas on how we could better communicate that constraint?
👂
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.
Identity m => m a -> (a -> b) ~> m a -> m 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.
well i feel silly for trying now
docs/crocks/Identity.md
Outdated
|
||
### of | ||
|
||
`Identity a => a -> Identity 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.
Should stick with the "shorthand" for 🌽sistancy. Even though this is on the instance for 🌽venience, we do not really need to show the instance, as this function is not dependent on the instance (?)
Identity m => a -> m a
docs/crocks/Identity.md
Outdated
|
||
### chain | ||
|
||
`Identity m => m a ~> (a -> m b) -> m 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.
🐱fect!! This is exactly right!!
docs/crocks/Identity.md
Outdated
|
||
### sequence | ||
|
||
`Identity m, Applicative f => m (f b) ~> f (m a) -> m (f 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.
So for sequence we need an f
returning function as the argument, but it is independent of the other types in this flow. so we can show that by using b
like this:
Identity m, Applicative f => m (f a) ~> (b -> f b) -> f (m 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.
Curious if m a ~> (b -> f b) -> f (m a)
works for 🌽 sistency to traverse then?
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.
nope. we need to already contain the f a
for sequence
.
In fact, that is the thing about sequence
, it must already contain the Applicative
.
Where traverse
has a value and takes a function that will lift that value (and apply any additional mapping to it, if it wants) into the Applicative
, and then sequence
over that.
Does that make 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.
Good 👁 though! in catching the similarity
docs/crocks/Identity.md
Outdated
|
||
### traverse | ||
|
||
`Identity m, Applicative f => m a ~> f (m b) -> m (f 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.
And this bad boy should be something along the lines of
Identity m, Applicative f => m a ~> (c -> f c) -> (a -> f b) -> f (m b)
(The siggy is wrong for the crocks
pointfree function. I will update that with the next PR. It should take a m a
and not a m (f a)
like it says. 🙄 )
2 similar comments
1 similar comment
On |
This is a PR for issue #42.
A WIP API for crocks; you should review it and change what you'd like, and add to readme; it's modeled after the most.js api
Not much to dispute here; mostly copied from readme 🧀