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

Add entry about typeof gotcha #331

Closed
wants to merge 1 commit into from
Closed

Conversation

nickrobinson251
Copy link
Contributor

@nickrobinson251 nickrobinson251 commented Apr 4, 2021

@codecov-io
Copy link

codecov-io commented Apr 4, 2021

Codecov Report

Merging #331 (0e57639) into master (9a029c4) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #331   +/-   ##
=======================================
  Coverage   90.04%   90.04%           
=======================================
  Files          13       13           
  Lines         472      472           
=======================================
  Hits          425      425           
  Misses         47       47           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a029c4...0e57639. Read the comment docs.

For example, the `rrule` signature for a constructor would be like:

```julia
function rrule(::Type{T}, args...; kwargs...)
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to mention when you want <:T here, because I've seen this version trip up users before as well.

In particular, be careful not to use `typeof(T)` here.
Because `typeof(T)` is `DataType`, using this to define an `rrule`/`frule` will define an `rrule`/`frule` for all constructors.

You can check which to use with `Core.Typeof`:
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 more useful than the below part on Typeof would be to create a struct that is also a functor and show how to define rrules for both its constructor and it as a functor. Writing functor rules also trips up users, and the two are easily confused.

@nickrobinson251
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants