6
votes
1answer
117 views

Better or more idiomatic way to apply a sequence of functions in Haskell

This is one of my Haskell solutions to a variation of the N-Queens problem, where the queens can move like knights in addition to their normal moves. It has been optimized somewhat to avoid ...
6
votes
1answer
101 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
4
votes
1answer
825 views

Tail-recursive factorial

Is there anything what could be improved on this code? def factorial(n: Int, offset: Int = 1): Int = { if(n == 0) offset else factorial(n - 1, (offset * n)) } ...
4
votes
1answer
55 views

Good OCaml style

I wanted to write a small but non-trivial function in OCaml to test my understanding. I have only a basic understanding of the libraries, and no idea at all of what is considered good style. The ...
4
votes
1answer
540 views

Recursively walking a tree to build up a new one

Could this be better factored as a reduce? ...
2
votes
2answers
483 views

simple stupid F# async telnet client

Did I write this code to correctly be tail call optimized? Am I forcing computations more than I need with !? Did I generally write this asynchronously correctly to ...
2
votes
1answer
97 views
1
vote
3answers
229 views

List-flattening function in erlang feels too wordy

I wrote a tail-recursive list-flattening function, but I'm not too happy with it. a) Is tail-recursion necessary here, or will the function be optimized without it? b) It's ugly how many clauses ...
1
vote
3answers
286 views

How to improve this functional python fast exponentiation routine?

I have the following python functions for exponentiation by squaring : ...
1
vote
1answer
121 views

Merge Sort Program

I have written the following program to implement merge sort in F#. Can you please review this and let me know how can I write this in the most functional way (also most efficient and concise)? In ...
1
vote
1answer
185 views

Recursive Determinant

The following code I devised to compute a determinant: ...