1

I am writing program to count Bell numbers, it is my first big program in OCaml. I want to use loop While in the loop While, but there is syntax error. Please correct it. Thanks.

I'm using site http://try.ocamlpro.com/

let rec factorial n =   
if n < 2 
   then 1
else 
   n * factorial(n-1)

let rec newton n k =
factorial n / (factorial k * factorial (n-k))

let bell = [|1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0|]

let i = ref 2
let k = ref 0
let x = ref 0
let z = ref 0
let s = ref 0

here you need to choose number u want to calc e.g. 4

let n = ref 4

if !n != 0 || !n != 1 then
    while !i <= !n do   
         while !k <= (!i-1) do
                x := newton (!i-1) !k;
                s := !s + (!x * bell.(!k));
                k := !k + 1 ;
                z := !k + 1
             done   
      s:=0;
      i:= !i + 1;
   done
else 
bell.(!n)<-1
  • should use Num to calc Bell numbers, but I first I I would like to make the program work on int

1 Answer 1

1

You can try to add ; after 1st done.

Sign up to request clarification or add additional context in comments.

1 Comment

@czarnywdowiec please, accepts the answere when it solves your problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.