lean4-htt/tests/lean/stream.lean
Leonardo de Moura 074259201e feat: add helper classes for implementing parallel for
It is based on an approach suggested by Andrew Kent, and refined by
Sebastian Ullrich.

TODO: expand the the parallel `for`s at `Do.lean`.
2020-12-19 14:15:47 -08:00

40 lines
958 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def g (xs : Array Nat) (ys : Array Nat) : IO Unit := do
let mut s := toStream ys
for x in xs do
match Stream.next? s with
| none => break
| some (y, s') =>
s := s'
IO.println s!"x: {x}, y: {y}"
#eval g #[1, 2, 3] #[4, 5]
#print "-----"
def f [Stream ρ α] [ToString α] (xs : Array Nat) (ys : ρ) : IO Unit := do
let mut ys := ys
for x in xs do
match Stream.next? ys with
| none => break
| some (y, ys') =>
ys := ys'
IO.println s!"x: {x}, y: {y}"
#eval f #[1, 2, 3] (toStream #[4, 5])
#print "-----"
#eval f #[1, 2] (toStream [4, 5, 6])
#print "-----"
#eval f #[1, 2, 3] (toStream "hello")
def h [Stream ρ α] [ToString α] (s : ρ) : IO Unit := do
for a in streamOf s do
IO.println a
#eval h (toStream [1, 2, 3])
#print "-----"
#eval h [1, 2, 3]
#print "-----"
#eval h (toStream #[1, 2, 3])
#print "-----"
#eval h #[1, 2, 3, 4, 5, 6, 7][2:5]
#print "-----"
#eval h ([1, 2, 3], [4, 5, 6])