Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include examples from discussion #13

Draft
wants to merge 8 commits into
base: StagedSL
Choose a base branch
from

Conversation

EmilyOng
Copy link
Collaborator

@EmilyOng EmilyOng commented Feb 7, 2024

This PR introduces a few examples and fixes:

  • Fibonacci
  • Accumulator Factory
  • All Zeros

@EmilyOng EmilyOng marked this pull request as draft February 7, 2024 08:38
let rec integers x n =
if n = 0 then []
else x :: integers (x + 1) (n - 1)

let rec fill_list f n =
if n = 0 then []
else f () :: fill_list f (n - 1)
else let x = f () in x :: fill_list f (n - 1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of evaluation changes:

let rec fill_list f n =
  if n = 0 then []
  else let x = f () in x :: fill_list f (n - 1)

let test () =
  let x = ref 1 in
  let incrementer () = let r = !x in x := !x + 1; r in

  fill_list incrementer 10 (* should give [1, ..., 10] but currently produces [10, ..., 1] *)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant