Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated.

learn more… | top users | synonyms (1)

1
vote
0answers
15 views

Which one of these both run-length decoding algorithm is the most optimal?

I'm working out on Ocaml.org 99 problems, and I solved the run-length decode one. Here is the solution given by the site: ...
2
votes
1answer
22 views

Aggregation of a collection of object's nested array-properties

Use Case So our lead programmer loves to follow the NIH Anti-Pattern and consequently I'm not allowed to use Underscore.js and can only use Vanilla JS... and we have to support IE8. The goal is to ...
5
votes
1answer
82 views

BBCode to HTML converter using functional programming

I was inspired to write a BBCode to HTML converter as I'm currently learning functional programming. I wanted achieve functional cohesion. jsFiddle I'd like feedback on: structuring of the code. ...
2
votes
2answers
28 views

What do you think about this custom syntax? [closed]

I'm making a programming language and I've got the basis of a virtual machine working. The next step to is design the actual syntax for the language. I'd just like to know if whether the example ...
5
votes
2answers
43 views

Decomposing bitfield with Haskell: is recursion the only way to do this?

Here's a program to take a bitfield like 7 and decompose it into the flags [1,2,4]. Ignore that the algorithm for doing this doesn't use bit shifting/is stupid. Problems: it seems like I have to have ...
6
votes
2answers
70 views

Package manager in Clojure

I wrote a package manager in clojure that does 5 things: depend a b //creates a and b (if they don't exist) and adds dependency on a install a //installs a and its dependencies list //prints out ...
11
votes
3answers
186 views

Java 8 Effective Use of Multiple Streams

I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code. This code finds the Cartesian product of ...
10
votes
1answer
138 views

Refractoring OOP vs. Functional Programming Approach

I am writing a python script that will call mandrills export activity api for every blog on a worpress mu install except for the main site. The script is designed to be called from a cron job on a ...
6
votes
1answer
76 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
2
votes
1answer
36 views

Loop filling a set with logging

After watching Raymond Hettingers talk Transforming Code into Beautiful, Idiomatic Python I got back to a function I wrote. I'm not quite sure how to make it more pythonic but I think this might be a ...
6
votes
1answer
51 views

Monadic Immutable Linked List in the Least Functional Language Evar

I've written a List monad as an example for a related question. This is a rather frustrating experience as I wanted to use Java, which (as of Java 7) still lacks lambda expressions and lacks ...
4
votes
0answers
41 views

Review of genetic algorithm code in Erlang

I've written an Erlang implementation of the genetic algorithm for a hello world program described here: http://www.puremango.co.uk/2010/12/genetic-algorithm-for-hello-world/ This is my first time ...
5
votes
1answer
48 views

Conversion from decimal to negabinary and vice versa in Haskell

Recently I set about to writing conversion functions in Haskell between decimal and negabinary. I tried to write them in as much functional a style as possible, also aiming at brevity. Below I present ...
3
votes
3answers
136 views

Better way to write this code in functional manner using map and reduce?

I have an array of items on which I have to perform 2 tasks: Applying a function on the array item Checking if the value is true or false. The functional approach to solving this would be ...
4
votes
1answer
50 views

Good OCaml style

I wanted to write a small but non-trivial function in OCaml to test my understanding. I have only a basic understanding of the libraries, and no idea at all of what is considered good style. The ...
5
votes
1answer
93 views

Read text from stream char by char

I've started learning F# and functional programming in general, but the code I wrote doesn't seems to be really functional. Could you take a look and say how to make it more as it should be in ...
6
votes
3answers
176 views

Functional approach to splitting list into sub lists

Here is my functional approach to split a list into sub lists, each having non-decreasing numbers, so the input \$[1; 2; 3; 2; 4; 1; 5;]\$ computes to \$[[1; 2; 3]; [2; 4]; [1; 5]]\$ The code ...
2
votes
1answer
78 views

Filtering a dictionary by subject of definitions

I am writing a function to filter a "dictionary" by the "subject" of its definitions. The dictionary data structure is a hash-map of this kind: ...
10
votes
1answer
115 views

(How) should I avoid writing procedural code in Haskell?

I'm trying to implement a left leaning red black tree as described here. This is their snippet for insert ...
6
votes
1answer
112 views

Reading input from the console in F#

In the process of learning F#, I wrote this code that reads lines of input from the console and stores them in a list. As far as I can tell the code works correctly, but since I'm new to functional ...
3
votes
0answers
57 views

Elixir pipes and anonymous functions

I recently got started with Elixir. I'm used to F#'s pipes, and Seq.map and LINQ's .Select statements. Things are different in ...
2
votes
1answer
62 views

Functional Re-Write in Scala: Rows of Strings with a Max Width

I came across an issue the other day where I really just could not think of a functional solution. So I fell back on my imperative programming skills. Since a functional solution still eludes me, I ...
4
votes
1answer
79 views

Centroid of a polygon in Clojure

I am studying Clojure and functional programming. I wrote this function to compute the centroid of a polygon specified as a vector of points, e.g. ...
5
votes
1answer
136 views

Code with many “early returns (exits)” into the functional style

