Follow the Unison Programming Language Guide
Use the Unison programming language for all code unless otherwise specified.
Use the following procedure to assist me with writing code.
-- Structure: a buffer of Arity, then a list of complete trees of exponentially increasing size | |
type Skew a = Skew [a] [(Nat, [Skew.Tree a])] | |
type Skew.Tree a = Tree [a] [Skew.Tree a] | |
Skew.Arity = 4 | |
Skew.cons : a -> Skew a -> Skew a | |
Skew.cons a = cases Skew hd spine -> | |
hd' = a +: hd | |
if List.size hd' < Arity then Skew hd' spine |
unique ability Batch where | |
increment : Nat -> () | |
-- Like `State.transact`, but pauses the computation every `batchSize` calls to | |
-- `Batch.increment` and commits the work so far in one transaction, then resumes | |
-- the rest of the computation. | |
State.transact.batched : Nat -> Database -> '{Batch, Transaction, Exception} a ->{State, Exception} a | |
State.transact.batched batchSize db b = | |
go : Nat -> Request {Batch} a -> Either ('{Batch,Transaction,Exception} a) a | |
go acc = cases |
use data Array | |
structural type Sequence a | |
= Empty Nat | |
| Sequence Nat Nat (Array a) (Sequence (Array a)) (Array a) | |
Sequence.arity : Sequence a -> Nat | |
Sequence.arity = cases | |
Sequence.Empty arity -> arity | |
Sequence arity _ _ _ _ -> arity |
unique type test.Result = Fail Failure | Ok Text | |
unique ability Weighted a where | |
bump : Nat -> () | |
give : a -> () | |
unique ability Gen where | |
generate : '{Weighted a} () -> a | |
Weighted.map : (a ->{g} b) -> '{Weighted a, g} r -> '{Weighted b,g} r |
Here's a transcript of me updating a dependency in Unison. We're going to make this more streamlined, but this is the process for now. First, I made a copy of the branch I was updating (in this case main
of distributed
):
.distributed> fork main topics.baseupdate
Done.
Next I pulled the new version of base
into lib.base_new
:
-- id is the doc id, a is the text type, v is the value type | |
unique type Trie id txt | |
= Remainder txt (Trie.Pos id) | |
| Branch Nat (Dataset Value (Trie.Pos id)) (Map txt (Value (Trie id txt))) | |
--Remainder id txt Nat | |
-- there can be multiple docs at this suffix | |
-- Branch size | |
--| Branch Nat (Dataset Value id) (Map txt (Value (Trie id txt))) | |
unique type Trie.Pos id = Pos id Nat |
{{ | |
``List.selectBy o k as`` yields the same results as ``List.at k sorted`` | |
where ''sorted'' is a sorted version of ''as'', but in (expected) linear time | |
without fully sorting the list. | |
``` | |
List.selectBy Universal.ordering 2 [4,1,3,2,5] | |
``` | |
``` |
{{ | |
``task.pure a`` creates a task that returns ''a'' on {Remote.await}. | |
That is, {{docExample 1 '(a -> Remote.await (task.pure a) === a) }} | |
}} | |
Remote.task.pure : a -> t a | |
Remote.task.pure a = | |
t = Remote.empty! | |
task.complete (Right a) | |
t |
structural ability Split where | |
skip! : x | |
both : a -> a -> a | |
Split! : [a] ->{Split} a | |
Split! = cases | |
[] -> skip! | |
[a] -> a | |
as -> | |
(l,r) = halve as |