From: Julien Moutinho <julien.moutinho@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] How do apply functors with module constraints?
Date: Fri, 19 Oct 2007 02:32:58 +0200 [thread overview]
Message-ID: <20071019003258.GA22312@localhost> (raw)
In-Reply-To: <ff8pmk$eik$1@ger.gmane.org>
On Thu, Oct 18, 2007 at 07:19:05PM -0400, Alan Falloon wrote:
> I am having a really hard time figuring out how to instantiate a functor
> when its arguments have module constraints. Here is an example:
> [...]
>
> However, this fails to compile because when I try to make module Joe
> because Bob.Pie and Daisy.Pie aren't the same. Fair enough, thats what
> abstraction is for, however I can't figure out the syntax to instantiate
> Joe!
>
> [...]
>
> Now I'm fresh out of ideas.
Here is a new one:
% cat fapie.ml
module type PIE =
sig
type pie
val bake : unit -> pie
val eat : pie -> unit
end
module type BAKER =
functor (Pie: PIE) ->
sig
val dozen : unit -> Pie.pie array
end
module type PIG =
functor (Pie: PIE) ->
sig
val feed : Pie.pie -> unit
end
module Farmer
(Pie : PIE)
(Baker : BAKER)
(Pig : PIG) =
struct
module Baker = Baker(Pie)
module Pig = Pig(Pie)
let feed_pigs () =
let pies = Baker.dozen () in
Array.iter Pig.feed pies
end
module Apple : PIE =
struct
type pie = Pie of string
let bake () = Pie "apple"
let eat (Pie "apple") = ()
end
module Bob
(Pie : PIE) =
struct
let dozen () = Array.init 13 (fun _ -> Pie.bake ())
end
module Daisy
(Pie : PIE) =
struct
let feed p = Pie.eat p; print_endline "OINK!"
end
module Joe = Farmer(Apple)(Bob)(Daisy)
let () = Joe.feed_pigs()
% ocaml fapie.ml
File "fapie.ml", line 36, characters 12-30:
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
Pie ""
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
OINK!
Hope this helps,
Julien.
next prev parent reply other threads:[~2007-10-19 0:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-18 23:19 Alan Falloon
2007-10-19 0:32 ` Julien Moutinho [this message]
2007-10-19 8:20 ` [Caml-list] " Nicolas Pouillard
2007-10-19 8:21 ` Andreas Rossberg
2007-10-22 14:54 ` Alan Falloon
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=20071019003258.GA22312@localhost \
--to=julien.moutinho@gmail.com \
--cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).