vitrea

Optics via the profunctor representation theorem

https://github.com/mroman42/vitrea

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.6%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Optics via the profunctor representation theorem

Basic Info
  • Host: GitHub
  • Owner: mroman42
  • License: gpl-3.0
  • Language: Haskell
  • Default Branch: master
  • Homepage:
  • Size: 94.7 KB
Statistics
  • Stars: 24
  • Watchers: 5
  • Forks: 3
  • Open Issues: 3
  • Releases: 0
Created about 6 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

readme.org

* vitrea

Pure profunctor lenses and optics via the /profunctor representation theorem/. You can read more about
this representation in the following articles.

 * [[https://bartoszmilewski.com/2017/07/07/profunctor-optics-the-categorical-view/]["Profunctor optics: the categorical view"]], Milewski (2017).
 * [[https://www.cs.ox.ac.uk/jeremy.gibbons/publications/proyo.pdf]["What you needa know about Yoneda"]], Boisseau, Gibbons (2018).
 * [[https://arxiv.org/abs/1809.00738]["Categories of optics"]], Riley (2018).
 * [[https://arxiv.org/abs/2001.07488]["Profunctor optics: a categorical update"]], Clarke, Elkins, Gibbons, Loregian, Milewski, Pillmore, Román (2019).
 
All the optics on this library are particular cases of a single unified definition. All the combinators on this library are instantiations of the profunctor optic to a particular Tambara module.

The usual notions of lawfulness (as in [[https://arxiv.org/abs/1809.00738]["Categories of optics"]]) apply to non-mixed optics (lenses, prisms, traversals...). However, there is not a consensus on what the natural notion of laws for a mixed optic should be, apart from specific cases like monadic lenses.
 

** Examples

The library follows, where possible, the style of combinators of the [[https://github.com/ekmett/lens/wiki/operators][lens library]].  Example code from [[https://arxiv.org/abs/2001.07488]["Profunctor optics: a categorical update"]] works directly under the library. 

*Example 1. (Lenses and prisms)* The composition of a prism (~address~) and a lens (~street~)
is used to parse a string and then access and modify one of its
subfields.

#+begin_src haskell
let home = "221b Baker St, London, UK"
address :: Prism Address String
street :: Lens String Address

  >>> home?. address.street
  Just "221b Baker St"
  >>> home & address.street. ̃ "4 Marylebone Rd"
  "4 Marylebone Rd, London, UK"
#+end_src

*Example 2. (Monadic lenses)* A polymorphic family of type-changing monadic lenses
for a logging monad is used to track each time a data holder
(~Box~) is accessed.


#+begin_src haskell
box :: (Show b) => MonadicLens IO a b (Box a) (Box b)

  >>> return (Box 42)
        >>= mupdate box "hello"
        >>= mupdate box "world"
  [box]: contents changed to "hello".
  [box]: contents changed to "world".
  Box{"world"}
#+end_src

*Example 3. (Algebraic lenses)* A classifying lens (~measure~) is used both for accessing
a the measurements of a point in the iris dataset and to classify
new measurements into a species (~Versicolor~).

#+begin_src haskell
let iris =
[ Iris Setosa 4.9 3.0 1.4, 0.2
, Iris Setosa 4.7 3.2 1.3 0.2
, ...
, Iris Virginica 5.9 3.0 5.1 1.8 ]
measure :: AlgLens [] Measurements Flower

  >>> iris!!4 ˆ. measure
  (5.0, 3.6, 1.4, 0.2)
  >>> iris & measure .? Measurements (4.8, 3.2, 3.5, 2.1)
  Iris Versicolor (4.8, 3.1, 1.5, 0.1)
#+end_src

*Example 4. (Traversals)* The composition of a traversal (~each~) with a prism
(~address~) and a lens (~city~) is used to parse a collection of strings
and modify one of their subfields.

#+begin_src haskell
let mail =
[ "43 Adlington Rd, Wilmslow, United Kingdom"
, "26 Westcott Rd, Princeton, USA"
, "St James's Square, London, United Kingdom"
]
each :: Traversal String [String]
address :: Prism Address String
city :: Lens String Address

  >>> mail & each.address.city % ̃ uppercase
  [ "43 Adlington Rd, WILMSLOW, United Kingdom"
  , "26 Westcott Rd, PRINCETON, USA"
  , "St James's Square, LONDON, United Kingdom"
  ]
#+end_src haskell

*Example 5. (Kaleidoscopes)* Following the previous Example 3, a kaleidoscope
(~aggregate~) is composed with an algebraic lens to create a new
point on the dataset by aggregating measurements with some function 
(~mean~, ~maximum~) and then classifying it.

#+begin_src haskell
measure :: AlgebraicLens [] Measurements Flower
aggregate :: Kaleidoscope Float Measurements

  >>> iris & measure.aggregate >- mean
  Iris Versicolor; Sepal (5.843, 3.054); Petal (3.758, 1.198)
#+end_src haskell


** About
/This is a complete rewriting from the first prototype of [[https://github.com/mroman42/vitrea-prototype-1][vitrea]], maintained by @emilypi and @mroman42./

Owner

  • Name: Mario Román
  • Login: mroman42
  • Kind: user
  • Location: Tallinn, Estonia
  • Company: TTU Institute of Cybernetics

Maths & CS

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you reference this software, please cite it as below."
authors:
- family-names: "Milewski"
  given-names: "Bartosz"
  orcid: "https://orcid.org/0000-0001-9249-0104"
- family-names: "Pillmore"
  given-names: "Emily"
- family-names: "Román"
  given-names: "Mario"
  orcid: "https://orcid.org/0000-0003-3158-1226"
title: "Vitrea: a Profunctor Optics Library."
version: 1.0.0
date-released: 2020-01-15
url: "https://github.com/mroman42/vitrea"

GitHub Events

Total
  • Watch event: 1
  • Push event: 2
Last Year
  • Watch event: 1
  • Push event: 2

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 24
  • Total Committers: 2
  • Avg Commits per committer: 12.0
  • Development Distribution Score (DDS): 0.125
Past Year
  • Commits: 2
  • Committers: 1
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mario Román m****8@g****m 21
Bartosz Milewski b****z@r****m 3
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 4
  • Total pull requests: 1
  • Average time to close issues: 2 months
  • Average time to close pull requests: 2 days
  • Total issue authors: 3
  • Total pull request authors: 1
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mroman42 (2)
  • considerate (1)
  • AriFordsham (1)
Pull Request Authors
  • BartoszMilewski (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

vitrea.cabal hackage
  • base >=4.12.0.0 && <4.13
  • mtl >=2.2.2 && <2.3
  • profunctors *
  • split *
  • time *