Proposal: Have :array get its own protocol implementation

29 views
Skip to first unread message

ad...@a-corp.co.uk

unread,
Sep 1, 2021, 1:55:42 PM9/1/21
to elixir-lang-core
Hello,

Not sure what the go is with protcols, but given that there is an is_array function, would it be possible to have an erlang :array dispatch to its own implementation for protocols?

Right now if you pass an :array to a protocol it treats it as a Tuple (which is reasonable as right now that's what it is implemented as).

Best

Adam

José Valim

unread,
Sep 1, 2021, 2:02:25 PM9/1/21
to elixir-l...@googlegroups.com
We supported tuples before but it led to a bunch of false positives on records looking like tuples. I think even the the is_array check does not guarantee it is actually an array. It is only a shallow check.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9faf9f62-72ad-41bd-9179-ee25d155cf65n%40googlegroups.com.

Wiebe-Marten Wijnja

unread,
Sep 1, 2021, 2:42:23 PM9/1/21
to elixir-l...@googlegroups.com

There are two userspace approaches that see some usage to deal with types like `:array`:

- There are some alternative/more powerful (but therefore also less portable/general/widespread) alternative 'protocol' implementations,
  such as `protocol_ex`. These will help if you have new protocols, but will not help to integrate new types with preexisting 'normal' protocols.

- A couple of libraries out there that wrap `:array` with a struct and implement common protocols for these (as well as, in the case of arrays, possibly the Access behaviour).
  For something like `:array`, this should not be significantly slower even though an extra wrapper is used.
  This technique integrates well with preexisting protocols, but does require you to use the wrapped types in your own code rather than e.g. `:array` directly.

~Marten/Qqwy

OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages