What does this Erlang type syntax for a map mean?

I’m looking at Erlang code (specifically the brod library for Kafka) and I’m puzzled by the type declarations. I see lines like this:

-type cg() :: #brod_cg{}.

which I assume means “cg is a map”. But I don’t know why its got the name in front of it. Is that actually providing anything for the type system? This is as opposed to something like this that makes more sense to me (since its declaring keys and the types of values for those keys).

-type fold_limits() :: #{ message_count => pos_integer()
                        , reach_offset => offset()
                        }.

It is a notation for erlang records.
https://erlang.org/doc/reference_manual/typespec.html#typeinrecords

2 Likes

I am not an Erlang expert but I think that is the record syntax, see here for more. Erlang -- Records

1 Like

See https://groups.google.com/g/elixir-lang-talk/c/6kn7J2XnFg8/m/I5poTNCEHwAJ for discussion of Record vs Struct vs Map by José Valim.