Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] functors with style?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-11-19 (19:45)
From: Krishnaswami, Neel <neelk@c...>
Subject: Re: [Caml-list] functors with style?
William Harold Newman [] wrote:
> If I did use explicit functor expressions everywhere, it'd be readable
> enough: if my intent is make the things exactly parallel, then using
> the explicit functor expressions everywhere would make that obvious,
> so I'd be happy. But because my previous closest approach to functors
> was using templates in g++, I'm predisposed to worry about the
> compiler emitting multiple copies of the functor expansion if I don't
> give the functor expansion a home in a particular file. Is that an
> issue in Ocaml?

If I understand the papers that the people at INRIA wrote, 
there is no such template-expansion-like problem in Ocaml.

A functor is compiled to what is essentially a function that
takes a record as an argument (the module it receives as an
argument), and returns a record of functions and values. So
code generation happens only once for each functor, and each
functor application takes a very small amount of memory at
link time.

A lot of the issues surrounding functors become much clearer
when you get an operational model for how it works: think of
the ML module language as a small functional language, with
functors mapping to lambdas and functor applications mapping
to function applications. Then your intuition about how
(for example) closures are represented can guide you towards
understanding how modules and functors work. 

When I got this I was seriously impressed with how elegantly
it all works out. (Or as we said in my native South Carolina:
Them ML hackers sure are pretty smart, ain't they? :)

Neel Krishnaswami
Bug reports:  FAQ:
To unsubscribe, mail  Archives: