Skip to content

Instantly share code, notes, and snippets.

@jasonrute
Created December 11, 2020 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrute/bb62203cb7debba0122ef69740ac078d to your computer and use it in GitHub Desktop.
Save jasonrute/bb62203cb7debba0122ef69740ac078d to your computer and use it in GitHub Desktop.
structure InfRange where
(start : Nat := 0)
(step : Nat := 1)
@[inline] partial def InfRange.forIn {β : Type u} {m : Type u → Type v} [Monad m] (range : InfiniteRange) (init : β) (f : Nat → β → m (ForInStep β)) : m β :=
let rec @[specialize] loop (j : Nat) (b : β) : m β := do
match ← f j b with
| ForInStep.done b => pure b
| ForInStep.yield b => loop (j + range.step) b
loop range.start init
def main : IO Unit := do
-- loop forever
for i in InfRange.mk 0 1 do
if i >= 100 then break
println! "{i}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment