### 5 releases (3 breaking)

new 0.4.0 | Sep 14, 2020 |
---|---|

0.3.0 | Sep 14, 2020 |

0.2.0 | Sep 13, 2020 |

0.1.1 | Sep 13, 2020 |

0.1.0 | Sep 13, 2020 |

#**98** in Filesystem

**MIT/Apache**

26KB

543 lines

# Path-Iter

A cocategory enumeration library based on path semantics

Implementation based on paper Cocategory Enumeration.

For an introduction to Path Semantics, see this paper.

### Sub-types in Path Semantics

In normal Path Semantics, one uses normal paths in theorem proving. Normal paths is a derivation from functions with sub-types.

This library focuses on sub-types, not on the more general case of normal paths.

A sub-type in Path Semantics is written in this form:

`x : [f] a
`

Where

is some input, `x`

is a function and `f`

is the output of `a`

.`f`

This library is for enumerating such sub-types efficiently.

### Example: AND

The

macro is used to write in the standard notation of Path Semantics.
It constructs a type using `path!`

that implements `Path`

:`IntoIterator`

`use` `path_iter``::``*``;`
`fn` `main``(``)`` ``{`
`for` a `in` `path!``(``[`And`]` `true``)` `{`
`//` Prints `(true, true)`
`println!``(``"``{:?}``"``,` a`)``;`
`}`
`}`

It prints

because that is the only input value to `(``true``,` `true``)`

which produces `And`

as output.`true`

### Example: AND 2

You can decide the output value at runtime:

`use` `path_iter``::``*``;`
`fn` `main``(``)`` ``{`
`for` `&`b `in` `&``[``false``,` `true``]` `{`
`for` a `in` `path!``(``[`And`]` b`)` `{`
`println!``(``"``{:?}``"``,` a`)``;`
`}`
`println!``(``"``"``)``;`
`}`
`}`

This prints:

`(false, false)
(false, true)
(true, false)
(true, true)
`

### Example: AND-NOT

You can chain path sub-types together:

`use` `path_iter``::``*``;`
`fn` `main``(``)`` ``{`
`for` a `in` `path!``(``[`And`]` `[`Not`]` `true``)` `{`
`println!``(``"``{:?}``"``,` a`)``;`
`}`
`}`

### Example: Partial Application

Partial application is a technique where a function reduces to another function when calling it with fewer arguments than the signature.

For example,

reduces to `And (true)`

`Idb`

.`use` `path_iter``::``*``;`
`fn` `main``(``)`` ``{`
`for` a `in` `path!``(``[`And`(``true``)``]` `true``)` `{`
`println!``(``"``{:?}``"``,` a`)``;`
`}`
`}`

This should not be confused with function currying, which is extensionally equal to partial application, but captures the underlying function in a closure.

The

macro expands to partial application automatically, but it is very limited.
Outside the macro `path!`

or for complex cases, one must use `path!`

.`PApp ::`papp

### Example: AND 3

The standard notation for composing paths is not very friendly with Rust macros.
Therefore, one can use a single bracket

with functions separated by commas:`[``]`

`use` `path_iter``::``*``;`
`fn` `main``(``)`` ``{`
`for` a `in` `path!``(``[``(``(`And`,` And`)``,` `(`And`,` And`)``)``,` `(`And`,` And`)``,` And`]` `true``)` `{`
`println!``(``"``{:?}``"``,` a`)``;`
`}`
`}`