List Info

Thread: "ocaml_beginners"::[] Function from signature




"ocaml_beginners"::[] Function from signature
user name
2006-07-24 23:40:25
Folks,

What would a function with this type signature look like?

val (‘and‘) : int -> int -> int

I would like to use it as

1 `and` 2

I got the idea from LexiFI but I can't even figure out if
the above  
signature has backticks or something else.

	Thanks, Joel






Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


"ocaml_beginners"::[] Function from signature
user name
2006-07-25 00:05:06
On Tue, 25 Jul 2006, Joel Reymont wrote:

> Folks,
>
> What would a function with this type signature look
like?
>
> val (?and?) : int -> int -> int
>
> I would like to use it as
>
> 1 `and` 2
>
> I got the idea from LexiFI but I can't even figure out
if the above
> signature has backticks or something else.

You can't do that in regular OCaml. It only works with
non-alphanumeric 
operators, e.g. "let ( ++ ) a b = ..."

If you need it very badly you can use that Camlp4 hack, at
your own risk:
   http://
martin.jambon.free.fr/ocaml.html#infix

Example:

   (* code using the syntax extension *)
   infix plus = ( + )
   infix times = ( * )
   let fortynine = pred 3 plus 5 times 7

   (* is converted into: *)
   let fortynine = ((pred 3) + 5) * 7


Martin

--
Martin Jambon, PhD
http://martin.jambon.fre
e.fr


Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 



"ocaml_beginners"::[] advice: ocaml -> c/c++
user name
2006-07-25 14:56:22
Hello all,
I just started working with ocaml as an extension
language and would like some advice on a good and or
'right' way to do the following.

I have a c++ class which contains a large amount of
data.  This will either be arrays of structs/classes
or stl containers of structs/classes.

What is a good way for ocaml to access this data? 
This would probably be either a sequential iterator or
map function.

Any thoughts are appreciated.



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 


Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 



"ocaml_beginners"::[] advice: ocaml -> c/c++
user name
2006-07-25 15:43:01
On Tue, Jul 25, 2006 at 07:56:22AM -0700, Brian Makin wrote:
> I just started working with ocaml as an extension
> language and would like some advice on a good and or
> 'right' way to do the following.

By "extension language" I'm going to assume
that you mean people will
write programs in OCaml which will call down to C++
functions written
using the OCaml FFI
(http://caml.inria.fr/pub/docs/manual-ocaml/manual032.ht
ml).

> I have a c++ class which contains a large amount of
> data.  This will either be arrays of structs/classes
> or stl containers of structs/classes.
> 
> What is a good way for ocaml to access this data? 
> This would probably be either a sequential iterator or
> map function.

I guess there are several ways.  The easiest would seem to
be to
create a module like this:

--------------------------------------------------
myData.mli -
type t  (* Private data handle. *)

type datum = { some_data : int; other_data : float }
   (* Type of each array element. *)

external get_handle : unit -> t =
"my_data_get_handle"
external length : t -> int = "my_data_length"
external get : t -> int -> datum =
"my_data_get"
external set : t -> int -> datum -> unit =
"my_data_set"
------------------------------------------------------------
---

You'll then need to write the associated C functions like
my_data_get,
etc., which will get and set elements in the array, and do
translation
between OCaml data structures and your C/C++ data
structures.

The translation can sometimes be avoided if your data
structures are
sufficiently simple (eg. structures composed entirely of C
doubles)
but I don't think you can avoid the copy.

Another way may be to make the data appear as an Extlib Enum
(http://ocaml-lib.so
urceforge.net/).  It won't be very fast though.

If your data is an array of some very simple structure (eg.
an array
of array of chars, ints or floats), then you could also look
at
mapping the C++ array directly into OCaml's accessible
memory by using
the standard Bigarray module.  This will be the fastest way,
but least
flexible, and certainly won't work for STL structures.

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


------------------------ Yahoo! Groups Sponsor
--------------------~--> 
Something is new at Yahoo! Groups.  Check out the enhanced
email design.
http://us.click.yahoo.com/TktRrD/gOaOAA/yQLSAA/saFolB/TM

------------------------------------------------------------
--------~-> 

Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


