Hal9000
For example, how does Kernel‘s to_string “know” that it belongs to String.Chars?
If I do a defimpl String.Chars, for: MyMod – how does to_string know
to call my implemented function?
Just curious.
Trending in Discussions
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
This is the start of my Elixir learning journal/journey. I plan to share my journey in this thread and am open to all feedback, construct...
New
This is where the projects in the Hologram Showcase get posted: apps built with Hologram and libraries made for it. New ones go up usuall...
New
Hi everyone!
This is our fourth edition. Last year, 1,000+ developers took part. The more of you who answer, the more useful the results...
New
Never used it. I know it’s well-liked by some and the authors have put a lot of work into it.
Aside from that, is there a community cons...
New
I’ve been fixing race condition / crash bugs in an open source org, for a few months now and almost all of them had the same problem. The...
New
Over the years I’ve tried dozens of time tracking and invoicing apps, and Harvest was the only one I liked. Primarily due to its relative...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #code-sync
- #exunit
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #ai
- #authentication
- #elixirconf-us
- #umbrella
- #full-time-contract
- #blog-post
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-eu
- #distillery
- #security
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
The module
String.Charshas a function ofto_string, and the kernelto_stringjust callsString.Chars.to_string.What a protocol does it auto-generate the protocol functions from a list of definitions. So when you
defimpl String.Chars, for: MyModor whatever the syntax was then it defines a module, and at protocol consolidation time it scans all the compiled modules to see what is impl’d (just an attribute marker is all it is, ofprotocol_impl, so for your example it would have an attribute on the module ofprotocol_impl: [protocol: String.Char, for: MyMod]), and it uses those to build functions that just test, so in your example it would generate a function of:I have an enhanced Protocol library that you can see the code of how it works if curious too. Can also look at the elixir code as well.
NobbZ
This does only explain it roughly, but should be just enough to understand it.
Kernel.to_string/1is a macro, expanding toString.Chars.to_string/1String.Chars.to_string/1matches on its argument, and without protocol consolidation it dispatches toString.Chars.xxx.to_string/1wherexxxis the qualified alias of the struct or elixirs internal type. With consolidation thosexxximplementations are integrated directly intoString.Chars.to_string/1.With consolidation it might look like this (simplified):
without consilidation more like this: