caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* basic question about Functors
@ 2009-12-22 22:48 Keith Sheppard
  2009-12-22 23:38 ` [Caml-list] " Eric Cooper
  0 siblings, 1 reply; 2+ messages in thread
From: Keith Sheppard @ 2009-12-22 22:48 UTC (permalink / raw)
  To: caml-list

Hello,

I'm still figuring out OCaml syntax and I have a very basic question.
I've looked through the Functors section of the ocaml tutorial
(http://www.ocaml-tutorial.org/modules) and so I see how I can declare
a StringMap like:

> module StringMap = Map.Make(String);;

Now I can define a function like:

> remove_fish = StringMap.remove "fish"

What I'm confused about is what type signature I can use in the mli
file if I want to make the remove_fish function public...

Thanks in advance
Keith


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] basic question about Functors
  2009-12-22 22:48 basic question about Functors Keith Sheppard
@ 2009-12-22 23:38 ` Eric Cooper
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Cooper @ 2009-12-22 23:38 UTC (permalink / raw)
  To: caml-list

On Tue, Dec 22, 2009 at 05:48:57PM -0500, Keith Sheppard wrote:
> I've looked through the Functors section of the ocaml tutorial
> (http://www.ocaml-tutorial.org/modules) and so I see how I can declare
> a StringMap like:
> 
> > module StringMap = Map.Make(String);;
> 
> Now I can define a function like:
> 
> > remove_fish = StringMap.remove "fish"
> 
> What I'm confused about is what type signature I can use in the mli
> file if I want to make the remove_fish function public...

The top level (or "ocaml -i") is your friend:

    # module StringMap = Map.Make(String);;
    module StringMap :
    ...
    # let remove_fish = StringMap.remove "fish";;
    val remove_fish : '_a StringMap.t -> '_a StringMap.t = <fun>

You could use this type signature as-is, but the '_a type variables are more
restrictive than necessary due to the "value restriction". To make it
fully general, use "eta expansion":

    # let remove_fish m = StringMap.remove "fish" m;;  
    val remove_fish : 'a StringMap.t -> 'a StringMap.t = <fun>

-- 
Eric Cooper             e c c @ c m u . e d u


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-12-22 23:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-22 22:48 basic question about Functors Keith Sheppard
2009-12-22 23:38 ` [Caml-list] " Eric Cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).