Skip to content

Commit

Permalink
Pro-functor member/traversal (part 8 of optics).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jul 21, 2024
1 parent 58f497c commit da7eade
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 152 deletions.
1 change: 1 addition & 0 deletions documentation/bookmark/biological_programming.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [A motor for cell-free metabolism: Researchers have developed the first cell-free system in which genetic information and metabolism work together](https://www.mpg.de/22163540/0703-terr-a-motor-for-cell-free-metabolism-153410-x)
0. [New tools for programming biology](https://centuryofbio.com/p/new-tools-for-programming-biology)
0. [Open Genes: Structured data on human genes associated with aging: functions, evolution, the influence of gene activity on lifespan, age-related changes in gene expression, associations of allelic variants of genes with longevity and age-related phenotype.](https://open-genes.com/genes)
0. [Axial Discovery - Cell reprogramming](https://discoverybio.substack.com/p/axial-discovery-cell-reprogramming)
Expand Down
1 change: 1 addition & 0 deletions stdlib/source/library/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@
_
(failure ..wrong_syntax))))

(the' .public per Macro ..left_associative)
(the' .public all Macro ..right_associative)

... (every (Monad m)
Expand Down
45 changes: 28 additions & 17 deletions stdlib/source/library/lux/abstract/functor/pro.lux
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,44 @@
[library
[lux (.except)]])

(every .public (Functor it)
(every .public (Functor =>)
(Interface
(is (for_any (_ cause effect
cause' effect')
(-> (<- cause cause') (-> effect effect')
(-> (it cause effect)
(it cause' effect'))))
(-> (=> cause effect)
(=> cause' effect'))))
each)))

(every .public (Cartesian it)
(every .public (Cartesian =>)
(Interface
(is (for_any (_ cause effect extra)
(-> (it cause effect)
(it (And cause extra) (And effect extra))))
(is (for_any (_ head head' tail)
(-> (=> head head')
(=> (And head tail) (And head' tail))))
in_left)
(is (for_any (_ cause effect extra)
(-> (it cause effect)
(it (And extra cause) (And extra effect))))
(is (for_any (_ tail tail' head)
(-> (=> tail tail')
(=> (And head tail) (And head tail'))))
in_right)))

(every .public (Co_Cartesian it)
(every .public (Co_Cartesian =>)
(Interface
(is (for_any (_ cause effect extra)
(-> (it cause effect)
(it (Or cause extra) (Or effect extra))))
(is (for_any (_ head head' tail)
(-> (=> head head')
(=> (Or head tail) (Or head' tail))))
when_left)
(is (for_any (_ cause effect extra)
(-> (it cause effect)
(it (Or extra cause) (Or extra effect))))
(is (for_any (_ tail tail' head)
(-> (=> tail tail')
(=> (Or head tail) (Or head tail'))))
when_right)))

(every .public (Monoidal =>)
(Interface
(is (for_any (_ head head'
tail tail')
(-> (=> head head')
(=> tail tail')
(=> [head tail] [head' tail'])))
in_parallel)
(is (=> Any Any)
empty)))
104 changes: 5 additions & 99 deletions stdlib/source/library/lux/aspect.lux
Original file line number Diff line number Diff line change
@@ -1,105 +1,11 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857)
(.using
[library
[lux (.except all with)
[abstract
[functor (.only Functor)
["[0]" pro]]]
[type
["[0]" nominal]]
["[0]" function]
[data
["[0]" product]]]])
[lux (.except)]])

(every .public (Aspect it context context' aspect aspect')
(-> (it aspect aspect')
(it context context')))

... TODO: Make this nominal type unnecessary.
(nominal.every .public (Membership one all)
(Variant
{#All all}
{#One one (Membership one (-> one all))})

(the outer
(for_any (_ one all)
(-> (Membership one all)
(Or all (And one (Membership one (-> one all))))))
(|>> nominal.as))

(the inner
(for_any (_ one all)
(-> (Or all (And one (Membership one (-> one all))))
(Membership one all)))
(|>> nominal.of))

(the .public membership_functor
(for_any (_ one)
(Functor (Membership one)))
(implementation
(the (each value it)
(nominal.of
(.when (nominal.as it)
{#All all}
{#All (value all)}

{#One one next}
{#One one (each (function (_ before)
(|>> before
value))
next)}))
)))

(every .public (Apply context)
(Interface
(is (Functor context)
functor)
(is (for_any (_ it)
(-> it
(context it)))
pure)
(is (for_any (_ it it')
(-> (context (-> it it'))
(-> (context it)
(context it'))))
with)))

(the .public membership_apply
(for_any (_ one)
(Apply (Membership one)))
(implementation
(the functor ..membership_functor)
(the pure (|>> {#All} nominal.of))
(the (with internal_effect internal_cause)
(.when (nominal.as internal_effect)
{#All internal_effect}
(by ..membership_functor each internal_effect internal_cause)

{#One one internal_effect}
(nominal.of
{#One one (with (by ..membership_functor each function.flipped internal_effect)
internal_cause)})))))

(the .public (one it)
(for_any (_ it)
(-> it
(Membership it it)))
(nominal.of {#One it (nominal.of {#All (|>>)})}))

(the .public (all it)
(for_any (_ one all)
(-> (Membership one all)
all))
(.when (nominal.as it)
{#All it}
it

{#One one next}
((all next) one)))

(every .public (Member all one)
(-> all
(Membership one all)))
)
(every .public (Aspect => context context' aspect aspect')
(-> (=> aspect aspect')
(=> context context')))
11 changes: 6 additions & 5 deletions stdlib/source/library/lux/aspect/case.lux
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

... [Profunctor Optics: Modular Data Accessors](https://arxiv.org/abs/1703.10857)
(.using
[library
[lux (.except macro
Expand Down Expand Up @@ -78,9 +79,9 @@
)

(every .public (Aspect context context' case case')
(for_any (_ it)
(-> [(pro.Functor it) (pro.Co_Cartesian it)]
(//.Aspect it context context' case case'))))
(for_any (_ =>)
(-> [(pro.Functor =>) (pro.Co_Cartesian =>)]
(//.Aspect => context context' case case'))))

(the functor
(for_any (_ case case')
Expand Down Expand Up @@ -117,12 +118,12 @@
(|>> when_right
(each /#when (sum.either function.identity /#some)))))

(the .public (of_aspect it)
(the .public (of_aspect =>)
(for_any (_ context context' case case')
(-> (Aspect context context' case case' (for_any (_ context context')
(Case' context context'
case case')))
(Case' context context' case case')))
(it [..functor ..co_cartesian]
(=> [..functor ..co_cartesian]
[#when sum.right
#some function.identity]))
Loading

0 comments on commit da7eade

Please sign in to comment.