Functional programming is a programming paradigm which primarily uses functions as means for building abstractions and expressing computations that comprise a computer program.

learn more… | top users | synonyms

1
vote
1answer
17 views

Recursive Determinant

The following code I devised to compute a determinant: module MatrixOps where determinant :: (Num a, Fractional a) => [[a]] -> a determinant [[x]] = x determinant mat = sum [s*x*(determinant ...
2
votes
0answers
34 views

functional javascript - recursively walking a tree to build up a new one; could this be better factored as a reduce?

/** * recursively build a nested Backbone.Model or Backbone.Collection * from a deep JSON structure. * * undefined for regex values */ exports.modelify = function modelify (data) { if ...
1
vote
2answers
37 views

functional javascript - how could I generalize this code that correlates parallel async requests with their results?

/** * takes a list of componentIDs to load, relative to componentRoot * returns a promise to the map of (ComponentID -> componentCfg) */ function asyncLoadComponents (componentRoot, components) ...
2
votes
0answers
82 views

Connect Four AI (Minimax) in Clojure

I wrote a Connect Four game inlcuding a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc. But ...
3
votes
1answer
91 views

The eternal dilemma: bar.foo() or foo(bar)?

I was using foo(bar) as it's adopted for functional programming. console.log( join( map(function(row){ return row.join(" "); }, tablify( ...
3
votes
2answers
110 views

Palindrome test in Haskell

I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the functional way of doing things. I built this short module to test if a given string ...
1
vote
0answers
25 views

Is this code for getting the dependency tree of a file correct?

function dep_tree(graph,node,prev_deps){ return uniq(flatten(graph[node].map(function(child_node){ if (contains(prev_deps,child_node)) throw "Circular reference between ...
0
votes
0answers
96 views

Could someone profile the space and time complexity of this Haskell snippet?

I'm new to programming and even more new to Haskell, below is a little tid-bit I wrote that operates on a bunch of lists. I am wondering if someone would be kind enough to walk through the function ...
4
votes
2answers
64 views

Is there a way to simple Haskell class instance?

I define a Pixel data with different size like this. data Pixel = RGB8 Word8 Word8 Word8 | RGBA8 Word8 Word8 Word8 Word8 | RGB16 Word16 Word16 Word16 | RGBA16 Word16 ...
1
vote
1answer
32 views

Any way to optimize or improve this python combinations/subsets functions?

I believe this is essentially the same method as the itertools.combinations function, but is there any way to make this code more more perfect in terms of speed, code size and readability : def ...
0
votes
1answer
32 views

Generalize subsets function for any order subset, concisest way possible? [closed]

Implementing a toy Apriori algorithm for a small-data association rule mine, I have a need for a function to return all subsets. The length of the subsets is given by parameter i. I need to ...
1
vote
1answer
64 views

List-flattening function in erlang feels too wordy

I wrote a tail-recursive list-flattening function, but I'm not too happy with it. a) Is tail-recursion necessary here, or will the function be optimized without it? b) It's ugly how many clauses ...
1
vote
1answer
117 views

Functional Exception handling with TryCatchFinally Statement helpers

Hello All, I wrote something to the effect of a try catch finally statement helper in functional style so that I can shorten much of the code I'm writing for my Service Layer that connects to a sql ...
2
votes
2answers
95 views

How to make this python function and its inverse more beautiful and symmetric?

I like the radix function and found a really neat way to compute it's inverse in python with a lambda and reduce (so I really feel like I'm learning my cool functional programming stuff) : def ...
5
votes
4answers
227 views

Which is considered better: push(array,value) or push(value,array)?

This is valid for many other functions. get(array,key) or get(key,array) ? find(array,value) or find(value,array) ? Etc...

1 2 3 4 5 7
15 30 50 per page