
I don't really have an opinion on the two alternatives, they both seem fine to me. I just wanted to chime in on the following:
On 16 Jun 2020, at 16:44, ☂Josh Chia (謝任中)
wrote: Is there just no way to return a struct by value on the stack?
There is indeed no way to do so, and this is a fundamental limitation not of Haskell, but of the ABI on your platform. To call unknown code, you need to know, well, how to call it. On most platforms the only portable/reliable specification for this is the C ABI (which is why every FFIs to/via C), however this ABI just doesn't defined how passing structs as arguments or returning them as results should work (at least not on any platform I'm aware of). This means that *no* language can portably pass structs to/from code via the C ABI (including C code compiled by, say, different compilers!). Kind regards, Merijn