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

Use a function over a closure to handle poor inference #62

Merged
merged 1 commit into from
May 26, 2024

Conversation

jakobnissen
Copy link
Contributor

@jakobnissen jakobnissen commented May 25, 2024

The previous code pattern using takewhile relied on Julia's type inference to produce correct results. In particular, it relied on takewhile(f, x) |> collect to correctly infer to Vector{<:Tuple{Char, Any}}. However, type inference in Julia is an optimization, and should not be relied on to produce the correct answer.
Instead, use a normal function to replace the functional style of programming.

Edit: I haven't been able to run tests locally, so this might not work as-is. See #63

@tecosaur
Copy link
Collaborator

At a glance, this looks good, but it seems to be made against an old version of the repo?

@jakobnissen
Copy link
Contributor Author

jakobnissen commented May 25, 2024

Edit: Should be solved now.
This fails because the doctests run in a module which doesn't have access to read_while!. I don't understand why the doctests run in a different module from where the function is defined.
You can delete the docstring examples, but I'd think it was better if the problem was solved.

@tecosaur tecosaur force-pushed the inference branch 2 times, most recently from 30b8bf2 to d182c46 Compare May 26, 2024 02:59
The previous code pattern using `takewhile` relied on Julia's type
inference to produce correct results. In particular, it relied on
`takewhile(f, x) |> collect` to correctly infer to `Vector{Pair{<:Any,
Char}}`. However, type inference in Julia is an optimization, and should
not be relied on to produce the correct answer. Instead, use a normal
function to replace the functional style of programming.
@tecosaur tecosaur merged commit d3aa7e1 into JuliaLang:main May 26, 2024
4 checks passed
@jakobnissen jakobnissen deleted the inference branch May 27, 2024 08:24
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.

2 participants