functional-programming

pure functional using F#

Is it possible to force F# to behave like a pure functional language like Haskell? May be using some compiler directives? ps: since i come from a C/C++ background, I want to force myself to learn functional programming without learning haskell :) ...

Functional Programming: Does a list only contain unique items?

I'm having an unsorted list and want to know, whether all items in it are unique. My naive approach would be val l = List(1,2,3,4,3) def isUniqueList(l: List[Int]) = (new HashSet()++l).size == l.size Basically, I'm checking whether a Set containing all elements of the list has the same size (since an item appearing twice in the original...

Meaning of Leaky Abstraction?

What does the term "Leaky Abstraction" mean? (Please explain with examples. I often have a hard time grokking a mere theory.) ...

Is it good or bad manner to oversecure?

If a function does all proper checks inside, should I check everything before calling it, or better not? Is security redundancy considered a good practice? Example (in a sort of C#-like pseudocode with by-reference arguments passing): doSomething(vector v) { ...; v.clear; useCleanVector(v) } useCleanVector(vector v) { if(!v....

Website for checking in which programing language code was written?

Do you know any site which can check this? I think, that i saw sometime ago, some kind of pastebin service which had option "autodetect", but I can't find it anymore. Do you know something which could help me? ...

Replace in a list in Erlang

I'm trying to learn some Erlang and having trouble figuring out the best approach for a particular problem. Here's what I'm doing: I have a big 2-D array of data (list of lists) whose values are calculated by independent processes. The processes send a message back to an aggregator with the result when they're done calculating. My probl...

How does change of the state work under the hood in functional languages

Hello, I would like to know how could functional languages implement "under the hood" creation of new state of for example Vector. When I have a Vector and I add another element to that particular Vector the old one is still there unchanged and new Vector containing the old one is created containing one more element. How is this handle...

Why no generics in go?

Disclaimer: I've only played with GO for one day now, so there's a good chance I've missed a lot. Does anybody know why there is no real support for generics/templates/whatsInAName in GO? So there is a generic map, but that's supplied by the compiler, while a GO programmer can't write her own implementation. With all the talk about maki...

Is there a JavaScript library that adds missing standard iteration methods (filter, map, reduce, some...) to Array?

Is there a JavaScript library which just adds some methods of Array, Object and other standard objects which have been standardized, but that are not available in all browsers? I am thinking of iteration methods in Array such as filter(), map(), reduce(), some(), or keys() in Object. Note that I don't want the library to introduce anyth...

example algorithm for generating random value in dataset with normal distribution?

I'm trying to generate some random numbers with simple non-uniform probability to mimic lifelike data for testing purposes. I'm looking for a function that accepts mu and sigma as parameters and returns x where the probably of x being within certain ranges follows a standard bell curve, or thereabouts. It needn't be super precise or ev...

Filtering a list in Haskell

I am trying to start learning haskell, and a question came up. Say, I have a function countFilter :: (a -> Bool) -> [a] -> ([a], Int) countFilter a z = case z of [] -> ([], 0); (x:xs) -> (filter a z , length (filter a z)) It returns a list, all the items of which apply to a certain predicate and a...

Fascinated by FP but still think imperative, how do I think functional ?

Like most ppl, I started with and still do a lot of imperative code(mostly Java, Ruby, Javascript). I've never been a big fan of OO, either because I never understood it properly or because I don't think OO. Got my first glimpse of FP via javascript, passing functions around, closures, etc. Have been in love with FP since then. Rece...

Merging two lists in Haskell

Can't figure out how to merge two lists in the following way in Haskell: INPUT: [1,2,3,4,5] [11,12,13,14] OUTPUT: [1,11,2,12,3,13,4,14,5] This would work similar to shuffling a deck of cards. Thanks in advance. ...

What's the difference of a "class" in Haskell and in an "abstract class" in OO language?

At first glance, there obvious distinctions between the two kinds of "class". However, I believe there are more similarities: Both have different kinds of constructors. Both define a group of operations that could be applied to a particular type of data, in other words, they both define an Interface. I can see that "class" is much m...

How to transform this simple OOP program to a functional-programming language?

During the last months I have tried to code using the functional programming paradigm. Now I have a solution in OOP and I am trying to find a functional solution. The problem is simple. I have an algorithm, which produces two different arrays as result (a and b). Now, I want to check how good the results are. Therefore I write several ...

What, if anything, is wrong with this shuffling algorithm and how can I know?

Just as background, I'm aware of the Fisher-Yates perfect shuffle. It is a great shuffle with its O(n) complexity and its guaranteed uniformity and I'd be a fool not to use it ... in an environment that permits in-place updates of arrays (so in most, if not all, imperative programming environments). Sadly the functional programming wor...

OCaml: Is there a function with type 'a -> 'a other than the identity function?

This isn't a homework question, by the way. It got brought up in class but my teacher couldn't think of any. Thanks. ...

Underscore.js: how to chain custom functions

Using Underscore.js, I can write the following which returns 42: _([42, 43]).chain() .first() .value() I have custom function, not part of Underscore.js called double(): function double(value) { return value * 2; }; I would like to be able to call this function in an Underscore chain, as if it was part of Underscore. I woul...

Are FP and OO orthogonal?

I have heard this time and again, and I am trying to understand and validate the idea that FP and OO are orthogonal. First of all, what does it mean for 2 concepts to be orthogonal? FP encourages immutability and purity as much as possible, while OO seems built for state and mutation – a slightly organized version of imperative program...

Is there any algorithm needs functional language exclusively to be implemented

Hi, I'm a C# developer and I don't have enough information about functional languages, My question that is there any algorithm needs functional language exclusively to be implemented? Regards. ...