moduleelixirelixir-iex

Inspecting BitString Data type in elixir interactive shell doesn't show info


Querying i("my string") returned data type of BitString

Running h(BitString) command in iex returns Could not load module BitString, got: nofile.

Compared to other data types that return module info on prompt, this particular module doesn't seem to serve any response. How do I view info regarding BitString in iex?

Queried i('my string') instead but this is of a List data type instead.

h(List) does return info on this module type.

I am interested in info pertaining to BitString data type

...


Solution

  • IEx.Helpers.i/1 prints a result of applying IEx.Info.info/1 to the term. As per documentation,

    • "Data type": Name of the data type. Usually the name of the module defining the data type.

    That said, BitString is just a name. If you are interested in the modules that are used to handle the type, you might read what i/1 printed to the end.

    iex|💧|1 ▸ i("f")
    Term
      "f"
    Data type
      BitString
    Byte size
      1
    Description
      This is a string: a UTF-8 encoded binary. It's printed surrounded by
      "double quotes" because all UTF-8 encoded code points in it are printable.
    Raw representation
      <<102>>
    Reference modules
      String, :binary
    Implemented protocols
      Collectable, IEx.Info, Inspect, List.Chars, String.Chars
    

    and see Reference modules: String, :binary.


    The confusion is most likely provoked by the fact that there is no explicit mapping type → module, because types in are not like types in OOP languages, the type is either defined by and then it has no defining module at all, only modules providing helper functions to deal with it, or is a struct, then it’s defined in some particular module.