Oh hey, this looks awesome!
Somebody can say “hey, this is not a constructor function, it’s a syntactic sugar for value, literal Elixir term”. But anyway, this is expression and value of this expression is Elixir struct of URI type. For simplicity I’ll call this thing as default constructor . And this default constructor is always public. Indeed, you can write in any place or your program something like this:
I so agree, it is, by definition, A Constructor of the type.
This is mostly caused by elixir being deficient in its typing system, which comes from it modeling after erlang instead of trying to fix that bug in erlang.
And then Full Lambda Calculus! Church Encoding! Lol. As I’m reading through I’m curious when church encoding of integers will come up, or the various combinators. ^.^
This looks like a data driven DSEL I saw in Elixir, though function wrapping.
iex> s0.(:pop, nil)
** (RuntimeError) For value of the type Stack got unsupported METHOD=:pop with SECURITY_KEY=nil
Heh, cute, I’m guessing you are using a make_ref() for the security key as they are unique references in the beam world? I’ve not looked at the code yet.
Lambda types are inferior in performance to classical data types like records or structs. I
Yep definitely figured that at the start.
- λ-type constructors and setters ~
2 times slower then default constructors and setters for structs
- λ-type getters ~
6 - 12 times slower then pattern matching on structs (but this is still pretty nice performance)
Not ‘as’ bad as expected though, that’s within the realm of usability considering structs are raw beam code…
You can run benchmarks with mix bench command in terminal
Ooo, my favorite things! ^.^
At the moment we can’t properly use Elixir protocols with values of λ-types (because of the same reason). I have couple ideas about it and maybe will fix it.
I have a couple of ideas for it to work with my ProtocolEx library though, hmm… If only Tuple Calls weren’t removed from the BEAM! That still bugs me to no end… >.>
Internal state of value of λ-type is vulnerable for reading (not writing!) through Function.info/2 core function. At the moment I don’t know how to fix it:
Eh, there are ways to but it would slow down the implementation more so not sure it is worth it…
It’s possible to read internal state using this function, but it’s still impossible to create new corrupted value of λ-type based on this internal state. So all immutable and private data is still really immutable and all values of λ-type are still valid and safe.
Ehhhh, actually you can… ^.^;
I’m leaving work right now or I’d show you how you can break this. 
Ping me tomorrow if you are curious, but in essence you can create almost any internal beam type with :erlang.binary_to_term, including picking it apart with the inverse.
This is a fun looking project though, no church encoding, just lambda encapsulation though, lol. ^.^