From: Radu Grigore <radugrigore@gmail.com>
To: fa.caml@googlegroups.com
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Writing the function Set.map using first-class modules and 4.00 inference
Date: Fri, 2 Nov 2012 07:59:17 -0700 (PDT) [thread overview]
Message-ID: <15ab226e-6bc3-4122-bb40-de8ae2a2339b@googlegroups.com> (raw)
In-Reply-To: <fa.FUGAe9RTYsSPA4RwbpKO14B0oVo@ifi.uio.no>
Nice. I'll show you an alternative.
In your solution you write
let chrs = CharSet.map (module StringSet) strs (fun s -> s.[0])
In my solution you write
let chrs = CharSet.of_list (StringSet.map_l strs (fun s -> s.[0]))
It has about the same length.
The disadvantage of my solution is that the type of map_l is weird
StringSet.map_l : StringSet.t -> (string -> 'a) -> 'a list
The advantages are
1. It is possible to implement in O(n), rather than O(n lg n)
2. Works in 3.12.
Somebody should put the linear time [of_list] in the standard library.
Here is a simple, O(n lg n) implementation, similar to yours.
module FunkySet = struct
module type OrderedType = Set.OrderedType
module type S = Set.S
module Make (E : OrderedType) = struct
include Set.Make (E)
let of_list xs = List.fold_right add xs empty
let map_l s f = List.map f (elements s)
end
end
next parent reply other threads:[~2012-11-02 14:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fa.FUGAe9RTYsSPA4RwbpKO14B0oVo@ifi.uio.no>
2012-11-02 14:59 ` Radu Grigore [this message]
2012-11-02 15:11 ` Radu Grigore
2012-11-02 16:00 ` Gabriel Scherer
2012-11-02 16:21 ` Radu Grigore
[not found] <fa.yP8czrxqEGCABee05wzAlISIlN4@ifi.uio.no>
[not found] ` <fa.rve4x46ugIvZs4BizovvjOCeTG0@ifi.uio.no>
[not found] ` <fa.i9E+7rAvghoTZ1MXH4g+uL4dpCY@ifi.uio.no>
[not found] ` <fa.AX0JYJa8kXsH/YSZ08tuyBc8m+0@ifi.uio.no>
[not found] ` <fa.YAoOn2iUcpHbr53eeBfGhPTDvtM@ifi.uio.no>
2012-11-05 8:05 ` Radu Grigore
2012-11-05 10:12 ` Gabriel Scherer
2012-11-05 12:02 ` Radu Grigore
2012-11-01 21:00 Jeff Meister
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=15ab226e-6bc3-4122-bb40-de8ae2a2339b@googlegroups.com \
--to=radugrigore@gmail.com \
--cc=caml-list@inria.fr \
--cc=fa.caml@googlegroups.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