5
голосов
7ответов
1780 просмотров

Rewriting C# code in F#

Just messing about with F# and I was trying to create a basic Lagrange Interpolation function based on this C# version (copied from a C++ wiki entry): double Lagrange(double[] pos, double[] val, double desiredPos) { double retVal = 0; for (int i = 0; i < val.Length; +...

46
голосов
9ответов
8334 просмотров

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 ...

8
голосов
2ответов
4074 просмотров

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 fu...

4
голосов
3ответов
263 просмотров

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 ope...

3
голосов
1ответов
361 просмотров

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 ...

4
голосов
7ответов
683 просмотров

How to remove imperative code from a function?

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 ...

15
голосов
5ответов
6611 просмотров

Functional programming library for Objective-C

Is there any functional programming library for Objective-C?

3
голосов
5ответов
215 просмотров

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 a...

3
голосов
3ответов
1005 просмотров

need help understanding this erlang code

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 repe...

2
голосов
2ответов
644 просмотров

Implementing a Command Line Interpreter with a functional language

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 la...

3
голосов
2ответов
460 просмотров

cross-platform zip file creation

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 ...

12
голосов
8ответов
7751 просмотров

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. D...

32
голосов
10ответов
4811 просмотров

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 cl...

4
голосов
2ответов
383 просмотров

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 ...

19
голосов
12ответов
5744 просмотров

CMS in functional programming language

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

3
голосов
2ответов
1722 просмотров

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 (...

2
голосов
3ответов
97 просмотров

Fine-grained sandboxing

Scenario: a program running in a byte code virtual machine like Java or Python, wants to evaluate (by compiling on the fly to byte code and then running) a function whose code was automatically generated or supplied from outside. The tricky bit is that the function's code is not trusted -- it ma...

23
голосов
9ответов
5070 просмотров

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 workin...

11
голосов
5ответов
2573 просмотров

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...

2
голосов
6ответов
1802 просмотров

right rotate a List in Erlang

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) -exp...

2
голосов
5ответов
307 просмотров

Is there a standard name for this function?

What would you name a function that takes a list and a function, and returns True if applying the function to all elements gives the same result? def identical_results(l, func): if len(l) <= 1: return True result = func(l[0]) for el in l[1:]: if func(el) != result: ...

8
голосов
6ответов
3235 просмотров

Functional Programming for Basic Algorithms

How good is 'pure' functional programming for basic routine implementations, e.g. list sorting, string matching etc.? It's common to implement such basic functions within the base interpreter of any functional language, which means that they will be written in an imperative language (c/c++). Alt...

16
голосов
2ответов
3237 просмотров

Operator Overloading in Clojure

Even looking closely over documentation on Clojure, I do not see any direct confirmation as to whether or not Clojure supports operator overloading. If it does, could someone provide me with a quick snipplet of how to overload, let's say, the "+" operator to delegate to some predefined method th...

5
голосов
2ответов
1577 просмотров

Pattern matching zero-argument functions in scala: mystified by warning

I'm playing with scala's distributed actors. Very nice. I have a server which executes incoming function objects. For example, the client has object Tasks { def foo = {Console.println("I am Foo")}; def bar = {Console.println("I am Bar");} } // In client actor... ... server ! Tasks.foo _...

14
голосов
6ответов
3302 просмотров

Which functional programming languages have bioinformatics libraries?

Which functional programming languages have bioinformatics libraries easily available? (Don't include multi-paradigm languages such as Ruby) Update: Listing which major functional programming languages don't currently have easy access to bioinformatics libraries is also welcome.

0
голосов
8ответов
2717 просмотров

Recursive function best practices; What are they?

What are some other language independent ways of designing recursive functions other than the typical: if (counter < 1) return output; else callSelf(); Do other methods even exist? Whenever viewing examples I always see a version of the code above. Thanks! :)

7
голосов
3ответов
475 просмотров

looking for learning exercise: implement these monads

When learning about new programming subjects I usually follow a pattern: I read about it, I understand it, and then I code up a few examples to make sure I really get it. I've read a lot about monads, and I'm confident that I understand and get them. I'm now at a stage where I'd really like to...

7
голосов
2ответов
1732 просмотров

Tail-recursion optimization in Oz

In the chapter about function in the Oz tutorial, it says that: similar to lazy functional languages Oz allows certain forms of tail-recursion optimizations that are not found in certain strict functional languages including Standard ML, Scheme, and the concurrent functional langu...

9
голосов
2ответов
505 просмотров

Unit-safe square roots

I just wondered how it is possible to write a user-defined square root function (sqrt) in a way that it interacts properly with F#'s unit system. What it should be like: let sqrt (x : float) = let x' = x / 1.0 // Delete unit (x ** 0.5) * 1.0 // Reassign unit But this is disallowe...

3
голосов
1ответов
448 просмотров

Learning Scheme Macros. Help me write a define-syntax-rule

I am new to Scheme Macros. If I just have one pattern and I want to combine the define-syntax and syntax-rules, how do I do that? (define-syntax for (syntax-rules (from to) [(for i from x to y step body) ...] [(for i from x to y body) ...])) If I just have one for, how do I combine t...