caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin DeMello <martindemello@gmail.com>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] "subclassing" a char map
Date: Sun, 15 Sep 2013 21:31:34 -0700	[thread overview]
Message-ID: <CAFrFfuGg3n4m5AU1QtE6GahMgdfADfP6ohbrxd5zpM8ju-g97w@mail.gmail.com> (raw)
In-Reply-To: <87txhlbdna.fsf@golf.niidar.ru>

Ah, thanks, that will do very nicely. I just wanted a type of char map
I couldn't insert anything else other than A-Z into, that the
typechecker would prevent me from mixing with the regular char map.

martin

On Sun, Sep 15, 2013 at 9:20 PM, Ivan Gotovchits <ivg@ieee.org> wrote:
> 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:31 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
2013-09-16  4:31   ` Martin DeMello [this message]
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=CAFrFfuGg3n4m5AU1QtE6GahMgdfADfP6ohbrxd5zpM8ju-g97w@mail.gmail.com \
    --to=martindemello@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=ivg@ieee.org \
    /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).