Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
call ocaml from R
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-06-25 (02:17)
From: Peng Zhang <pczhang@g...>
Subject: call ocaml from R
Hi folks,

I need some help from you. What I want to do is that my main program
is in R and I want to implement part of it with ocaml.

The following is an example.

/* mysin.R */
mysin <- function(x)
  .C("mysin", as.double(x), r = double(1))$r

/* */
let sin_ml x = sin x
let _ = Callback.register "sin_ml" sin_ml

I want to use sin defined in in mysin.R

Then I write the following stub code

/* mysin.c */
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/callback.h>

void mysin(double * x, double * r){
  value * closure_f;
  closure_f = caml_named_value("sin_ml");
  *r = Double_val(caml_callback(*closure_f, caml_copy_double(*x)));

It isn't working right now. What I am not sure about is what to put in

Can somebody help with me this? Thank you very much!