From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] how to use functors?
Date: Sat, 19 Nov 2005 22:11:35 +0000 [thread overview]
Message-ID: <200511192211.35365.jon@ffconsultancy.com> (raw)
In-Reply-To: <ad8cfe7e0511191337q4de3366cuaa1ca62be993f56b@mail.gmail.com>
On Saturday 19 November 2005 21:37, Jonathan Roewen wrote:
> Hi,
>
> Prolly the wrong list, but I can't access caml.inria.fr's documentation ATM
> =/
This is probably one for the beginners list. There is a brief explanation of
functors on my "Benefits of OCaml" pages:
http://www.ffconsultancy.com/free/ocaml/
under "Modules and Functors".
Feed the functor a module with a sig that matches that required by the functor
and it will spit out another module based upon the one you gave.
For example, the built-in "String" module contains the "t" type and "compare"
function definitions required by the "Set.Make" functor. So applying "String"
to "Set.Make" gives you a module implementing sets of strings:
# module SetOfStrings = Set.Make(String);;
module SetOfStrings :
sig
type elt = String.t
type t = Set.Make(String).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
end
> How do I use a functor? For example: build a weak hashtable from Weak
> module? Seems useful for building a cache... if only I knew how to use
> it =P
You may want something more controllable.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
next prev parent reply other threads:[~2005-11-19 22:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-19 21:37 Jonathan Roewen
2005-11-19 22:11 ` Jon Harrop [this message]
2005-11-22 15:22 ` Christophe Raffalli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200511192211.35365.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox