Remark: we considered using the following alternative design
structure Stream (α : Type u) where
stream : Type u
next? : stream → Option (α × stream)
class ToStream (collection : Type u) (value : outParam (Type v)) where
toStream : collection → Stream value
where Stream is not a class, and its state is encapsulated.
The key problem is that the type Stream α "lives" in a universe higher than α.
This is a problem because we want to use Streams in monadic code.
Streams are used to implement parallel for statements.
Example:
for x in xs, y in ys do
...
is expanded into
let mut s := toStream ys
for x in xs do
match Stream.next? s with
| none => break
| some (y, s') =>
s := s'
...
- toStream : collection → stream
Instances
def Std.Stream.forIn {ρ : Type u_1} {α : Type u_2} {m : Type u_3 → Type u_4} {β : Type u_3} [Stream ρ α] [Monad m] (s : ρ) (b : β) (f : α → β → m (ForInStep β)) :
m β
Equations
- Std.Stream.forIn s b f = Std.Stream.forIn.visit✝ f s b
Instances For
@[instance_reducible, instance 100]
instance Std.instForInOfMonadOfStream {m : Type u_1 → Type u_2} {ρ : Type u_3} {α : Type u_4} [Monad m] [Stream ρ α] :
ForIn m ρ α
Equations
- Std.instForInOfMonadOfStream = { forIn := fun {β : Type ?u.4} => Std.Stream.forIn }
@[instance_reducible]
Equations
- Std.instToStreamArraySubarray = { toStream := fun (a : Array α) => Std.Rii.Sliceable.mkSlice a *...* }
@[instance_reducible]
Equations
- Std.instToStreamStringRaw = { toStream := fun (s : String) => s.toRawSubstring }
@[instance_reducible]
Equations
- Std.instToStreamRange = { toStream := fun (r : Std.Legacy.Range) => r }
@[instance_reducible]
Equations
- One or more equations did not get rendered due to their size.
@[reducible, inline]
abbrev Stream.next? {stream : Type u} {value : outParam (Type v)} [self : Std.Stream stream value] :
Equations
Instances For
@[reducible, inline]
abbrev ToStream.toStream {collection : Type u} {stream : outParam (Type u)} [self : Std.ToStream collection stream] :
collection → stream