functional

Combining Predicates

Is there any way that you can combine predicates? Lets say I have something like this: class MatchBeginning : public binary_function<CStdString, CStdString, bool> { public: bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const { return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0; } };...

Generic identity function for use with type inference

Hi I was wondering if it is possible, as my 5 minutes of experimentation proved fruitless. I hoped it would be as easy as: T Identity<T>(T t) { return t; } But this fails to compile on generic methods taking Func parameters. Eg OrderBy. Even specifying type parameters (which is exactly what I want to avoid!), it fails to compile. ...

Pitfalls for OO Programmer Learning the Functional Way?

I've been programming Java for a few years now, and I've dabbled in functional programming now and again. I'm thinking I should learn how to do the functional thing properly after having 'fun' with XQuery, so... Are there traps my OO way of thinking can lead me into when I'm writing in a functional way? ...

static methods make Java a pseudo functional language?

I've been mulling about a post by Misko Hevery that static methods in Java are a death to testability. I don't want to discuss the testability issue but more on the concept of static methods. Why do people hate it so much? It's true that we don't have closures (but we have a slightly awkward anonymous functions), lambdas & functions as ...

Are functional languages inherently more parallelizable than their OO or imperative cousins?

I've been reading and thinking a fair bit about this. The buzz seems to be that in the multi-core future, functional languages will become more popular. I'm a relative noob to functional programming. My only exposure was academic, and nothing complicated enough to really put this class of language through its paces. So, as I understand ...

Where could I find some code examples about Integration Testing

I have methods that interact with DB and external files. I need to write integration tests, however I am not sure how to. Do you know where I can find some source codes about integration testing with Database or External File? If you write a test method that tests a production method in which there are calls to other methods, is this a...

Passing a function object: Error

What's wrong with the following little program that passes a function object? #include <iostream> #include <functional> void foo(const std::unary_function<const std::string&, void>& fct) { const std::string str = "test"; fct(str); // error } class MyFct : public std::unary_function<const std::string&, void> { public: void operat...

anyone tried new php beta release with anonymous functions?

Hi, has anybody tried out the new 5.3.0 RC1 php release and played a bit with anonymous functions? I would like to know if you can use it like python for functional programming. E.g., can you do something like: def sinus(x): if x<=0.1: return x else: return (lambda x: 3*x-4*x*x*x)(sinus(x/3)) print sinus(172.0) Or bet...

Are there any decent scripting languages that use functional programming?

I've been reading a bit about functional programming recently and am keen to get have a bit of a play. are there any decent scripting languages that support functional programming? I find that the bulk of my ad-hoc programming is done in Python, so I thought I might be able to do the same with a functional language. Any recommendations? ...

Does Ruby perform Tail Call Optimization?

Functional languages lead to use of recursion to solve a lot of problems, and therefore many of them perform Tail Call Optimization (TCO). TCO causes calls to a function from another function (or itself, in which case this feature is also known as Tail Recursion Elimination, which is a subset of TCO), as the last step of that function, t...

What is a good example for functional style web programming using javascript?

I'm doing javascript on a daily basis at the moment. I'm coming from an OO background and most of the code I have contact with is somewhat procedural/OO style. I'm looking for good examples that solves more or less typical web programming tasks but in a functional manner. I'm not interested to have any arbitrary example that just looks ...

List of Functional code snippets for Procedural Programmers?

Sometimes I still get stuck trying to translate procedural code into functional code. Is there a list of functional idioms/snippets that are mapped to procedural idioms/snippets? Edit Since there doesn't seem to be a centralized website of these snippets, I am turning this into a community wiki. Please paste any procedural -> function...

Can I have a deferrable unique functional index in Oracle?

I'd like to create a deferrable unique functional index in Oracle 10g. I know how to create a unique functional index: create unique index LIST_ITEM_ENTRY_NO_UNIQ on LIST_ITEM (case status when 'cancel' then null else LIST_KEY end, case status when 'cancel' then null else ENTRY_NO end); I know how to create a deferrable...

Why can't F# infer the type of this statement?

/// I can't do this let max = float n |> sqrt |> int64 |> Math.BigInt /// But this is allowed let max = Math.BigInt(float n |> sqrt |> int64) ...

SET vs. SELECT - What's the difference?

Can someone please identify the functional/performance differences, if any, between SET and SELECT in T-SQL? Under what conditions should I choose one over the other? UPDATE: Thanks to all who responded. As a few people pointed out, this article by Narayana Vyas Kondreddi has lots of good info. I also perused the net after reading the...

C++: Function wrapper that behaves just like the function itself

How can I write a wrapper that can wrap any function and can be called just like the function itself? The reason I need this: I want a Timer object that can wrap a function and behave just like the function itself, plus it logs the accumulated time of all its calls. The scenario would look like this: // a function whose runtime shoul...

F# vs. Clojure

What are the most significant differencies between the F# and Clojure ? Which constructs has F# which Clojure does not have and vice versa? Does F# have macros? ...

Are there any examples of Functional Relational Programming in the wild?

I've just finished reading a very interesting paper entitied "Out of the Tar Pit" which presents this idea of FRP as a way of reducing complexity in applications by minimizing state and control. Are there any examples of this idea out in the wild? Is anybody making use of these ideas? Is there any work being done in this area? Edit: FRP...

GUI programming in Scala

I'm trying to learn Scala, and I'd like to learn by writing a simple swing app, but I'm unsure what GUI programing looks like in a functional world, and specifically when using Scala. Any pointers, or tutorials, or gotchas when coming from an OO/Java background would be really welcome. ...

Is there a way to do currying in C?

Say I have a pointer to a function _stack_push(stack* stk, void* el). I want to be able to call curry(_stack_push, my_stack) and get back a function that just takes void* el. I couldn't think of a way to do it, since C doesn't allow runtime function definition, but I know there are far cleverer people than me here :). Any ideas? ...