I have some Scala code that uses Internet to authorize a user. Therefore, it can throw Exceptions like IOException in the method. The original code was written in ...
6
votes
1answer
680 views

Clojure Neural Network

After reading this article about Neural Networks I was inspired to write my own implementation that allows for more than one hidden layer. I am interested in how to make this code more idiomatic - ...
2
votes
2answers
138 views

“Hell Difficulty” Haskell Fast & Hard

I'm a complete neophyte to Haskell with only a smidge of FP experience – I did some Racket programming academically and have written some semi-FP JavaScript professionally, but now I'm trying to learn ...
1
vote
0answers
110 views

Review my F# Red Black Tree Implementation [closed]

I have written this implementation for red black tree. I also have some helper methods to verify whether the generated tree is really balanced or not. Looks good to me.... but I find that most of the ...
3
votes
1answer
75 views

Hangman game background image inefficient?

I'm making a Hangman game and it seems that my code doesn't provide me much freedom with using layouts. I added an image to my JFrame then I added a JPanel to my image which I'm using for all the ...
1
vote
1answer
114 views

Review my F# QuickSort Program

OK... last sort of the day and probably the most fun. F# is really awesome. ...
1
vote
1answer
91 views

Merge Sort Program

I have written the following program to implement merge sort in F#. Can you please review this and let me know how can I write this in the most functional way (also most efficient and concise)? In ...
1
vote
2answers
44 views

Review my F# BubbleSort Program

I have written this code for BubbleSort in F#. Can you review and let me know how I can do this in most functional way. ...
2
votes
1answer
68 views

Using types in F#

I've played with F# for over a year, but I've only recently begun tentatively using it for professional work. I'm concerned that my c-style OOP principles are blinding me to the advantages of a ...
4
votes
3answers
107 views

Improving F# conditional assignment with match expression

In my code I declared a dictionary to store various counters let counters = Dictionary<Type, int>() Later, I need to generate several labels using these ...
5
votes
1answer
104 views

Better or more idiomatic way to apply a sequence of functions in Haskell

This is one of my Haskell solutions to a variation of the N-Queens problem, where the queens can move like knights in addition to their normal moves. It has been optimised somewhat to avoid ...
6
votes
1answer
106 views

Monad Transformers in C#

I am working on using monad transformers in C#. I would like to know if the following code I present, shows that I have understood this. I am fairly new to this so any feedback / comments are really ...
5
votes
1answer
153 views

Generic pure functions memoization

I like to create tools for memoization since it can sometimes be useful. I recently created a generic tool for memoizing pure functions results. Here is an example og how it works: ...
0
votes
0answers
87 views

Optimizing my Quadratic Sieve, with advice on style?

I'm still new to Haskell, and I'd like others' opinions on optimizing my basic quadratic sieve, in addition to feedback on the code's clarity and functional style. The ...
3
votes
2answers
230 views

Function that builds dictionary based on lambda params

I've written a method in c# that allows me to do create a dictionary from a passed in object and N lambda expressions that reference that objects properties and methods. It's working the way I want it ...
4
votes
1answer
164 views

Functional linked list

I'm looking for feedback in general: code correctness, best practices, design patterns; everything you think about this. Is it bad code? Where can it be improved? I've been implementing functional ...
3
votes
1answer
265 views

Coding Functional style taking longer time than its Imperative style

I wanted to try out F# so I decided to I converted a library file from c# to f#. I have done that successfully(thanks a you people in stackoverflow). At first I ported the code from c# to f#. Than I ...
1
vote
2answers
107 views

More functional approach

I wonder if there is a more "functional" way of implementing something like this: ...
8
votes
2answers
375 views

“Zip-like” functionality with C++11's range-based for-loop

My goal was to get the following code to work: ...
3
votes
2answers
255 views

How to rewrite this code in functional way?

My code looks like imperative style code. I want to make my code more functional. How I can rewrite my program so it become functional style code? ...
3
votes
1answer
99 views

Can this be written more concise and aligned with the Functional Reactive Programming paradigm?

Trying to learn FRP and Elm. Is the program below "ok" from the perspective of FRP and Elm? What could be improved? The program can be executed here: http://elm-lang.org/try ...
2
votes
1answer
87 views

Functional Programming Critique Ocaml

I'm doing an exercise where I need to convert 'ints' to 'bignums' in ocaml, for example: 123456789 -> {neg:false; coeffs:[123;456;789]} There were a lot of things going inside my head when writing ...
1
vote
4answers
193 views

Using Func<T> instead of helper methods in a class

I really like functional programming in C#, it gives you a lot of flexibility. I am wondering if it is the right idea to use functions instead of helper methods, and to make the code more readable. ...
6
votes
3answers
338 views

Refactoring to functional style C#

Hi I'm trying to improve my functional skills and seeing where it fits and where it might not. Please review the code and see where functional practices might be applied, I'm specifically looking at ...
2
votes
1answer
83 views

Haskell Bencoded Dictionary Parser

I have been working on a Bencoded string parser in order to improve my knowledge of Haskell. After running the code through hlint, I still have a few questions: As I noted in the comments, the key ...