ParkeTgo

Untitled

Aug 16th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. {-
  2. Build a list by calling the supplied function on all `Natural` numbers from `0`
  3. up to but not including the supplied `Natural` number
  4.  
  5. Examples:
  6.  
  7. ```
  8. ./generate 5 Bool Natural/even = [ True, False, True, False, True ]
  9.  
  10. ./generate 0 Bool Natural/even = [] : List Bool
  11. ```
  12. -}
  13. let generate
  14. : Natural → ∀(a : Type) → (Natural → a) → List a
  15. = λ(n : Natural)
  16. → λ(a : Type)
  17. → λ(f : Natural → a)
  18. → List/build
  19. a
  20. ( λ(list : Type)
  21. → λ(cons : a → list → list)
  22. → List/fold
  23. { index : Natural, value : {} }
  24. ( List/indexed
  25. {}
  26. ( List/build
  27. {}
  28. ( λ(list : Type)
  29. → λ(cons : {} → list → list)
  30. → Natural/fold n list (cons {=})
  31. )
  32. )
  33. )
  34. list
  35. (λ(x : { index : Natural, value : {} }) → cons (f x.index))
  36. )
  37.  
  38. in generate
Add Comment
Please, Sign In to add comment