- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15
add paper draft #148
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
base: master
Are you sure you want to change the base?
add paper draft #148
Changes from 1 commit
5f925db
              b5dbe83
              dd8a7ef
              833e30c
              44d7ba3
              f3b9c00
              d2a926c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| @misc{SetfieldPackage, | ||
| author = {{Takafumi Arakaki} and {Jan Weidner}}, | ||
| title = "{Setfield.jl}", | ||
| year = {2017}, | ||
| publisher = {GitHub}, | ||
| journal = {GitHub repository}, | ||
| url = {https://github.com/jw3126/Setfield.jl} | ||
| } | ||
|  | ||
| @misc{JuliaPR21912, | ||
| author = {Keno Fischer}, | ||
| title = "{Heap allocated immutable arrays and compiler support}", | ||
| year = {2019}, url = {https://github.com/JuliaLang/julia/pull/21912}, | ||
| publisher = {GitHub}, | ||
| journal = {GitHub PR}, | ||
| } | ||
|  | ||
|  | ||
| @misc{MutabilitiesPackage, | ||
| author = {Takafumi Arakaki}, | ||
| title = "{Mutabilities.jl}", | ||
| year = {2019}, | ||
| url = {https://github.com/tkf/Mutabilities.jl}, | ||
| publisher = {GitHub}, | ||
| journal = {GitHub repository}, | ||
| } | ||
|  | ||
| @misc{HaskellLens, | ||
| author = {{Edward Kmett} and contributers}, | ||
| title = "{Lens}", | ||
| year = {2012}, | ||
| url = {https://github.com/ekmett/lens}, | ||
| publisher = {GitHub}, | ||
| journal = {GitHub repository}, | ||
| } | ||
|  | ||
| @misc{ImmutableJS, | ||
| author = {{Lee Bryon} and contributers}, | ||
| title = "{Immutable-js}", | ||
| year = {2014}, | ||
| url = {https://github.com/immutable-js/immutable-js}, | ||
| publisher = {GitHub}, | ||
| journal = {GitHub repository} | ||
| } | ||
|  | ||
| @article{Julia-2017, | ||
| title={Julia: A fresh approach to numerical computing}, | ||
| author={Bezanson, Jeff and Edelman, Alan and Karpinski, Stefan and Shah, Viral B}, | ||
| journal={SIAM {R}eview}, | ||
| volume={59}, | ||
| number={1}, | ||
| pages={65--98}, | ||
| year={2017}, | ||
| publisher={SIAM}, | ||
| doi={10.1137/141000671} | ||
| } | ||
|  | ||
| @article{AlgebrasAndUpdateStrategies, | ||
| title = "Algebras and update strategies", | ||
| abstract = "The classical (Bancilhon-Spyratos) correspondence between view update translations and views with a constant complement reappears more generally as the correspondence between update strategies and meet complements in the order based setting of S. Hegner. We show that these two theories of database view updatability are linked by the notion of {"}lens{"} which is an algebra for a monad. We generalize lenses from the category of sets to consider them in categories with finite products, in particular the category of ordered sets.", | ||
| author = "Michael Johnson and Robert Rosebrugh and Richard Wood", | ||
| note = "The following article appeared in Journal of universal computer science, 16(5), 729-748, and can be found at http://dx.doi.org/10.3217/jucs-016-05-0729. Version archived for private and non-commercial use with the permission of the author/s and according to publisher conditions. For further rights please contact the publisher.", | ||
| year = "2010", | ||
| language = "English", | ||
| volume = "16", | ||
| pages = "729--748", | ||
| journal = "Journal of Universal Computer Science", | ||
| issn = "0958-695X", | ||
| publisher = "Technische Universitat Graz from Austria", | ||
| number = "5", | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: 'Setfield.jl: Changing the immutable' | ||
| tags: | ||
| - Julia | ||
| - Functional Programming | ||
| - Optics | ||
| authors: | ||
| - name: Jan Weidner | ||
| orcid: 0000-0002-0980-8239 | ||
| affiliation: 1 | ||
| affiliations: | ||
| - name: PTW-Dosimetry | ||
| index: 1 | ||
| date: 13 September 2020 | ||
| bibliography: paper.bib | ||
| --- | ||
|  | ||
| # Summary | ||
| We discuss the problem of updating immutable objects. The solutions presented are implemented in the Setfield.jl package [@SetfieldPackage]. | ||
|  | ||
| # Overview | ||
|  | ||
| In the Julia programming language [@Julia-2017], some objects are *mutable* (`Array`, `mutable struct`, `...`), while others are *immutable* (`Tuple`, `struct`, `...`). | ||
| Neither is strictly better than the other in every situation. However, *immutability* usually leads to code that is easier to reason about, for both humans and compilers. | ||
| And therefore less buggy and more performant programs. | ||
| One convenience with mutability is, that it makes updating objects very simple: | ||
|  | ||
| `spaceship.captain.name = "Julia"` | ||
|  | ||
| The analogous operation in the immutable case is to create a copy of `spaceship`, | ||
| with just the captains name changed to "Julia". This operation is sometimtes called functional update. | ||
| Just think for a moment, how would you do achieve this? | ||
| It is a non trivial problem and there are many approaches. Both in Julia [@JuliaPR21912; @MutabilitiesPackage] and other languages [@HaskellLens; @ImmutableJS]. | ||
|          | ||
|  | ||
| The `Setfield.jl` package provides one solution to this problem. Namely it allows the user | ||
| to specify a functional update using the same syntax as in a mutable setting. The only syntactic difference is the `@set` macro in front: | ||
|  | ||
| `@set spaceship.captain.name = "Julia"` | ||
|  | ||
| And voila, this returns an updated copy. The implementation is based on the lens formalism, | ||
| see the documentation of the package. For an entry point to the lens literature see the introduction of [@AlgebrasAndUpdateStrategies]. | ||
|  | ||
| # Acknowledgements | ||
|  | ||
| We acknowledge various small contributions in form of issues and pull requests, by various | ||
| authors. Details can be extracted from the github repository of the package. | ||
|  | ||
| # References | ||
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.
Mutabilities.jl is just a wrapper of non-type-changing lens from Setfield.jl. So I don't feel it's adequate for showing as an alternative "approach." It may be useful for briefly discussing it as an alternative interface for lenses, though.
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.
That is an interestig perspective. I thought of
MutabilitiesasAnd to execute an update you would do
melt ... update! ... freeze.I thought of the partial
melts/freezesas less important and passing between mutable and immutable as the key idea.You seem to put much more emphasis on the partial aspect (which I agree is pretty close to lenses) and less emphasis on passing between mutable and immutable.
So really passing between mutable and immutable was the alternative approach I wanted to highlight.