Created
August 27, 2024 02:15
-
-
Save wolfspider/662908fd629262ace94dbc647898f5c5 to your computer and use it in GitHub Desktop.
More code alchemy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Underscores | |
| using Transducers | |
| using WebAssemblyCompiler | |
| function fpwasm(f) | |
| z = Iterators.countfrom() |> Map(x -> 2x) |> TakeWhile(x -> x < 10) | |
| j = reduce(+, z) | |
| return j | |
| end | |
| compile((fpwasm, Float64); filepath = "fpwasm.wasm", validate = true, optimize = false) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After working with FP for a while now I am thrilled that this can be done in such a straightforward way. Truly, without any extra library imports or anything we can see what the machine sees. We see the "while" in TakeWhile and we see the 2x in there as well as the countfrom(). In terms of authoring your own FP language this could be really useful if you do not want to implement everything in a higher level language but want the same guarantees.