functional-programming

Functional approach to parse hierarchical CSV

Hi all. I'm trying to create a piece of code but cannot get it working. The simplest example I can think of is parsing some CSV file. Suppose we have a CVS file, but the data is organized in some kind of hierarchy in it. Like this: Section1; ;Section1.1 ;Section1.2 ;Section1.3 Section2; ;Section2.1 ...

Will writing my Web appication in a functional programming language such as Haskell or Erlang make it more scalable than J2EE?

Hi I am writing a Facebook application that would use a Postgres DB along with Facebook APIs and run on Amazon EC2. (and I am hoping for heavy loads ) With Java, I know that DB would be my primary bottleneck and concurrency limitations of Tomcat would be the secondary bottleneck. I could alleviate DB issues with caching and concurren...

Technical choices in unmarshalling hash-consed data

There seems to be quite a bit of folklore knowledge floating about in restricted circles about the pitfalls of hash-consing combined with marshalling-unmarshalling of data. I am looking for citable references to these tidbits. For instance, someone once pointed me to library aterm and mentioned that the authors had clearly thought about...

Efficient recursion in functional programming vs. inefficient recursion in different paradigms

As far as I know recursion is very elegant but unefficient in OOP and procedural programming (see the wonderful "High Order perl", Mark Jason Dominus). I had some informations that in functional programming recursion is fast - keeping its elegance and simplicity. Could someone confirm and possibly amplify this? I am thinking in terms of...

How to update records with fields, which support in-place modifications, in a functional way in OCaml?

Assume I have a record with a Hashtbl field: type rec = { table : (int, int) Hashtbl.t; value : int; (* more fields... *) } How should I update it in a functional way, i.e. something like that: let new_rec = { old_rec with value = old_rec.value + 1 ; (* that's ok *) table = hash_table + (key -> value binding...

Why does Haskell give me a type error if I hardcode a return value?

I'm really at a loss to explain why this is a type error: foo :: (Eq a) => a -> a foo _ = 2 Can anyone explain? ...

f# return sorting indices from array.sort

for F# array, is there an easy way to return sorting indices along with the sorted array? like the sort() function from Matlab? Background: I came from matlab/R, where manipulating array on indices are essential. I'd like to reproduce some index functions and trying to be able to pass indices array around as a variable in various funct...

Map applied to multiple arguments in Haskell

Is there a way to use Haskell's "map" or something similar with multiple arguments? i.e. to find the distance between a given point (defined as a tuple) and a list of other points: map distance (-3,-3) buildings Clearly, that doesn't work, because it tries to map "distance" to (-3,-3), where distance expects two tuples: let distance...

Python - functional "find"?

I need a function, which is capable of iterating over the collection, calling a supplied function with element of the collection as a parameter and returning the parameter or it's index when received "True" from supplied function. It is somethong like this: def find(f, seq, index_only=True, item_only=False): """Return first item i...

Multiple assignment of non-tuples in scala

Just to clarify, when I say multiple assigment, parallel assignment, destructuring bind I mean the following pattern matching gem scala> val (x,y) = Tuple2("one",1) x: java.lang.String = one y: Int = 1 which assigns "one" to x and 1 to y. I was trying to do val (x,y) = "a b".split() I was expecting that scala would attempt to patt...

Pseudocode help

Hello all I have been given a strange requirement(challenging for me atleast) to write a logic in an application. I've to write a business logic wherein it should perform the following functionality Total current consumption = current from A elements + current from B elements. A and B are different types of devices Now lets say the b...

How can I write simulations in Erlang?

Hi guys, I want to do some numerical stuff in Erlang like this: You've got an array with the following values: [2,3,4] In each iteration, you calculate 0.1 * [n-1] + 0.7 *[n] + 0.2 * [n+1] This becomes the new [n]. If n == 0 then [n-1] = 0. If [n] == length of array then [n] = 0. So I try an example: [2,3,4] calculations:...

Haskell - Redefining (hiding) arithmetic operators

I want to redefine several arithmetic operators in Haskell in order to make them more extensible and generic. E.g. class Mul a b c | a b -> c where (*) :: a -> b -> c This seems to work in combination with import Prelude hiding ((*)) hiding the standard * operator. But of course all usual multiplications have to work as well, ...

Suggest me a Opensource Scala project to follow and understand

Possible Duplicate: Where do I find an Open Source project written in Scala? I have been learning Scala for the past few weeks and I guess I am ready to get my hands dirty with some real meaningful project. But before actually starting a project and doing things wrong, I want to understand an existing opensource project done b...

Functional languages & support for memoization

Do any of the current crop of popular functional languages have good support for memoization & if I was to pick one on the strength of its memoisation which would you recommend & why? Update: I'm looking to optimise a directed graph (where nodes could be functions or data). When a node in the graph is updated I would like the values of ...

Haskell newbie question: What is "lifting"?

I don't understand what "lifting" is. Should I first understand Monads before understanding what a "lift" is (I'm completely ignorant about Monads too yet:) ? Or can someone explain it to me with simple words ? ...

Resources for learning Monads, Functors, Monoids, Arrows etc

Can you people please suggest some good books / weblinks from where I can get to learn about above mentioned concepts? (Please note that I am a Java programmer and have NO prior experience with functional programming. I have been studying Scala since last one month and would appreciate the resources that try to teach the above mentione...

Query on Booleans in Lambda Calculus

Hi All, I have following query on lambda calculus which am not able to understand: Here is the lambda calculus representation for the AND operator: lambda(m).lambda(n).lambda (a).lambda (b). m(n a b) b Can anyone help me in understanding this representation? Regards, darkie ...

side effect gotchas in python/numpy? horror stories and narrow escapes wanted

I am considering moving from Matlab to Python/numpy for data analysis and numerical simulations. I have used Matlab (and SML-NJ) for years, and am very comfortable in the functional environment without side effects (barring I/O), but am a little reluctant about the side effects in Python. Can people share their favorite gotchas regarding...

Return value in F# - incomplete construct

I've trying to learn F#. I'm a complete beginner, so this might be a walkover for you guys :) I have the following function: let removeEven l = let n = List.length l; let list_ = []; let seq_ = seq { for x in 1..n do if x % 2 <> 0 then yield List.nth l (x-1)} for x in seq_ do let list_ = list_ @ [x]; list_; It takes a list, a...