amuletml / amulet

An ML-like functional programming language
https://amulet.works/
BSD 3-Clause "New" or "Revised" License
326 stars 15 forks source link

Returning a top-level export instead of as part of a table #299

Open s5bug opened 3 years ago

s5bug commented 3 years ago

How to emulate

return function(importantArgData)
  return { stuff = "stuff" }
end

in Amulet? The best that I can do is generating a table with --export:

let foo importantArgData = { stuff = "stuff" }
do
  return { foo = function(importantArgData) return { stuff = "stuff" } end }
end
s5bug commented 3 years ago

What would be the best way to handle this? --export looking for an expression at the end of the file instead of exporting all top-level declarations? I.e.

let foo = ???
let bar = ???

function (x : int) -> foo (bar x)

is a valid Amulet file?

More likely there's a better way, but I haven't been able to think of it.