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

Docs for Func and AppFunc #4378

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

UlisesTorrella
Copy link
Contributor

Hi! This pr closes issue 2650.
I tried to keep it simple, since most of the concepts are explained in the Applicative page.
I added some comments whilst I was trying to understand the code. Let me know if anything is wrong, I'm not an expert, so perhaps I got something mixed up.

@johnynek
Copy link
Contributor

I think the doc needs to start with the fact that shape looks almost identical to Kleisli and explain how they are different.

The issue links to a blog post and explains it and maybe we can just reuse some of the explanation. A very short summary may be that Kleisli is about sequential composition of functions while Func (poorly named) is about parallel compositions of functions.

I appreciate your PR, but I think re-explaining other core typeclasses (Applicative, Traverse) shouldn't go in here.

@UlisesTorrella
Copy link
Contributor Author

I was hesitant to mention that. I had written something about it, but though that, given that AppFunc is "more general" than Kleisli it would be confusing to mention Kleisli for someone unfamiliar to it.
But you are right, if it was discussed in the issue is because it's a point of confusion. I'll include it. Should it start the doc? or start the "AppFunc" section?

@UlisesTorrella
Copy link
Contributor Author

Ok, I mentioned the similarities with Kleisli and removed over explanation of traverse, just left the link to the applicative docs and an example

@UlisesTorrella UlisesTorrella marked this pull request as ready for review January 20, 2023 13:15
Copy link
Contributor

@reardonj reardonj left a comment

Choose a reason for hiding this comment

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

docs/datatypes/directory.conf needs to be updated with a reference to this page.

I left some small fixup suggestions as well, but I have to wonder if this article would be more useful if it started by introducing AppFunc directly, then discussing Func as a weaker version after (similar to how Apply is described in the Applicative article). With the current version, the motivation for caring (how to: compose applicative functors), is buried really deep.

docs/datatypes/func.md Outdated Show resolved Hide resolved
@@ -0,0 +1,78 @@
# Func
Copy link
Contributor

Choose a reason for hiding this comment

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

A link to the scaladoc should be added now that #4401 is merged.

docs/datatypes/func.md Outdated Show resolved Hide resolved
docs/datatypes/func.md Outdated Show resolved Hide resolved
docs/datatypes/func.md Outdated Show resolved Hide resolved
docs/datatypes/func.md Outdated Show resolved Hide resolved
@@ -0,0 +1,78 @@
# Func
Copy link
Contributor

Choose a reason for hiding this comment

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

Since AppFunc is so important here, maybe the title should be "Func and AppFunc"? Some of the typeclasses are done this way.


# AppFunc

AppFunc extends Func to wrap around a special type of functor: Applicative functors.
Copy link
Contributor

Choose a reason for hiding this comment

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

May as well link to the section for reference.

Suggested change
AppFunc extends Func to wrap around a special type of functor: Applicative functors.
AppFunc extends Func to wrap around a special type of functor: [Applicative] functors.

docs/datatypes/func.md Outdated Show resolved Hide resolved

Signature: `AppFunc[F[_], A, B] extends Func[F, A, B]`

Now, for the reader familiar with `Kleisli`, we find an even more similar data type. `AppFunc` provides compositions of weaker constraint, allowing to compose `AppFunc[F[_], A, B]` with `AppFunc[G[_], C, A]`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these Kleisli call outs are going to help people trying to figure out what AppFunc is for. Have you considered having a comparison to Kleisli section at the end of the article?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, yes actually I think at the beginning it was at the end but a suggestion was to move it to the beginning. Given that most doubts in the PR introducing the code were around "why do we need this if Kleisli is a thing"

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, I guess that's down to a matter of audience. For cats newcomers, Kleisli is probably at least as foreign as this.

@UlisesTorrella
Copy link
Contributor Author

UlisesTorrella commented Mar 4, 2023

docs/datatypes/directory.conf needs to be updated with a reference to this page.

I left some small fixup suggestions as well, but I have to wonder if this article would be more useful if it started by introducing AppFunc directly, then discussing Func as a weaker version after (similar to how Apply is described in the Applicative article). With the current version, the motivation for caring (how to: compose applicative functors), is buried really deep.

Hey, I saw your suggestions and applied almost all, only question the one about Kleisli, let me know what you think.
Also updated the branch and incluede docs links

Copy link
Contributor

@reardonj reardonj left a comment

Choose a reason for hiding this comment

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

Now that I've read it, the new Kleisli text gives enough context to not feel out of place at the start.


Func is a wrapper around a `run` function `A => F[B]` where `F` is a functor. Given that, the Func data type is equipped with the known `map` function, and a `mapK` function to apply natural transformations (from a `Func[F[_], A, B]` get an `Func[G[_], A, B]`).

The signature `Func[F[_], A, B]` is very similar to the signature for [Kleisli](../datatypes/kleisli.md): `Kleisli[F[_], -A, B]`. The difference is that `Func` is a less restrictive data type that wraps around functors, and only provides basic methods `run`, `map`, and `mapK`, while `Kleisli` is strong enough to provide composition, flatMap, and more. We will see a more useful data type just next with `AppFunc`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does just [Kleisli] without an explicit link not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I got an exception when running the preview. I got this explicit from another doc doing the same, must be for the same reason. Idk why it says the Klesli reference is "ambiguous"

Copy link
Contributor

Choose a reason for hiding this comment

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

Wierd. Too bad. Maybe 2 sections called "Kleisli" somewhere?

docs/datatypes/func.md Outdated Show resolved Hide resolved
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.

Improve doc for Func
3 participants