Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 531

Why does my recursion never terminate in OCaml?

$
0
0
let qrec=Queue.create ()let rec queueaddrec1 n= if n==1 then  Queue.add 1 qrec else  Queue.add n qrec;  queueaddrec1 (n-1)let ()= queueaddrec1 5; Queue.iter print_int qrec;

VScode told me the following line will never return. I don't why. When I ran it I got a endless loop.

queueaddrec1 5

If I write this:

let rec queueaddrec2 n= if n>1 then  Queue.add n qrec;  queueaddrec (n-1) else  Queue.add 1 qrec

I get another error:

This expression has type 'a but an expression was expected of type ('b->'b Queue.t->unit)->int->int Queue.t->'aThe type variable 'a occurs inside('a->'a Queue.t->unit)->int->int Queue.t->'b

Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>