Skip to content

Instantly share code, notes, and snippets.

@wolfspider
Created August 27, 2024 02:15
Show Gist options
  • Select an option

  • Save wolfspider/662908fd629262ace94dbc647898f5c5 to your computer and use it in GitHub Desktop.

Select an option

Save wolfspider/662908fd629262ace94dbc647898f5c5 to your computer and use it in GitHub Desktop.
More code alchemy
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)
@wolfspider
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment