forked from Orchid/orchid
pre-recording backup
This commit is contained in:
3
notes/papers/report/parts/examples/maps/list.md
Normal file
3
notes/papers/report/parts/examples/maps/list.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# List
|
||||
|
||||
In order to use lists as tuples, one needs to be able to access arbitrary elements by index. This is done by the new `list::get` function which returns an `option`. Since most lists in complex datastructures are of known length, this leads to a lot of unreachable branches. The marking and elimination of these called for the definition of `option::unwrap` and `std::panic`.
|
||||
6
notes/papers/report/parts/examples/maps/main.md
Normal file
6
notes/papers/report/parts/examples/maps/main.md
Normal file
@@ -0,0 +1,6 @@
|
||||
This example demonstrates the construction of a basic functional map.
|
||||
|
||||
The `fn.orc` file is exactly identical to [the version in list-processing][1]
|
||||
`list.orc` and `option.orc` are extended to accommodate additional functionality.
|
||||
|
||||
[1]: ../list-processing/fn.md
|
||||
10
notes/papers/report/parts/examples/maps/map.md
Normal file
10
notes/papers/report/parts/examples/maps/map.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Map
|
||||
|
||||
A map implemented using a list of 2-length lists each containing a key and a corresponding value. Although `list` defines a `pair` for internal use, a binary `list` was chosen to test the performance of the interpreter.
|
||||
|
||||
While using a Church-pair instead of a list to store individual entries could multiply the performance of this map, a greater improvement can be achieved by using some sort of tree structure. This implementation is meant for very small maps such as those representing a typical struct.
|
||||
|
||||
## cover vs erase
|
||||
|
||||
In a list map like this one, most operations are O(n), except insertion which has an O(1) variant - appending a new frame with the new value without checking if one already exists. This is not generally a good idea, but in some extreme situations the time it saves can be very valuable.
|
||||
|
||||
5
notes/papers/report/parts/examples/maps/option.md
Normal file
5
notes/papers/report/parts/examples/maps/option.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Option
|
||||
|
||||
This example uses a lot of lists of known length, but with the introduction of `list::get` a lot of `option`s are added to the flow of logic. A way to mark impossible branches is needed.
|
||||
|
||||
This is handled using a new external function called `std::panic`. Since Orchid is a sandboxed language this doesn't actually cause a Rust panic, instead it produces a dedicated ExternError when it's first reduced. Using this, `option::unwrap` is trivial to define.
|
||||
Reference in New Issue
Block a user