-
Notifications
You must be signed in to change notification settings - Fork 62
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
Conversation
Codecov Report
@@ 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.
|
For example, the `rrule` signature for a constructor would be like: | ||
|
||
```julia | ||
function rrule(::Type{T}, args...; kwargs...) |
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.
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`: |
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 more useful than the below part on Typeof
would be to create a struct that is also a functor and show how to define rrule
s for both its constructor and it as a functor. Writing functor rules also trips up users, and the two are easily confused.
DataType
. I'm sure it could be improved further when we do the rest of More docs/examples for structs/constructors #315 and add detailed examples.Core.Typeof
, so feedback appreciated