functional

What is the difference between dynamic languages and functional languages?

Hi, I often find developers use the terms functional language and dynamic language together, and wonder why are they always being put together. What are the differences between them? Can a language be both dynamic and functional? Do they complement each other? Why do we need them anyway? I'm a C# programmer and don't yet understand this...

Is there any function object to create objects in STL?

Consider the following class: class Person { public: // I don't want any "char *" to be converted to Person implicitly! explicit Person( const char * name ) : name_(name) {}; private: std::string name_; }; Also consider following array of char* data: char STUDENT_NAMES[][20] = { "Bart", "Liza", "Maggie" }; ...

Looking for a functional language

I'm a scientist working mostly with C++, but I would like to find a better language. I'm looking for suggestions, I'm not even sure my "dream language" exist (yet), but here's my wishlist; IMPORTANT FEATURES (in order of importance) 1.1: Performance: For science, performance is very important. I perfectly understand the importance of p...

UI based on functional programming

I am learning functional programming concepts now a days, and professionally I am an Asp.net developer. But asp.net makes you to change properties of objects too often in code behind. Functional programming is based on immutable objects. And apply this concept to change the value of a textbox will be very painful. Also in some event hand...

Using Either to process failures in Scala code

Option monad is a great expressive way to deal with something-or-nothing things in Scala. But what if one needs to log a message when "nothing" occurs? According to the Scala API documentation, The Either type is often used as an alternative to scala.Option where Left represents failure (by convention) and Right is akin to Some...

Compile to xslt?

The answer to this may very well be no, as much searching has turned up nothing. I thought long ago I saw something like this, but it may all have been a mirage. Basically, it's so atrociously awful writing xslt out by hand. It's not the functional paradigm that bothers me. What bothers me is the fact that it uses XML based syntax. I wo...

How should I think about Scala's Product classes?

The package "scala" has a number of classes named Product, Product1, Product2, and so on, up to Product22. The descriptions of these classes are surely precise. For example: Product4 is a cartesian product of 4 components Precise, yes. Communicative? Not so much. I expect that this is the perfect wording for someone who already under...

Erlang vs OCaml (best niche to fit)

Hi I'd like to pick up one FP language (it's always a pain when you work in a position that does not require you learn much), and after doing some research, I felt Erlang and OCaml are the two that I'd really like to get my feet wet for the following reasons: 1) I work mainly on high-availability web server back-end system in C++. I hea...

Functional GLUT?

I'm learning a bit of functional programming in Gambit-C Scheme by restricting myself to not using set!. I thought it might be fun to write a little OpenGL game using this environment, which seems to lend itself well to game development. However, it seems to be difficult to stick to a functional style and avoid global state when using ...

How do I refer to std::sin(const valarray<double> &) ?

I'm having trouble with some valarray function pointer code: double (*fp)(double) = sin; valarray<double> (*fp)(const valarray<double> &) = sin; The first compiles, the second gives: error: no matches converting function 'sin' to type 'class std::valarray<double> (*)(const class std::valarray<double>&)' ...

Is there a modeling language for the functional programming paradigm?

UML is a standard aimed at the modeling of software which will be written in OO languages, and goes hand in hand with Java. Still, could it possibly be used to model software meant to be written in the functional programming paradigm? Which diagrams would be rendered useful given the embedded visual elements? Is there a modeling languag...

Complex iterations in haskell

Hi I have this complex iterations program I wrote in TI Basic to perform a basic iteration on a complex number and then give the magnitude of the result: INPUT “SEED?”, C INPUT “ITERATIONS?”, N C→Z For (I,1,N) Z^2 + C → Z DISP Z DISP “MAGNITUDE”, sqrt ((real(Z)^2 + imag(Z)^2)) PAUSE END What I would like to do is make a Haskell versio...

Clojure: How to generate a 'trie'?

Given the following... (def inTree '((1 2) (1 2 3) (1 2 4 5 9) (1 2 4 10 15) (1 2 4 20 25))) How would you transform it to this trie? (def outTrie '(1 (2 () (3 ()) (4 (5 (9 ())) (10 (15 ())) (20 (25 ())))))) ...

Can Rails integration tests hit another server for OpenID auth?

Can Rails integration tests hit another server for OpenId authentication? When my Rails application, running on http://localhost:3000/, redirects to http://localhost:1123/server for OpenId authentication, Rails fake browser actually goes to http://localhost:3000/server. It seems like the fake browser used in the integration tests is ign...

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++). Although there are many exceptions.. At leas...

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

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 may have been generated by a stochastic meth...

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; ++i) { double weight = 1; ...

Rails functional test file access

I need to access a file in a Rails functional test in test/functional/main_controller_test.rb. If I mention the file within "", and the included file is placed in test/ directory, I can run the test using: $ cd test $ ruby functional/main_controller_test.rb But, I get a cannot find file error, when I use it from the top-level Rails p...

functional programming: immutable data structure efficiency

Hi, I don't understand, how FP compilers make the code dealing with immutable data structures fast, not blow up stack, etc. For example, insert operation in tree, it has to copy the whole tree before adding the new node and return the copied tree, versus the imperative couterpart that only needs to add a pointer to the new node. If the ...