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

Clojure function composition: logging results of an action performed by a “pure” function

I'm wondering how I could compose this program better allow it to grow more functionality without constant refactoring. This is my code sample for Hacker School, so I'm less married to the results ...
1
vote
1answer
21 views

Removing duplicates from list and filtering non-letter characters

I'm just starting out in Haskell and have been set an assignment for uni where I have to create a reverse index of words in a text file and find what line numbers they appear on. I also have to remove ...
4
votes
1answer
31 views

Counting items in categories

I'm an experienced programmer that also has a little experience with functional programming, although mostly theoretical (as in hobby-level reading and very minor projects). I recently decided to ...
3
votes
2answers
42 views

Curious fractions in functional Ruby

Problem 33 in Project Euler asks: The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is ...
6
votes
2answers
41 views

Refactor module for calls to internal image service

Looking for help refactoring the following code to follow a Functional Programming paradigm. The first function builds a configuration object with default settings and optional presets, while the ...
1
vote
0answers
18 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
25 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 ...
6
votes
1answer
103 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
30 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
45 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
82 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
256 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 ...
11
votes
1answer
145 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
80 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
38 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
56 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
49 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
49 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
140 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
96 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
4answers
223 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
79 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
119 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
147 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
66 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
71 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
82 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
180 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
701 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
146 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
124 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
77 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
123 views

Review my F# QuickSort Program

OK... last sort of the day and probably the most fun. F# is really awesome. ...
1
vote
1answer
104 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
52 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
117 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 ...
6
votes
1answer
113 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 optimized somewhat to avoid ...
6
votes
1answer
117 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
172 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
91 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
265 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
183 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
268 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: ...
9
votes
2answers
515 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
256 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? ...