Loop
Theory
A Loop is the process of lifting a morphism
to a morphism
via a functor
This lifting is intrinsic to the definition of a functor and expresses how a function can be “looped over” structured containers.
Such a transformation preserves the structure imposed by \(F\), and is uniform across all functors. It satisfies the naturality condition, which ensures that for any morphism \(f : A \to B\), the following diagram commutes:
In this sense, looping over a structure corresponds to applying a function across the functorial image, while preserving internal shape and categorical consistency.
Syntax
The for
keyword introduces a loop whose range of traversal is defined by a functor \(F\). In other words, iteration takes place over the structured space \(F(A)\), assigning an identifier to each element in this space. The identifier will be available within the expression context.
There are two ways to express a for
loop:
- Inline Expression
An inline for
loop appends the for
clause directly to the end of an expression.
- Scoped Block
A scoped for
loop defines a block of statements to be executed for each element in the loop space.
A <LoopSpace>
can be:
-
An entire type space
-
A filtered subtype
The identifier is also available within the
where
clause condition scope.