I was going through mochiweb source code and got to see something i never used before. The module declaration especially in mochiweb_request
and mochiweb_response
modules found in the mochiweb http library. Here is how the module begins:
-module(mochiweb_request,[Socket, Method, RawPath, Version, Headers]). -author(...).
Then in the module you see get(socket) -> Socket;get(method)-> Method; ....
This has confused me. When i tried getting the module info of one of these such module, the compiler had added something: {abstract,true}
in the return to:
mochiweb_request:module_info().
. Infact, their documentation refers to these modules as abstract modules
.
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 here
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:
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....."), ...
Trying to io:format("\n\t Req = ~p~n",[Req])
reveales a complex data structure (a tuple) whose element(1,Req) == mochiweb_request
. It is interesting!?!!!?
Question 1 is: Is it stable to use in production for now or i can wait till it is made official?
Question 2 is: How did the mochiweb guys get the confidence of using it, if it is not yet official?
Question 3: Why is it not yet official? (because, to me, it brings some Object Oriented features in)
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?
Last Question: No where in the Erlang Docs have i found this feature talked about. No text book, Not even home. 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 here?