title: Parameterised Modules in Erlang
body: <p>I was going through mochiweb source code and got to see something i never used before. The module declaration especially in <code>mochiweb_request</code> and <code>mochiweb_response</code> modules found in the mochiweb http library. Here is how the module begins:</p>
  
  <pre>
  -module(mochiweb_request,[Socket, Method, RawPath, Version, Headers]).
  -author(...).
  </pre>
  
  <p>Then in the module you see <code>get(socket) -> Socket;get(method)-> Method; ....</code><br>
  This has confused me. When i tried getting the module info of one of these such module, the compiler had added something: <code>{abstract,true}</code> in the return to: <br>
  <code>mochiweb_request:module_info().</code>. Infact, their documentation refers to these modules as <code>abstract modules</code>.</p>
  
  <p>I have searched google and found a paper on parameterised modules: the link is so big but am sure you will get the paper if u follow on <a href="http://www.google.co.ug/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBEQFjAA&amp;url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.58.79%26rep%3Drep1%26type%3Dpdf&amp;rct=j&amp;q=Parameterised%20modules%20in%20Erlang%20pdf&amp;ei=d_aBTc-tMdXX4gay4sDWCA&amp;usg=AFQjCNF1B71sV5kf_cGAZx7f8eNm9w5XlQ&amp;cad=rja" rel="nofollow">here</a></p>
  
  <p>These modules cannot be called directly but are called through instances of them selves. It makes modules behave as though they were funs. I have come to realise that its an unofficial feature in the runtime system. What confuses me is that the mochiweb guys are using it well!. In a mochiweb module, you will find your self writing:</p>
  
  <pre>
  loop(Req,_DocRoot)->
      "/" ++ Path = Req:get_path(),
      Body = Req:recv_body(),
      Method = Req:get(method),
      ...,
      ....,
      Response = Req:ok({"text.html;charset=utf-8",[],chunked}),
      Response:write_chunk("Some text here....."),
      ...
  </pre>
  
  <p>Trying to <code> io:format("\n\t Req = ~p~n",[Req])</code> reveales a complex data structure (a tuple) whose <code>element(1,Req) == mochiweb_request</code>. It is interesting!?!!!?<br><br>
  Question 1 is: Is it stable to use in production for now or i can wait till it is made official?<br><br>
  Question 2 is: How did the mochiweb guys get the confidence of using it, if it is not yet official?<br><br>
  Question 3: Why is it not yet official? (because, to me, it brings some Object Oriented features in)<br><br>
  Question 4: Is there anyone out there who has used it also? In which cases has he/she used these parameterised modules? Why? Can you point us there to see or post a link to some source code so we can find out more on this feature?<br><br>
  Last Question: No where in the Erlang Docs have i found this feature talked about. No text book, Not even <a href="http://erlang.org" rel="nofollow">home</a>. So how did those who have used it already find out how and why to use it? Has it already been included in the commercial version of the Erlang Run time system found <a href="http://www.erlang.se" rel="nofollow">here</a>?<br><br></p>