kjnilsson / fez

F# to core erlang compiler experiment
MIT License
280 stars 16 forks source link

RFC 1: Arrays #15

Open kjnilsson opened 7 years ago

kjnilsson commented 7 years ago

Arrays have no direct equivalent in core erlang. A lot of code that uses arrays can be quite directly translated to using lists instead (fsharp Lists or Seqs). The exception to this is code that mutates the array directly. That said a lot of code may use arrays and it would be good to cover arrays in some shape or form.

The most direct equivalent of erlang's binary() type is the byte array so it would make sense to translate operations on byte arrays to operations on binaries.

Arrays are generic so this leave a lot of types uncovered. Should the non mutable aspects and apis of Array.* that aren't byte arrays simply be translated as erlang lists? Are there any other options?

rascala commented 7 years ago

Could it be done as a NIF? Store an array of pointers to blobs with some methods to manage it?

How much work would it be?

kjnilsson commented 7 years ago

Manual memory management just doesn't play nicely with the erlang vm typically.

tsloughter commented 6 years ago

Does it have to be a data structure available in core and not the stdlib? There is the array module, http://erlang.org/doc/man/array.html, which while not being an array like F#'s may give better performance when implementing than a list.

kjnilsson commented 6 years ago

@tsloughter yes I am leaning towards using the array module for any non-binary types with a fez specific Array.setElement function that returns the array. The problem is that fsharp arrays are mutable and there is no realistic means of supporting functions ( like Array.set) that return unit. The gnarly bit of translating one language into another. :)

tsloughter commented 6 years ago

Ah yea, set on mutable needs to return unit :(. I'd be curious to a NIF like @rascala suggests, using resources to reference the array. But maybe garbage collection issues with that...

kjnilsson commented 6 years ago

Erlang (or rather hipe) has mutable arrays but only of immediate types. See hipe_ bif

Probably not a practical approach though. On Wed, 27 Dec 2017 at 16:46, Tristan Sloughter notifications@github.com wrote:

Ah yea, set on mutable needs to return unit :(. I'd be curious to a NIF like @rascala https://github.com/rascala suggests, using resources to reference the array. But maybe garbage collection issues with that...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kjnilsson/fez/issues/15#issuecomment-354141047, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIDlLp7JrDsL0i2SFWn4AxUNEZTBEUXks5tEnRYgaJpZM4N98jr .