zesterer / tao

A statically-typed functional language with generics, typeclasses, sum types, pattern-matching, first-class functions, currying, algebraic effects, associated types, good diagnostics, etc.
https://tao.jsbarretto.com/
Mozilla Public License 2.0
1.09k stars 23 forks source link

Foreign function interface #35

Open sug0 opened 1 year ago

sug0 commented 1 year ago

Hi,

First of all, this looks great! Congratulations on this awesome project.

I just wanted to ask if there is currently any usable FFI, or one in the plans. I'd love to use tao as an embedded language in my projects. However, I realize this may go against your goals of totality, as FFI functions can perform arbitrary computations.

Cheers, Tiago

zesterer commented 1 year ago

I think the backend would likely need a substantial overhaul before it was ready for this, but it'll definitely need an FFI of some sort eventually.

It'll likely involve some equivalent of Rust's unsafe, but where the safety requirements are more stringent (i.e: no observable side effects, in the case of a pure function hooked up to FFI).

I've not put an enormous amount of thought into it at this stage (my focus is currently on the frontend) but I'm hoping to write a cranelift backend within the next few months, which opens ups the opportunity of implementing an FFI.

sug0 commented 1 year ago

In the event you pick something like the ML effect, all FFI functions could fallback to this. It would allow arbitrary I/O. AFAIK you can't really prove whether a FFI function will yield a pure computation, unless yeah you explcitly stated this with an unsafe hint of sorts.

Either way, looking forward to the implementation of this feature. Good luck!

zesterer commented 1 year ago

Thanks! I'm hoping I'll have some more time over the coming months to dive into the new backend and make this a reality!