"ocaml_beginners"::[] advice: ocaml -> c/c++
user name
2006-07-25 18:03:32

--- Richard Jones <richannexia.org> wrote:

Yes, I'm going to have users write OCaml which calls
c++ library functions.

I'll poke around this a bit more.

Thanks for the input.


> On Tue, Jul 25, 2006 at 07:56:22AM -0700, Brian
> Makin wrote:
> > I just started working with ocaml as an extension
> > language and would like some advice on a good and
> or
> > 'right' way to do the following.
> 
> By "extension language" I'm going to
assume that you
> mean people will
> write programs in OCaml which will call down to C++
> functions written
> using the OCaml FFI
>
(http://caml.inria.fr/pub/docs/manual-ocaml/manual032.ht
ml).
> 
> > I have a c++ class which contains a large amount
> of
> > data.  This will either be arrays of
> structs/classes
> > or stl containers of structs/classes.
> > 
> > What is a good way for ocaml to access this data? 
> > This would probably be either a sequential
> iterator or
> > map function.
> 
> I guess there are several ways.  The easiest would
> seem to be to
> create a module like this:
> 
> --------------------------------------------------
> myData.mli -
> type t  (* Private data handle. *)
> 
> type datum = { some_data : int; other_data : float }
>    (* Type of each array element. *)
> 
> external get_handle : unit -> t =
> "my_data_get_handle"
> external length : t -> int =
"my_data_length"
> external get : t -> int -> datum =
"my_data_get"
> external set : t -> int -> datum -> unit =
> "my_data_set"
>
------------------------------------------------------------
---
> 
> You'll then need to write the associated C functions
> like my_data_get,
> etc., which will get and set elements in the array,
> and do translation
> between OCaml data structures and your C/C++ data
> structures.
> 
> The translation can sometimes be avoided if your
> data structures are
> sufficiently simple (eg. structures composed
> entirely of C doubles)
> but I don't think you can avoid the copy.
> 
> Another way may be to make the data appear as an
> Extlib Enum
> (http://ocaml-lib.so
urceforge.net/).  It won't be
> very fast though.
> 
> If your data is an array of some very simple
> structure (eg. an array
> of array of chars, ints or floats), then you could
> also look at
> mapping the C++ array directly into OCaml's
> accessible memory by using
> the standard Bigarray module.  This will be the
> fastest way, but least
> flexible, and certainly won't work for STL
> structures.
> 
> Rich.
> 
> -- 
> Richard Jones, CTO Merjis Ltd.
> Merjis - web marketing and technology -
> http://merjis.com
> Team Notepad - intranets and extranets for business
> - http://team-notepad.com
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 


------------------------ Yahoo! Groups Sponsor
--------------------~--> 
Great things are happening at Yahoo! Groups.  See the new
email design.
http://us.click.yahoo.com/SktRrD/hOaOAA/yQLSAA/saFolB/TM

------------------------------------------------------------
--------~-> 

Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


"ocaml_beginners"::[] advice: ocaml -> c/c++
user name
2006-07-26 20:25:54
Perhaps Jeff's "Forklift" project can help.
 
http://jhen
rikson.org/forklift/index.html

 
________________________________

From: ocaml_beginners@yahoogroups.com
[mailto:ocaml_beginners@yahoogroups.com] On Behalf Of Brian
Makin
Sent: Tuesday, July 25, 2006 7:56 AM
To: ocaml_beginners@yahoogroups.com
Subject: "ocaml_beginners"::[] advice: ocaml
-> c/c++




Hello all,
I just started working with ocaml as an extension
language and would like some advice on a good and or
'right' way to do the following.

I have a c++ class which contains a large amount of
data. This will either be arrays of structs/classes
or stl containers of structs/classes.

What is a good way for ocaml to access this data? 
This would probably be either a sequential iterator or
map function.

Any thoughts are appreciated.


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.4/399 - Release
Date: 7/25/2006
 


------------------------ Yahoo! Groups Sponsor
--------------------~--> 
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/WktRrD/lOaOAA/yQLSAA/saFolB/TM

------------------------------------------------------------
--------~-> 

Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )