functional-programming

How difficult is it to learn functional programming languages?

Given that a persona has extensive experience in different imperative programming languages right from C to JAVA. Whats the learning curve for functional programming languages such a Haskell ? ...

Help translating this Java codeblock to Clojure?

I'm getting my feet wet with Clojure, and trying to get used to functional programming. I've been translating various imperative functions from other languages into their Clojure equivalents -- and so far everything has been going well. However, I've now run into a sticking point and I have no idea how to translate this Java method int...

Extending an existing type in OCaml

I've been doing some OCaml programming lately to learn the language and to get more acquainted with functional programming. Recently, I've started to think that I'd like to be able to extend an existing type (either built in-or one of my own), for example: type bexp = And of bexp * bexp | Or of bexp * bexp | Xor of bexp * bexp | Not ...

How to do numerical simulation with immutable data in Clojure?

I'm using Clojure and I need to run a small simulation. I have a vector of length n (n is usually between 10 and 100) that holds values. On each simulation round (maybe 1000 rounds together), one of the values in the vector is updated randomly. I guess I could do this by using an Java array and calling the aset method, but this would bre...

High-level multithreading/concurrency abstractions for .NET

I just wondered why, unlike Scala, F# or Haskell, the basic .NET framework (as available in C# or VB) seems to have very little native support for higher level concurrency patterns. There are basic mechanisms available - locks, monitors, the thread pool - but what about Synchronized variables (MVar) Synchronous channels Asynchronous ...

Concurrent map/foreach in scala

I have an iteration vals: Iterable[T] and a long-running function without any relevant side effects: f: (T => Unit). Right now this is applied to vals in the obvious way: vals.foreach(f) I would like the calls to f to be done concurrently (within reasonable limits). Is there an obvious function somewhere in the Scala base library? Some...

Iterating through a list of lists?

I have Items from a certain source (populated from somewhere else): public class ItemsFromSource{ public ItemsFromSource(string name){ this.SourceName = name; Items = new List<IItem>(); } public string SourceName; public List<IItem> Items; } Now in MyClass I have Items from several sources (populated from so...

How far should I take referential transparency?

I am building a website using erlang, mnesia, and webmachine. Most of the documentation I have read praises the virtues of having referentially transparent functions. The problem is, all database access is external state. This means that any method that hits the database is no longer referentially transparent. Lets say I have a user ob...

Erlang and Java interfacing

I am particularly interested in knowing the performance implications of the Erlang component when doing this kind of interfacing. After learning about Erlang I thought that it might be useful to code certain components of an application in Erlang where I need to use the high concurrency and throughput that it provides. Has any one tried...

Tips for optimizing sql commands worrying about legacy

The concern with the legacy of the SQL statements is a constant in my head. Especially when SCRUM is used, where the code has no owner, that is, all must be able to repair and maintain each piece. Optimizing SQL procedures usually means converting it into a set-based commands and using special operators. I need tips to keep the code work...

When choosing a functional programming language for use with LLVM, what are the trade-offs?

Let's assume for the moment that C++ is not a functional programming language. If you want to write a compiler using LLVM for the back-end, and you want to use a functional programming language and its bindings to LLVM to do your work, you have two choices as far as I know: Objective Caml and Haskell. If there are others, then I'd like...

Clojure: Unable to resolve symbol. I'm stumped.

When I paste this code into a REPL, it works fine: (use 'clojure.contrib.seq-utils) (defn- random-letter [] (char (+ (rand-int 26) 97))) (defn- random-digit [] (rand-int 10)) (defn- random-password "Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa" [] (let [password (interpose '((random-digit))...

Hashtable indexed on several fields

Hello SO, I'm currently programming an OCaml module defining a type corresponding to a CPU register. The interface of this module is the following : (* * Defines a type which represents a R3000 register. *) type t = | R0 (* Always 0 *) | AT (* Assembler te...

Inventing a suitable infix operator symbol for liftM

When working with monadic expressions in Haskell, the use of liftM's (even in infix position) often seems quite unaesthetic and verbose to me. Most other monadic primitives (>>=, >>) and even liftM's pure pendant $ are infix operators. This makes me think why there is no operator symbol for monadic lifting. Do you have reasonable, cons...

Haskell too many where clauses, any alternate suggestions

I am totally new in Haskell and when writing small programs i normally end up with too many where clauses to check many things in the function, so it is good practice to write where clauses or is there any other good alternatives for this ? for example in the code below i tried to find if there is ant duplicate elements in each row of t...

Is functional programming a subset of imperative programming?

One of the main characteristics of functional programming is the use of side-effectless functions. However, this can be done in an imperative language also. The same is true for recursion and lambda functions (for example C++0x). Therefore I wonder whether imperative programming languages are a superset of functional ones. ...

F# :: traversing lists There and Back Again

This is homework :-) Write a function that counts the number of elements in the list that are larger than or equal to the average (using integer division for simplicity). Using just a single traversal of the list structure! I already have a solution to this, BUT it involves ref variable changed from closure foo'. I'm interested in a...

Nested Lambdas in Python

Hi, I'm a beginning python programmer, and I'd like someone to clarify the following behavior. I have the following code: env = lambda id: -1 def add(id, val, myenv): return lambda x: val if x == id else myenv(id) test_env = add("a", 1, env) test_env_2 = add("b", 2, test_env) When I look up "a" in test_env, it functions correc...

pitfalls/disadvantages of functional programming

When would you NOT want to use functional programming? What is it not so good at? I am more looking for disadvantages of the paradigm as a whole, not things like "not widely used", or "no good debugger available". Those answers may be correct as of now, but they deal with FP being a new concept (an unavoidable issue) and not any inheren...

Why purely functional languages instead of "impure" functional languages?

What's the advantage, for someone who is not a theoretical computer scientist, of learning a purely functional language like Haskell or Erlang instead of an "impure" language with a strong functional component, like Python or version 2 of the D programming language? My arguments are as follows: No paradigm is perfect. Languages that ...