Skip to content

Commit

Permalink
doc fixup (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott authored Oct 20, 2022
1 parent 0e5356f commit 1fdf055
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 0 additions & 2 deletions docs/src/assets/flux.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ article pre {
max-width: none;
padding: 1em;
border-radius: 10px 0px 0px 10px;
margin-left: -1em;
margin-right: -2em;
}

.hljs-comment {
Expand Down
Binary file added docs/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 9 additions & 10 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@

Functors.jl provides a set of tools to represent [functors](https://en.wikipedia.org/wiki/Functor_(functional_programming)). Functors are a powerful means to apply functions to generic objects without changing their structure.

Functors can be used in a variety of ways. One is to traverse a complicated or nested structure as a tree and apply a function `f` to every field it encounters along the way.
The most straightforward use is to traverse a complicated nested structure as a tree, and apply a function `f` to every field it encounters along the way.

For large models it can be cumbersome or inefficient to work with parameters as one big, flat vector, and structs help manage complexity; but it may be desirable to easily operate over all parameters at once, e.g. for changing precision or applying an optimiser update step.

## Appropriate Use

!!! warning "Not everything should be a functor!"
Due to its generic nature it is very attractive to mark several structures as [`@functor`](@ref) when it may not be quite safe to do so.

Typically, since any function `f` is applied to the leaves of the tree, but it is possible for some functions to require dispatching on the specific type of the fields causing some methods to be missed entirely.

Examples of this include element types of arrays which typically have their own mathematical operations defined. Adding a [`@functor`](@ref) to such a type would end up missing methods such as `+(::MyElementType, ::MyElementType)`. Think `RGB` from Colors.jl.

## Basic Usage and Implementation

When one marks a structure as [`@functor`](@ref) it means that Functors.jl is allowed to look into the fields of the instances of the struct and modify them. This is achieved through [`Functors.fmap`](@ref).
Expand Down Expand Up @@ -61,3 +52,11 @@ Baz(1.0, 2)

Any field not in the list will be passed through as-is during reconstruction. This is done by invoking the default constructor, so structs that define custom inner constructors are expected to provide one that acts like the default.

## Appropriate Use

!!! warning "Not everything should be a functor!"
Due to its generic nature it is very attractive to mark several structures as [`@functor`](@ref) when it may not be quite safe to do so.

Typically, since any function `f` is applied to the leaves of the tree, but it is possible for some functions to require dispatching on the specific type of the fields causing some methods to be missed entirely.

Examples of this include element types of arrays which typically have their own mathematical operations defined. Adding a [`@functor`](@ref) to such a type would end up missing methods such as `+(::MyElementType, ::MyElementType)`. Think `RGB` from Colors.jl.

0 comments on commit 1fdf055

Please sign in to comment.