Skip to content
Enigma Lav edited this page Jan 5, 2021 · 4 revisions

Welcome to the Fractanoos wiki!

Swift's property wrappers enable many useful features and one of it is the ability to put a refinement typing into the language without the need for writing many new adapter types.

You will be most productive if you would use a concept of possible worlds from modal logic to understand exposed features of this library. Let me guide you through. Each program consists of states, where each consecutive state caused by a mutation of the previous state. This form a set of states, over which and by quantifying over them and applying predicate expressions to ensure properties.

@Constrained is ∀ over all states of a variable

@Stateful is ∀ & ∃ over all states of a variable

@Modal is ∃ over some states, with implication

This library provides 5 entities at your disposal:

  1. @Unique that can be used only once. A move-only value essentially
  2. @Constrained which limits what values can go into variables. Think of it as of type predicate
  3. @Linear which enforces the order of changes that happen to variable
  4. @Stateful that takes a transition graph to enforce the correct transition. For example, to have an opened file, before changing it.

The difference between linear and stateful is in that linear cheks values always consequently, whilst stateful can track the complex graph of transitions.

  1. @Function that put constraints on incoming and outgoing values. New functions retain constraints.

The technique I can recommend is to use an interface to model the state as a variable of a type and then pair it with @Linear, @Consrained or @Stateful

There is also ability to model actors. But it is not working, because it causes DispatchQueue to crash (that happens not by my fault, believe me).

Clone this wiki locally