functional-programming

Reduce Permutation

I need an algorithm that can map the runs in a permutation to a single number, but also reduce the subsequent numbers. So a run is a sequential set of numbers in a permutation that is sorted and in-order. In the list, 1;2;3;5;6;4 there are two runs, 1;2;3 and 5;6. I want to replace these with a single number, a minimum, so if, after re...

Distinctive traits of the functional languages

It is known that all functional languages share some basic properties like using functions as basic building block for programs with all the consequences like using recursion instead of iteration. However, some fundamental differences also exist. Lisp uses a single representation for both Lisp code and data, while ML has no standard repr...

Going functional in C#

I know that in C# 3.0 you can do some functional programming magic with Linq and lambda expression and all that stuff. However, is it really possible to go completely "pure" functional in C#? By "pure" I mean having methods that are pure (always gives the same output for the same input) and completely free of side-effects. How do we get ...

Convert existing snippet of code to use Array.ForEach

We know that if you have: var aa = new [] { 1, 2, 3, 4, 5 }; for (int i = 0; i < aa.length; ++i) { aa[i] = aa[i] + 1; } it's really var aa = new [] { 1, 2, 3, 4, 5 }; Arrary.ForEach(aa, a => a + 1); However, what if I had this: var aa = new [] { 1, 2, 3, 4, 5 }; var ab = new [] { 1, 2, 3, 4, 5 }; for (int i = 0; i < aa.length;...

What are some pros/cons to various functional languages?

I know of several functional languages - F#, Lisp and its dialects, R, and more. However, as I've never used any of them (although the three I mentioned are on my "to-learn" list), I was wondering about the pros/cons of the various functional languages out there. Are there significant pros/cons, both in learning the language and in any r...

Vulnerability in the functional programming paradigm?

A few days ago, there were a couple questions on buffer overflow vulnerabilities (such as Does Java have buffer overflows?, Secure C and the universities - trained for buffer overflow, to name a couple) which can happen in imperative programming languages such as C. In functional programming, (from the very limited exposure I've had fro...

Creating objects on-the-fly in OCaml

I am attempting to learn OCaml by using compiled code instead of the top-level; however, much of the sample code online seems to appeal to the latter. I would like to create a new Foo within a method of an object per below. This code does not compile, citing a syntax error with the doFooProc definition. class bar = object (self) metho...

Declarative thread safety in .NET

Hi, I need to make an existing app thread safe. Due circumstances (see below), I decided to use one single ReaderWriterLock for the entire graph of business objects. All methods/properties must look like these: public int MyReadOperation(string inputParam) { rwLock.AcquireReaderLock(10000); try { // do all read operation...

Functional style C# API design (returning function parameter augmented with calculation result)

Hi, There is a question regarding usage of functional programming techiques in C# code. Example Let we have interface interface IGraph { /*contains vertices and edges*/} Suppose we need to layout graph's vertices (assign Point to each vertex). interface ILayoutInfo { Point GetVertexPoint(vertex); } Simple layout route can have ...

Are the functional programming features provided in C# rich enough? What's missing

Are the functional programming features provided in C# rich enough? Would a LISP programmer miss LISP when programming in C#.. whats missing?? ...

Concise Haskell book

In a blog post regarding his JavaScript book, Doug Crockford says I relied on two models when I wrote JavaScript: The Good Parts. The first was Kernighan and Richie's The C Programming Language. It is a brilliant little book. I thought there should be a K&R for JavaScript. When it seems that most tech books are sold by the pound, it ...

JUMP and CALL

How is a JUMP and CALL instruction different? How does it relate to the higher level concepts such as a GOTO or a procedure call? (Am I correct in the comparison?) This is what I think: JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called. On...

What are some impressive examples of functional code?

I'm getting a bit tired of having to code explicitly for multicore if I want more speed, particularly when I'm just writing a one-off script. My dev box already has 8 cores and that number is going up a lot faster than the clock speed. Functional languages seem to offer a potential escape hatch, but I haven't put in the effort to maste...

Tuples in Ruby

Does anyone use tuples in Ruby? If so, how may one implement a tuple? Ruby hashes are nice and work almost as well, but I'd really like to see something like the Tuple class in Python, where you can use . notation to find the value for which you are looking. I'm wanting this so that I can create an implementation of D, similar to Dee for...

Is it possible to change the step size of the built-in haskell range function or literal?

The default [1..5] gives this [1,2,3,4,5] and can also be done with the range function. Is it possible to change the step size between the points, so that I could get something like the following instead? [1,1.5,2,2.5,3,3.5,4,4.5,5] ...

Hardware Assisted Garbage Collection

I was thinking on ways that functional languages could be more tied directly to their hardware and was wondering about any hardware implementations of garbage collection. This would speed things up significantly as the hardware itself would implicitly handle all collection, rather than the runtime of some environment. Is this what LISP...

Can any algorithmic problem be solved in a purely functional way?

I've been contemplating programming language designs, and from the definition of Declarative Programming on Wikipedia: This is in contrast from imperative programming, which requires a detailed description of the algorithm to be run. and further down: ... Any style of programming that is not imperative. ... It then goes on to...

Why can't I implicitly cast a Delegate with Extension methods?

I'm trying to figure out a way to automatically cast something to an Action or Func and the best I can come up with is something like this: [TestFixture] public class ExecutionTest { public void BadMethod() { throw new Exception("Something bad happened"); } [Test] public void TestBadMethod() { //...

Trouble in F# Land with map

Ok. I'm not asking for a plssendcodezkthx. But I am somewhat new to FP and I'm trying to figure out how to do this, because I know the code I have won't accomplish what I'd like to achieve. So all arguments about optimization aside, here is my code Then I'll explain. let moveBoids boids = boids |> List.map (fun(boid) -> let...

Examining the internals of the functions in Haskell

I am a Haskell newbie, though had a previous Lisp/Scheme experience. Right now I am looking at the examples from SICP and trying to implement them in Haskell to get more hands-on experience. In the lecture 3b authors present a function for computing the derivatives symbolically. It contains, among others, the following lines: (define (d...