functional-programming

right rotate a List in Erlang

Hi, I am getting myself familiar to Sequential Erlang (and the functional programming thinking) now. So I want to implement the following two functionality without the help of BIF. One is left_rotate (which I have come up with the solution) and the other is right_rotate (which I am asking here) -export(leftrotate/1, rightrotate/1). %%(1...

Advice on Learning "How to Think Functional"?

As a newbie in functional languages (I started touching Erlang a couple of weeks ago -- the first functional language I could get my hands on). I started to writing some small algorithms (such as left_rotate_list, bubble_sort, merge_sort etc.). I found myself often getting lost in decisions such as "should I use a helper List for interm...

Are functional programming languages good for practical tasks?

It seems to me from my experimenting with Haskell, Erlang and Scheme that functional programming languages are a fantastic way to answer scientific questions. For example, taking a small set of data and performing some extensive analysis on it to return a significant answer. It's great for working through some tough Project Euler questio...

F-Sharp (F#) untyped infinity

I wonder why F-Sharp doesn't support infinity. This would work in Ruby (but not in f#): let numbers n = [1 .. 1/0] |> Seq.take(n) -> System.DivideByZeroException: Attempted to divide by zero. I can write the same functionality in much complex way: let numbers n = 1 |> Seq.unfold (fun i -> Some (i, i + 1)) |> Seq.take(n) -> works...

CMS in functional programming language

Are there any CMS'es, written in functonal programming languages (lisp, haskell, f#/nemerle, scala, erlang, clojure, smalltalk) already? ...

How to view the contents of parsed R functions?

R is a functional programming language, and one of it's primary benefits is it's ability to create open and transparent functions. As John Chambers says in his excellent book "Software for Data Analysis: Programming with R": Computations are organized around functions, which can encapsulate specific, meaningful computational results...

Does functional programming mandate new naming conventions?

I recently started studying functional programming using Haskell and came upon this article on the official Haskell wiki: How to read Haskell. The article claims that short variable names such as x, xs, and f are fitting for Haskell code, because of conciseness and abstraction. In essence, it claims that functional programming is such a...

C++ LINQ-like iterator operations

Having been tainted by Linq, I'm reluctant to give it up. However, for some things I just need to use C++. The real strength of linq as a linq-consumer (i.e. to me) lies not in expression trees (which are complex to manipulate), but the ease with which I can mix and match various functions. Do the equivalents of .Where, .Select and ....

What could be the next evolution after OOP?

Today we can look back on the evolution of computer science and see structural programming, functional programming, and finally object-oriented programming. Additionally, things like meta-programming (reflective programming) and combining approaches into a single language (e.g. LINQ) are current. Another trend is template-meta-programmi...

cross-platform zip file creation

hi all, i'd like to create a zip archive from within R, and need maximal cross-platform compatibility, so I would prefer not to use a system("zip") command. Within utils there's zip.file.extract (aka unzip), which uses [a lot of] c code, derived from zlib 1.1.3 within a file called dounzip.c I couldn't find any similar capabilities for ...

Implementing a Command Line Interpreter with a functional language

Hi, I'm toying with the idea of writing a command line interpreter and I suspect that a functional language such as Clojure is well suited to this task. I am however 5 years out of a CS degree and my only experience with functional languages was a harrowing experience with Haskell in a third year languages course. So, is a language suc...

need help understanding this erlang code

Hi: I'm having trouble understanding this line. [Pid2 ! {delete, V1a} || {Pid1a, V1a} <- PV1a, Pid2 <- P2, Pid1a /= Pid2 ], Here is what I understand: anything before the double pipe "||" is done repeatedly, according what's after the double pipe. so messages with delete atom is repeated sent to Pid2. I know '/=' mean inequal...

In a functional programming what would you call this sort of operation?

In a functional programming what would you call this sort of operation? function(f,vargs){ //variable count of arguments return function(){ return f(vargs) } } I think this is Currying, but I had the impression that currying is the term when we bind a single argument not several arguments. Or perhaps this is a delay, not ...

Functional programming library for Objective-C

Is there any functional programming library for Objective-C? ...

F# remove imperative code - quick help

I'm new to functional world and appreciate help on this one. I want to SUPERCEDE ugly imperative code from this simple function, but don't know how to do it. What I want is to randomly pick some element from IEnumerable (seq in F#) with a respect to probability value - second item in tuple (so item with "probability" 0.7 will be picked...

Complex object initialization scope issues with nested functions

OK, so I'm trying to use S4 classes to build a very complex object, with slots including a half-dozen matrices, a few lists, and probably a kitchen sink or two in there. The object is initialized by referring to and unpacking a configuration object which I've already defined. It's easy enough to define the class with setClass(), but I'm ...

Operate on values within structurally similar types in Haskell

Excuse me for my extremely limited Haskell-fu. I have a series of data types, defined in different modules, that are structured the same way: -- in module Foo data Foo = Foo [Param] -- in module Bar data Bar = Bar [Param] -- * many more elsewhere I'd like to have a set of functions that operate on the list of params, eg to add and ...

Break or shortcircuit a fold in Scala

I have written a simple depth-first search in Scala with a recursive function like that: search(labyrinth, path, goal) where labyrinth is a specification of the problem (as graph or whatever), path is a list that holds the path taken so far and goal is a specification of the goal state. The function returns a path to the goal as a Lis...

Are there any tools for performing static analysis of Scala code?

Are there any tools for performing static analysis of Scala code, similar to FindBugs and PMD for Java or Splint for C/C++? I know that FindBugs works on the bytecode produced by compiling Java, so I'm curious as to how it would work on Scala. Google searches (as of 27 October 2009) reveal very little. Google searches (as of 01 Februar...

What are the main issues in designing an interpreter for a functional language?

Suppose I want to implement an interpreter for a functional language. I would like to understand the issues involved in doing so and suitable literature that is available. This is a new language that is in early design stages, that is why the question is broad in scope. For the purpose of this discussion we can assume that the purpose o...