ocamlbuild - passing multiple statements in ocaml using "in" and "and" operations -


i wanted convert c++ code ocaml, i'm getting syntax error

c++ code

int** matrix(int n,int **a,int**b) { t=n/2; a11=new int*[t]; for(i=0;i<t;i++)     a11[i]=new int [t]; for(i=0;i<t;i++)     for(j=0;j<t;j++)         a11[i][j]=a[i][j];  a12=new int*[t]; for(i=0;i<t;i++)     a12[i]=new int [t]; for(i=0;i<t;i++)     for(j=0;j<t;j++)         a12[i][j]=a[i][j+t];  a21=new int*[t]; for(i=0;i<t;i++)     a21[i]=new int [t]; for(i=0;i<t;i++)     for(j=0;j<t;j++)         a21[i][j]=a[i+t][j]; } 

ocaml code

let matrix n x y = let t = n/2 in         let a11 = array.make_matrix t t 0 in         = 0 t-1             j = 0 t-1             a11.(i).(j) <- x.(i).(j)             done         done                     ,         a12 = array.make_matrix t t 0 in         = 0 t-1             j = 0 t-1             a12.(i).(j) <- x.(i).(j+t)             done         done                 ,         a21 = array.make_matrix t t 0 in         = 0 t-1             j = 0 t-1             a21.(i).(j) <- x.(i+t).(j)             done         done ;; 

the problem value of t not getting passed inside a12 , a21 arrays , getting unbounded.

the and let can't appear in body of let. instead, use multiple lets:

let matrix n x y =   let t = n/2 in   let a11 = array.make_matrix t t 0 in   = 0 t-1     j = 0 t-1       a11.(i).(j) <- x.(i).(j)     done   done;   let a12 = array.make_matrix t t 0 in   = 0 t-1     j = 0 t-1       a12.(i).(j) <- x.(i).(j+t)     done   done;   let a21 = array.make_matrix t t 0 in   = 0 t-1     j = 0 t-1       a21.(i).(j) <- x.(i+t).(j)     done   done 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -