josevalim

josevalim

Creator of Elixir

That’s precisely what they do.

That was exactly the scenario. There was a protocol implementation for that record as well, which is why everything failed.

0
Post #21
OvermindDL1

OvermindDL1

If it was designed to have such an implementation and it did in fact have such an implementation, then how did it fail I’m quite curious? That sounds like a failure in the implementation itself then?

0
Post #22
josevalim

josevalim

Creator of Elixir

The implementation was not expecting a keyword list as the second element of the tuple. That’s how the false positive happened. We could tell the implementations to carefully guard its types but that would be yet another downside of the proposed approach. And we are not statically typed, so we can’t rule it out upfront.

0
Post #23
OvermindDL1

OvermindDL1

Ah so it was less that the failing use was a record and more that it’s name happened to be used for a different purpose, that definitely sounds like part of that fluffy bit of dynamic typing. ^.^

Yeah this is what I require for ProtocolEx, the match and guard is supposed to be very exact for what you want and it gets placed ‘into’ the protocol consolidation directly to allow easy fallback matching (along with a lot of optimizations in the way of inlining code or even allowing macro’s directly into the protocol implementations and more, it’s quite a bit faster and very few of these optimizations rely on the matching part, they could be in normal protocol’s as well).

Although I’d like to see records-with-limitations supported in protocols I can see why you don’t. If you ever do get interested in support however I can try to find time to write a PR for it. ^.^

In the mean time ProtocolEx exists and supports it all, in exchange for a compiler hook entry in mix.exs (I still really really wish Mix could automatically detect these with a sorter for them…). :slight_smile:

I’m also still very curious why the implementation of MyDecimal is so much faster than Decimal though, I’m still worried I screwed it up somehow if anyone wants to look at it. ^.^;

1
Post #24
wojtekmach

wojtekmach OP

Hex Core Team

We’ve just released stable versions of Decimal v1.9.0 and v2.0.0, happy arbitrary precision computations :slight_smile:

6
Post #25
— All posts loaded —