functional-programming

What's the formal difference between a function-level language and a functional one?

I'm pretty good at Haskell and have been teaching myself J. I've read about John Backus' distinction between value-level and function-level programming. J is a function-level language that allows one to write in a value-level style if desired. (I hope I've got that right.) Where does Haskell fit in in this? I know Haskell permits a taci...

Haskell: Functions that sometimes return a function

Hoe do you write a function that can either return a value or another function? For example: Function Foo (x) If X = 0 Return "Done" Else Return a Function that calls Foo(x-1) ...

Pattern matching with reals (Standard ML)

Doing this: fun test a 0.0 = "good" | test a b = "bad"; results in an error, but if I change the 0.0 the error goes away. However, I need to match 0.0 and I'm wondering if and how that can be accomplished. ...

What to call OOP's equivalent of "referential transparency"?

My understanding is that the term "referential transparency" can really only be applied to functional code. However, a method call on an object in object-oriented code can have a similar property, which is that the return value of the method, and the state of the object after a method call depends only on the state of the object before ...

objects or closures - when to use?

I can define an object and assign attributes and methods: class object: def __init__(self,a,b): self.a = a self.b = b def add(self): self.sum = self.a + self.b def subtr(self): self.fin = self.sum - self.b def getpar(self): return self.fin obj = object(2,3) obj.add() obj.subtr() o...

Fast Standard ML compiler or bytecode interpreter, with read-eval-print loop, for Linux?

For use with a class I'll be teaching, I'm looking for a fast compiler or bytecode interpreter for Standard ML. I'm looking for fast compile times; any reasonable run time will do. Bonus if the compilation model is simple and clear. Students in the class will also be using MLton to generate good binaries, but MLton is slow to compile...

Loose programming in high level languages, how, why and how much?

I'm writing my code in haXe. This is quite irrelevant to the question though, as long as you keep in mind that it's a high level language and compareable with Java, ActionScript, JavaScript, C#, etc. (I'm using pseudocode here). I'm going to work on a big project and am busy preparing now. For this question I'll create a small scenario ...

C++: Difficulty with partial application

I'm trying to use partial application of function arguments so I can use STL's find_if. Here is a sample program: (Class header and implementation is merged for brevity.) #include <functional> #include <iostream> #include <vector> #include <algorithm> #include <iostream> using namespace std; struct Odp { int id; Odp(int id) ...

Calculating percent difference between elements in a list with functional programming in Mathematica?

This stems from a related discussion, How to subtract specific elements in a list using functional programming in Mathematica? How does one go about easily calculating percent differences between values in a list? The linked question uses Differences to easily calculate absolute differences between successive elements in a list. Howev...

Simulating side-effects with threads

I was watching this Channel 9 talk and a very interesting statement is made in the around the 60 minutes in. He said that even with completely pure functions once you introduce threads you can simulate side effects. The way he outlined this was using C-omega notation, which I'm not familiar with, and this already has the relevant lang...

How can I write a multi-client server that doesn't have mutable state?

I am looking at functional programming and struggling with one point.. How do I do the following without mutable state? Imagine I have a server.. and clients try to connect.. and each client gives the server a number and gets told the current total. Now without mutable state the server can't keep a total... so I am thinking each client...

Proper commenting for functional programming

I've been learning scheme, and I just realized that I don't really know how to properly comment my functional scheme code. I know how to add a comment of course - you add a ; and put your comment after it. My question is what should I put in my comments, and where should I comment for maximum readability and comprehensability for other p...

Immutable data structures performance

I don't get how can something as a Set be immutable and still have an acceptable performance. From what I've read in F# Sets internally use Red Black Trees as their implementation. If each time we want to add something new to a Red Black Tree we have to basically recreate it, how can it have ever good performance? What am I missing her...

Fixed point combinators for functions over custom types?

Most examples of the use of fixed point combinators involve functions that take integers to integers (e.g. factorial). In many cases the fixed point of a function over the real numbers will end up being an arbitrary rational or perhaps irrational number (a famous example is the logistic map http://en.wikipedia.org/wiki/Logistic_map). In ...

Fixed point combinator usage? Why a stack overflow here?

I am confused about something. I wanted to generate an example (in Clojure) demonstrating how a fixed point combinator could be used to evaluate the fixed point of a sequence that mathematically converges after an infinite number of applications but would, in fact, converge after a finite number of steps due to finite precision of floati...

Can someone give me examples of functional programming vs imperative/procedural programming?

Are procedural and imperative the same thing? ...

What do I need to do to get paid to Scheme?

I'm a big fan of functional programming in general, Schemes in particular, and PLT-Racket ideally. I am wondering what concrete steps are likely to get me into a position where coding Scheme (or some functional language) is the bulk of the work. I'm actually quite interested in academia, but on the other hand, I don't feel like I neces...

Functional proofs (Haskell)

I failed at reading RWH; and not one to quit, I ordered Haskell: The Craft of Functional Programming. Now I'm curious about these functional proofs on page 146. Specifically I'm trying to prove 8.5.1 sum (reverse xs) = sum xs. I can do some of the induction proof but then I get stuck.. HYP: sum ( reverse xs ) = sum xs BASE: sum ( r...

Python: Why is functools.partial necessary?

Partial application is cool. What functionality does functools.partial offer that you can't get through lambdas? >>> sum = lambda x, y : x + y >>> sum(1, 2) 3 >>> incr = lambda y : sum(1, y) >>> incr(2) 3 >>> def sum2(x, y): return x + y >>> incr2 = functools.partial(sum2, 1) >>> incr2(4) 5 Is functools somehow more efficient, or...

For any projects using functional programming?

Hello, I have a free time and would like to do functional programming and learn some functional programming language. But as we know the best theory it is practice. In this regard, I would like to know in which sector is most often used functional programming? I understand if the project is written in a functional language that is some...