caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] adding a function to an already existing module
@ 2013-01-11  5:07 Francois Berenger
  2013-01-11  5:14 ` Siraaj Khandkar
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Berenger @ 2013-01-11  5:07 UTC (permalink / raw)
  To: caml-list

Hello,

Let's say I want to add a function to the List module
of the std lib.

I'd like to do this without having to change list.ml
in the std lib.

And, my function need to have access to everything available
in list.ml (constructors, type names, etc.).

Is this possible and how to do this?

For example, I want to create MyList, and this module
is the exact List module plus some functions of my own.
Then, some of my code would use MyList instead of List.

Thanks a lot,
F.

PS: a full copy-paste of list.ml is considered cheating ;)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] adding a function to an already existing module
  2013-01-11  5:07 [Caml-list] adding a function to an already existing module Francois Berenger
@ 2013-01-11  5:14 ` Siraaj Khandkar
  2013-01-11  5:26   ` Francois Berenger
  0 siblings, 1 reply; 4+ messages in thread
From: Siraaj Khandkar @ 2013-01-11  5:14 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

module MyList = struct
    include List

   let foo l = bar l
end


On Jan 11, 2013, at 0:07, Francois Berenger <berenger@riken.jp> wrote:

> Hello,
> 
> Let's say I want to add a function to the List module
> of the std lib.
> 
> I'd like to do this without having to change list.ml
> in the std lib.
> 
> And, my function need to have access to everything available
> in list.ml (constructors, type names, etc.).
> 
> Is this possible and how to do this?
> 
> For example, I want to create MyList, and this module
> is the exact List module plus some functions of my own.
> Then, some of my code would use MyList instead of List.
> 
> Thanks a lot,
> F.
> 
> PS: a full copy-paste of list.ml is considered cheating ;)
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] adding a function to an already existing module
  2013-01-11  5:14 ` Siraaj Khandkar
@ 2013-01-11  5:26   ` Francois Berenger
  2013-01-11  5:47     ` Siraaj Khandkar
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Berenger @ 2013-01-11  5:26 UTC (permalink / raw)
  To: caml-list; +Cc: Siraaj Khandkar

On 01/11/2013 02:14 PM, Siraaj Khandkar wrote:
> module MyList = struct
>      include List
>
>     let foo l = bar l
> end

Not exactly, because:

module MyList = struct
   include List
   let expose_length_aux = length_aux (* stupid example *)
end

gives:
Error: Unbound value length_aux

While length_aux is available to code from list.ml.

> On Jan 11, 2013, at 0:07, Francois Berenger <berenger@riken.jp> wrote:
>
>> Hello,
>>
>> Let's say I want to add a function to the List module
>> of the std lib.
>>
>> I'd like to do this without having to change list.ml
>> in the std lib.
>>
>> And, my function need to have access to everything available
>> in list.ml (constructors, type names, etc.).
>>
>> Is this possible and how to do this?
>>
>> For example, I want to create MyList, and this module
>> is the exact List module plus some functions of my own.
>> Then, some of my code would use MyList instead of List.
>>
>> Thanks a lot,
>> F.
>>
>> PS: a full copy-paste of list.ml is considered cheating ;)
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] adding a function to an already existing module
  2013-01-11  5:26   ` Francois Berenger
@ 2013-01-11  5:47     ` Siraaj Khandkar
  0 siblings, 0 replies; 4+ messages in thread
From: Siraaj Khandkar @ 2013-01-11  5:47 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

On Jan 11, 2013, at 0:26, Francois Berenger <berenger@riken.jp> wrote:

> On 01/11/2013 02:14 PM, Siraaj Khandkar wrote:
>> module MyList = struct
>>     include List
>> 
>>    let foo l = bar l
>> end
> 
> Not exactly, because:
> 
> module MyList = struct
>  include List
>  let expose_length_aux = length_aux (* stupid example *)
> end
> 
> gives:
> Error: Unbound value length_aux
> 
> While length_aux is available to code from list.ml.

Oh, I didn't realize you really did mean "everything"! :)

Not much you can do if the interface doesn't expose it though, it's kind of the point. Copying and moding list.ml does seem like the only way to get _exactly_ what you want then.



> 
>> On Jan 11, 2013, at 0:07, Francois Berenger <berenger@riken.jp> wrote:
>> 
>>> Hello,
>>> 
>>> Let's say I want to add a function to the List module
>>> of the std lib.
>>> 
>>> I'd like to do this without having to change list.ml
>>> in the std lib.
>>> 
>>> And, my function need to have access to everything available
>>> in list.ml (constructors, type names, etc.).
>>> 
>>> Is this possible and how to do this?
>>> 
>>> For example, I want to create MyList, and this module
>>> is the exact List module plus some functions of my own.
>>> Then, some of my code would use MyList instead of List.
>>> 
>>> Thanks a lot,
>>> F.
>>> 
>>> PS: a full copy-paste of list.ml is considered cheating ;)
>>> 
>>> --
>>> Caml-list mailing list.  Subscription management and archives:
>>> https://sympa.inria.fr/sympa/arc/caml-list
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-11  5:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-11  5:07 [Caml-list] adding a function to an already existing module Francois Berenger
2013-01-11  5:14 ` Siraaj Khandkar
2013-01-11  5:26   ` Francois Berenger
2013-01-11  5:47     ` Siraaj Khandkar

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).