functional-programming

Query on type expressions in ML

All, Here is the type expression which I need to convert to a ML expression: int -> (int*int -> 'a list) -> 'a list Now I know this is a currying style expression which takes 2 arguments: 1st argument = Type int and 2nd argument = Function which takes the previous int value twice and return a list of any type I am having a hard time...

Trouble with lazy convolution fn in Clojure

I am writing some signal processing software, and I am starting off by writing out a discrete convolution function. This works fine for the first ten thousand or so list of values, but as they get larger (say, 100k), I begin to get StackOverflow errors, of course. Unfortunately, I am having a lot of trouble converting the imperitive ...

Monad in non-programming terms

How would you describe a monad in non-programming terms? Is there some concept/thing outside of programming (outside of all programming, not just FP) which could be said to act or be monad-like in a significant way? ...

Deriving type expression in ML

All, I want to derive the type expression for the function below in ML: fun f x y z = y (x z) Now I know typing the same would generate the type expression. But I wish to derive these values by hand. Also, please mention the general steps to follow when deriving type expressions. ...

understanding referential transparency

Generally, I have a headache because something is wrong with my reasoning: For 1 set of arguments, referential transparent function will always return 1 set of output values. that means that such function could be represented as a truth table (a table where 1 set of output parameters is specified for 1 set of arguments). that makes the...

Implement an immutable deque as a balanced binary tree?

I've been thinking for a while about how to go about implementing a deque (that is, a double-ended queue) as an immutable data structure. There seem to be different ways of doing this. AFAIK, immutable data structures are generally hierarchical, so that major parts of it can be reused after modifying operations such as the insertion or ...

Why ADTs are good and Inheritance is bad?

Hi fellow stackies. I am a long time OO programmer and a functional programming newbie. From my little exposure algebraic data types only look like a special case of inheritance to me where you only have one level hierarchy and the super class cannot be extended outside the module. So my (potentially dumb) question is: If ADTs are jus...

What's an event-loop and how is it different than using other models?

I have been looking into Node.JS and all the documentation and blogs talk about how it uses an event-loop rather than a per-request model. I am having some confusion understanding the difference. I feel like I am 80% there understanding it but not fully getting it yet. ...

Scala - idiomatic way to calculate sums of interleaved array?

Hi all, I'm attempting to calculate the average color of an image in Scala, where "average" is defined as the redSum/numpixels, greenSum/numpixels, blueSum/numpixels . Here is the code I am using to calculate the average color in a rectangular region of an image (the Raster). // A raster is an abstraction of a piece of an image and th...

Trying to gain confidence in the benefits of TDD

I just bought The Art of Unit Testing from Amazon. I'm pretty serious about understanding TDD, so rest assured that this is a genuine question. But I feel like I'm constantly on the verge of finding justification to give up on it. I'm going to play devil's advocate here and try to shoot down the purported benefits of TDD in hopes that ...

Is there a Scheme implementation that parallelizes?

Is there a R5RS-or-higher Scheme implementation that does parallelization? For example, if I say to do: (map (lambda (x) (pure-functional-stuff x)) '(1 3 5 7 11 13)) it will process 1, 3, 5, and 7 simultaneously if the machine can do it? That's supposed to be one of the big advantages of functional programming, but I c...

Does a Clojure proxy always invoke super.method()?

While using Clojure proxies, fns passed to proxy should override existing methods or are they called in conjunction with super.method()? In the following code, RequestHandler.get() is invoked along with the proxy get []. ;see: http://github.com/paulosuzart/JTornado (ns org.ctornadoweb) (import '(org.jtornadoweb Web$RequestHandler)) (im...

Immutable game object, basic functional programming question.

Hi all, I'm in the process of trying to 'learn more of' and 'learn lessons from' functional programming and the idea of immutability being good for concurrency, etc. As a thought exercise I imagined a simple game where Mario-esq type character can run and jump around with enemies that shoot at him... Then I tried to imagine this bein...

Functional JavaScript: how to implement Function.prototype.not

I was working on some code earlier today, when I realized, "Hey! This code would be more concise and semantic if I abstracted the idea of a boolean not out of an anonymous function and into a prototype function..." Consider a predicate generator: function equalTo(n) { return function(x) { return n==x; }; } So you can ...

Monotonify (list-munging) without a For loop.

For or While loops in Mathematica code always make me feel a little dirty but I was confusing myself trying to do some list munging all functional-like, and resorted to this: (* # Given a list of {x,y} pairs, transform the data as follows: every time # there's a decrease in y-value from one datapoint to the next, say {x1,Y} # fo...

(List of) Reasonable usage of F# and how OO-Programmer benefit from it

Possible Duplicate: What areas of code are you using f# for? F# is a language that will be used more and more. Microsoft has built in Visual Studio 2010 F# and the potential is huge, like I've read in several IT magazines. So let's collect useful information about the "right" application of F# and what advantages we could ge...

Advanced functional programming literature

Hello there, when a developer new to object oriented programming has grasped the foundations there are several books/documents how to expand the knowledge on this paradigm. For example books about: object oriented design patters how to get your design right (object oriented analysis/design) how to determine whether your design seem...

Benefits and uses of a functional programming language

Possible Duplicate: Why functional languages? I began programming with C/C++, VB, and eventually Python - all imperative languages. I took a course about programming languages and learned my first functional language - OCaml. It was terrible. Syntax and other horrors aside, OCaml took my imperative thought process and threw i...

Why can a Boost.Bind function be called with extra parameters?

#include <iostream> #include <string> #include <boost/bind.hpp> void foo(std::string const& dummy) { std::cout << "Yo: " << dummy << std::endl; } int main() { int* test; std::string bar("platypus"); (boost::bind(&foo, bar))(test, test, test, test, test, test, test, test); } When run, it prints out, "Yo: platypus." It...

Strange "Could not deduce template argument for 'T'" error

The error is in this code: //myutil.h template <class T, class predicate> T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, predicate condition); //myutil.cpp template <class T, class Pred> T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, Pred condition) { T input cout<< inputMessage; cin>...