Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:13:13+00:00 2026-05-13T18:13:13+00:00

I can see why parameterised modules are used so much, as they allow us

  • 0

I can see why parameterised modules are used so much, as they allow us to do things like:

X = y:new("param").

X:action1().
X.get_property():

: which feels very OO. However, this is only an experimental feature in Erlang and I hear it may be removed, so I need to find an alternative.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:13:13+00:00Added an answer on May 13, 2026 at 6:13 pm

    Parametrised modules are nothing but a shortcut on the first argument of a function. See these two examples:

    -module(y, [Name,Age]).
    -compile(export_all).
    
    action1() -> io:format("Hello, ~p!~n",[Name]).
    
    get_age() -> Age.
    

    Run it:

    1> c(y).
    {ok,y}
    2> X = y:new("Fred",22).
    {y,"Fred",22}
    3> X:action1().
    Hello, "Fred"!
    ok
    4> X:get_age().
    22
    

    Now without parametrized stuff:

    -module(y).
    -compile(export_all).
    
    action1([Name,_]) -> io:format("Hello, ~p!~n",[Name]).
    
    get_age([_,Age]) -> Age.
    

    Running it:

    1> c(y).
    {ok,y}
    2> X = ["Fred",22].
    ["Fred",22]
    3> y:action1(X).
    Hello, "Fred"!
    ok
    4> y:get_age(X).
    22
    

    The biggest ‘advantage’ of parametrized modules is that you shift the burden of carrying state from a variable to a module name. This is in appearance much simpler to someone not used to ‘the Erlang way’, but it clashes with conventional styles of code.

    It’s not just a question of being experimental or not. You throw out referential transparency and the semantics to immutable variables become a bit weird. A good example of this is to imagine you add the following functions to a parametrized module:

    ret_fn() -> fun(Age) -> Age + 5 end.
    

    When compiling the module, you get the warning ./y.erl:8: Warning: variable 'Age' shadowed in 'fun'. This is warning you that you are using the name of a predefined variable within the head clause of an anonymous function. However, a quick look at the ret_fn/0 function shows absolutely NO sign of where that variable is from.

    Now imagine that you use the variable Name for any other purpose; you will get a run time error telling you ** error: no match of right hand side value < ... >.

    The point I’m making is that parametrized modules reduce the amount of typing you need to do at the expense of logical simplicity. Not just for you, but for any other Erlang programmer to work on your code.

    On top of that, tools like dialyzer, TypEr, tidiers and whatnot have no guarantee to support these idioms. These tools are pretty useful, too! Don’t dismiss them. (Edit: newer versions of Erlang (R13B04+) now guarantee that support)

    The best alternative to parametrized modules is to avoid them and use what every other Erlang programmer outside of mochiweb is using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What I ended up doing was creating a decision shape… May 14, 2026 at 9:53 pm
  • Editorial Team
    Editorial Team added an answer I just found out how stupid I am! :D You… May 14, 2026 at 9:53 pm
  • Editorial Team
    Editorial Team added an answer Is it possible? Yes, but you need to do an… May 14, 2026 at 9:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.