# tail recursion vs. forward recursion

Filed under:
|
##### ocaml

Can someone give me the difference between these two kinds recursions and example?

specifically in ocaml. Thanks

© Stack Overflow or respective owner

• #### tail recursion vs. forward recursion

as seen on Stack Overflow - Search for 'Stack Overflow'
Can someone give me the difference between these two kinds recursions and example? specifically in ocaml. Thanks >>> More

• #### Are there advantages for using recursion over iteration - other than sometimes readability and elegance?

as seen on Programmers - Search for 'Programmers'
I am about to make two assumptions. Please correct me if they're wrong: There isn't a recursive algorithm without an iterative equivalent. Iteration is always cheaper performance-wise than recursion (at least in general purpose languages such as Java, C++, Python etc.). If it's true that recursion… >>> More

• #### Python recursive function error: "maximum recursion depth exceeded"

as seen on Stack Overflow - Search for 'Stack Overflow'
I solved Problem 10 of Project Euler with the following code, which works through brute force: def isPrime(n): for x in range(2, int(n**0.5)+1): if n % x == 0: return False return True def primeList(n): primes = [] for i in range(2,n): if isPrime(i): … >>> More

• #### How does the recursion here work?

as seen on Stack Overflow - Search for 'Stack Overflow'
code 1: public static int fibonacci (int n){ if (n == 0 || n == 1) { return 1; } else { return fibonacci (n-1) + fibonacci (n-2); } } how can you use fibonacci if you haven't gotten done explaining what it is yet? I've been able to understand… >>> More

• #### Dynamic Programming Recursion and a sprinkle of Memoization

as seen on Stack Overflow - Search for 'Stack Overflow'
I have this massive array of ints from 0-4 in this triangle. I am trying to learn dynamic programming with Ruby and would like some assistance in calculating the number of paths in the triangle that meet three criterion: You must start at one of the zero points in the row with 70 elements. Your… >>> More

• #### F# and OCaml

as seen on Stack Overflow - Search for 'Stack Overflow'
I hear that F# is derived from OCaml. How true is this statement? That is to say, are the resources available for learning OCaml useful to someone who wants to learn F#? What are the major differences between the two languages (aside from the fact that F# is .NET)? >>> More

• #### Higher-order type constructors and functors in Ocaml

as seen on Stack Overflow - Search for 'Stack Overflow'
Can the following polymorphic functions let id x = x;; let compose f g x = f (g x);; let rec fix f = f (fix f);; (*laziness aside*) be written for types/type constructors or modules/functors? I tried type 'x id = Id of 'x;; type 'f 'g 'x compose = Compose of ('f ('g 'x));; type 'f fix = Fix… >>> More

• #### Good projects to learn OCaml and F#

as seen on Stack Overflow - Search for 'Stack Overflow'
After learning the basic syntax, reading some non-trivial code is a fast way to learn a language. We can also learn how to design a library/software during reading others' code. I have following lists. A Chess program in OCaml by Tomek Czajka. Hal Daumé has written several machine learning libraries… >>> More

• #### OCaml beginner needs help: What is wrong?

as seen on Stack Overflow - Search for 'Stack Overflow'
Code: let rec get_val (x, n) = match x with [] -> -1 | if (n=0) then (h::_) -> h else (_::t) -> get_val(t, n-1) ;; Error message: Characters 55-57: | if (n=0) then (h::_) - h ^^ Error: Syntax error >>> More

• #### Tail-recursive merge sort in OCaml

as seen on Stack Overflow - Search for 'Stack Overflow'
Hello world! I’m trying to implement a tail-recursive list-sorting function in OCaml, and I’ve come up with the following code: let tailrec_merge_sort l = let split l = let rec _split source left right = match source with | [] -> (left, right) | head :: tail ->… >>> More