axelson
Scenic Core Team
Is there anywhere that “MFA” is described in detail in the official Elixir documentation? I’ve tried to find it before but was unable to. Am I just missing it somewhere?
(I know what it is I just to have somewhere to link to in my own documentation for anyone unfamiliar with the concept).
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
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 am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
peerreynders
In context of typespecs:
For
child_spec()Erlang usesmfargs()to refer to a{M,F,A}tuple (module, function atom, arguments list -Kernel.apply/3,:erlang.apply/3).kip
Its a good question! The nearest I could find was an erlang type definition in the docs at Types and Function Specifications — Erlang System Documentation v29.0.2
tfwright
This has recently come up for me as I am working on a library where I am adding support for a “function reference” argument. Previously I was expecting
{module, function, args}even though theargscomponent was not really used for anything simply because that format seems to be universal in Elixir. But due to a behavior change I really need to know what arity to expect and I’m sort of at a loss when it comes to best practice!I am using NimbleOptions and there is no built in support for this. In fact, the documentation has this line which was puzzling to me right off the bat:
(There is also
{:fun, arity}but in my use case the module is also variable, edit: and also on closer reading this appears to be for functions of set arity?)I have to wonder why it seems that in Elixir
mfahas come to mean specifically the args variation and I don’t think I’ve seen amfargstype in the wild…voughtdq
Do you mean for enforcing that it has a specific arity or supporting functions that have unknown arities? Not sure about best practices as I prefer to support them all as a matter of flexibility.
For unknown, the
{SomeModule, :function, args}is what I would reach for. I rarely use it in practice though:Then all the others -
{SomeModule, :function}&SomeModule.function/2fn _a, _b -> :ok endFor expected arity, it’s just the others (i.e. no
{m, f, a}).Not sure about that option for NimbleOptions, but I think it can take a capture like
&Enum.map/2, which would cover the bases of requiring a specific arity. Then it’s just a matter of taste on whether you want to support{SomeModule, :function}.Edit:
Yeah I was actually surprised to see it called
aritybecause that would imply it should be{MyModule, :my_fun, 2}, right? It would be interesting to know the historical context of calling the third elementarity.tfwright
Both, I think. Possibly I am missing some angle but in my use case I intended to require the user specify a function, which requires specifying an arity, without making any assumptions about the arguments.
I suppose I could allow them to specify only the function name, but in that case I would have to simply pick the first function defined in the module with that name, which seems like undesirable ambiguity. I could see why in many cases it wouldn’t matter, since the user controls the function and the option, so it can be left to them to pass the correct configuration that matches their implementation, but in my case I can’t infer the desired arity from the option (for reasons I don’t think are relevant here).
Mostly however I am just confused about the
mfa/mfargsmismatch between Elixir and Erlang.voughtdq
Did a little code excavation and it turns out that, even in the Erlang repository “mfa” can mean both, but if in the “args” variant, I see a lot more adhoc type specs. It’s probably one of those cases where its interchangeable use has caused it to have multiple meanings. It does help that you can match on the third element for the various cases:
{m, f, a} when is_integer(a) and a >= 0- known arity{m, f, :_}- unknown arity{m, f, a} when is_list(a)- args instead of arityI think capturing
&SomeModule.function/2is more familiar, but{SomeModule, :function, 2}does make it easier to check if the function exists (vs having to check the capture withFunction.info/2).soyjeansoy
afair I read
mfain typespec section in Elixir hexdocs.