caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: Martin DeMello <martindemello@gmail.com>
Cc: "caml-list\@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] "subclassing" a char map
Date: Mon, 16 Sep 2013 08:20:57 +0400	[thread overview]
Message-ID: <87txhlbdna.fsf@golf.niidar.ru> (raw)
In-Reply-To: <CAFrFfuHwyDw1u41bnWnZNzUATRn+5inB1h8udW09sDVH134Wjg@mail.gmail.com> (Martin DeMello's message of "Sun, 15 Sep 2013 15:29:25 -0700")

Martin DeMello <martindemello@gmail.com> writes:

> I have a char multiset defined via
>
> module MultiSet = Map.Make(struct type t = char let compare = compare end)
>
> Now I would like to split off a distinct type that can only contain
> A-Z as keys. What's the best way to do this?
>
> martin

Not sure, that I correctly understood your needs... but you can
implement «A-Z keys» as an abstract type, contained in a module with the
following signature:

module type Caps =  sig
  type t
  val create: char -> t option
  val compare: t -> t -> int
  val project: t -> char
end

Next, you can instatiate a Map from abstract type Cap.t to 'a:

module CapMap = Map.Make(Caps)

where Caps is an implementation, conforming to the signature Caps. For
example like this:

module Caps : Caps = struct
    type t = char
    let create = function
      | 'A'..'Z' as ch -> Some ch
      | otherwise      -> None
    let compare = compare
    let project ch = ch
end

-- 
         (__) 
         (oo) 
   /------\/ 
  / |    ||   
 *  /\---/\ 
    ~~   ~~   
...."Have you mooed today?"...

  reply	other threads:[~2013-09-16  4:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-15 22:29 Martin DeMello
2013-09-16  4:20 ` Ivan Gotovchits [this message]
2013-09-16  4:31   ` Martin DeMello
2013-09-16  7:42     ` Goswin von Brederlow
2013-09-16 21:09       ` Martin DeMello
2013-09-17  8:13     ` oleg

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=87txhlbdna.fsf@golf.niidar.ru \
    --to=ivg@ieee.org \
    --cc=caml-list@inria.fr \
    --cc=martindemello@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).