Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] Module parameterization by ints

Expand Messages
  • Matthieu Dubuget
    It seems to me that this is exactly the same? define a functor MyFunctor like this: module MyFunctor (S : sig val sz : int end) = struct ... S.sz ...
    Message 1 of 8 , Jul 1, 2009
    • 0 Attachment
      It seems to me that this is exactly the same?

      define a functor MyFunctor like this:
      module MyFunctor (S : sig val sz : int end) =
      struct
      ... S.sz ... ← in your module, you now have
      access to S.sz
      end



      Your module can now be generated like this:

      module MyModule = MyFunctor (struct let sz = 3 end);;

      Hoping this helps?
    • Vincent Aravantinos
      ... Good starting points: - if you accept an imperative FIFO : module Queue of the standard library - if you want a functional FIFO : module Fqueue of Jane
      Message 2 of 8 , Jul 1, 2009
      • 0 Attachment
        --- In ocaml_beginners@yahoogroups.com, Phil Tomson <rubyfan@...> wrote:
        > Following up on this question: I need to do something very similar to
        > the original poster's question but the answer given isn't quite clear
        > to me.
        >
        > I would like to create a FIFO that is limited to N slots. I'd like to
        > create a FIFO module that can be parameterized by an integer (N) so
        > that I can create a FIFO of a specific size. How would I go about
        > doing this?

        Good starting points:
        - if you accept an imperative FIFO : module Queue of the standard library
        - if you want a functional FIFO : module Fqueue of Jane Street's Core library (http://ocaml.janestreet.com/?q=node/13, also available with Godi)
        - finally module Squeue of Jane Street's Core library seems to do kinda what you want

        This last module's signature contains the following:

        (** [create maxsize] returns a synchronized queue bounded to have no more than
        [maxsize] elements. *)
        val create : int -> 'a t

        Then you can apply the previous answers (but maybe it is this last point which is the problem ?).

        Cheers
      • Ashish Agarwal
        ... If Squeue.create returns a queue bounded to a specific size, wouldn t that be a non-functorized solution? Then, you no longer need the solutions previously
        Message 3 of 8 , Jul 1, 2009
        • 0 Attachment
          > Then you can apply the previous answers
          If Squeue.create returns a queue bounded to a specific size, wouldn't that
          be a non-functorized solution? Then, you no longer need the solutions
          previously mentioned.


          On Wed, Jul 1, 2009 at 4:47 AM, Vincent Aravantinos <
          vincent.aravantinos@...> wrote:

          >
          >
          > --- In ocaml_beginners@yahoogroups.com <ocaml_beginners%40yahoogroups.com>,
          > Phil Tomson <rubyfan@...> wrote:
          > > Following up on this question: I need to do something very similar to
          > > the original poster's question but the answer given isn't quite clear
          > > to me.
          > >
          > > I would like to create a FIFO that is limited to N slots. I'd like to
          > > create a FIFO module that can be parameterized by an integer (N) so
          > > that I can create a FIFO of a specific size. How would I go about
          > > doing this?
          >
          > Good starting points:
          > - if you accept an imperative FIFO : module Queue of the standard library
          > - if you want a functional FIFO : module Fqueue of Jane Street's Core
          > library (http://ocaml.janestreet.com/?q=node/13, also available with Godi)
          > - finally module Squeue of Jane Street's Core library seems to do kinda
          > what you want
          >
          > This last module's signature contains the following:
          >
          > (** [create maxsize] returns a synchronized queue bounded to have no more
          > than
          > [maxsize] elements. *)
          > val create : int -> 'a t
          >
          > Then you can apply the previous answers (but maybe it is this last point
          > which is the problem ?).
          >
          > Cheers
          >
          >
          >


          [Non-text portions of this message have been removed]
        • Vincent Aravantinos
          ... Well he can stil functorize it if he wants. The advantage being to bound all possibly created squeues to have the wanted size thus avoiding potential
          Message 4 of 8 , Jul 1, 2009
          • 0 Attachment
            --- In ocaml_beginners@yahoogroups.com, Ashish Agarwal <agarwal1975@...> wrote:
            >
            > > Then you can apply the previous answers
            > If Squeue.create returns a queue bounded to a specific size, wouldn't that
            > be a non-functorized solution? Then, you no longer need the solutions
            > previously mentioned.

            Well he can stil functorize it if he wants. The advantage being to bound all possibly created squeues to have the wanted size thus avoiding potential mistakes.
          • Phil Tomson
            ... Thanks, that should do what I need. Phil
            Message 5 of 8 , Jul 1, 2009
            • 0 Attachment
              On 7/1/09, Matthieu Dubuget <matthieu.dubuget@...> wrote:
              > It seems to me that this is exactly the same?
              >
              > define a functor MyFunctor like this:
              > module MyFunctor (S : sig val sz : int end) =
              > struct
              > ... S.sz ... ← in your module, you now have
              > access to S.sz
              > end
              >
              >
              >
              > Your module can now be generated like this:
              >
              > module MyModule = MyFunctor (struct let sz = 3 end);;
              >
              > Hoping this helps?
              >

              Thanks, that should do what I need.

              Phil
            Your message has been successfully submitted and would be delivered to recipients shortly.