The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [functional-programming]

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.

Filter by
Sorted by
Tagged with
10
votes
2answers
315 views

You can't sink me

Here is a Battlehips game in F#. Now, before you start jumping up and down on my code, please understand that, for all its awesomeness, F# has a serious limitation: Its compilation is linear, and the ...
10
votes
1answer
516 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...
10
votes
2answers
920 views

“Pure” functional simple Scala battle game simulation

I am a long time imperative programmer (mostly C++) taking my first forays into functional programming with Scala. I am following some online tutorials about functional programming and Scala and I'm ...
10
votes
2answers
230 views

Is this Bridges code F# idiomatic?

Introduction I'm primarily a C# programmer, just starting out with learning F#. I found myself with a problem which felt like it was appropriate for a functional language, and now that I have the ...
10
votes
2answers
602 views

Naive Bayes classifier

I just started learning Haskell, and I must say it is unlike anything else. As my first not-entirely-trivial piece of code I tried to write a simple Bayes Classifier. It is in two parts, a classifier ...
10
votes
1answer
677 views

Small game written in F#

I'm trying to wrap my head around F#. I'd like your honest opinion about this simple game source code that I wrote. Rules are simple: Every player has soldiers and territory Player can recruit ...
10
votes
1answer
127 views

Printing patterns in Haskell

Write a function Int -> Char -> Char -> [String] that will create the appropriate pattern. For example: ...
10
votes
1answer
942 views

Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
10
votes
2answers
542 views

FizzBuzz in JavaScript using Ramda

Just getting up to speed in Ramda, I have implemented this: ...
10
votes
1answer
432 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 ...
10
votes
1answer
192 views

Hunt the wumpus: Functional JavaScript (Node) with Lodash

I'd like a code review of the following simple implementation of the classic game Hunt the Wumpus I'm trying to use JavaScript in the most "functional" way. To help me, I'm using lodash and ES6. <...
10
votes
2answers
699 views

Monad transformers in C# for use in validation

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 ...
10
votes
0answers
738 views

Realtime concurrent Haskell MIDI buffer

Problem Background MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
9
votes
2answers
6k views

Reading input from console in F# (as a sequence of lines)

Consuming input line-by-line until the end is often useful. In C# I would write the following loop: while ((line = Console.ReadLine()) != null) { // ... I ...
9
votes
2answers
3k views

Higher Order Functions in VBA, the dirty way

I have been building a small library of VBA functions. I have a small section with higher order functions that I'd like to share. It uses strings as delegates/function pointers and ...
9
votes
1answer
3k 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 ...
9
votes
1answer
438 views

Neural Network in Haskell

Following this website I wrote a neural network which uses the MNIST training data to recognize digits. The author writes that it should take a couple of minutes to train the network with 30 epochs of ...
9
votes
1answer
196 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 ...
8
votes
3answers
408 views

Story-based adventure with functions and relationships

This is a story-based adventure program I coded by myself (forgive the length). It took a long time but it was fun. It includes loading times, changes in relationships, relationship levels, storyline ...
8
votes
4answers
6k views

Swap even/odd characters

I wrote some code to solve this problem https://www.hackerrank.com/challenges/string-o-permute which basically states: take an even length string and swap all the even indexed characters. For example ...
8
votes
4answers
644 views

Printing a factorial from an integer

I am very new to functional programming. I wrote this program where the user can enter an integer and it will print the factorial. If the user enters a negative integer or not an integer at all, it'll ...
8
votes
2answers
945 views

Mock/Stub out filesystem in F# for unit testing

I'm looking to do some basic verification testing on my functions that write to the filesystem. I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
8
votes
2answers
328 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 the ...
8
votes
2answers
176 views

Function invocation every second time

Recently I got test task at the project, it is fairly simple: ...
8
votes
2answers
142 views

Functional way to have two toggles that turn each other off

I have two sets of toggles that need to "uncheck" each other. This is my current solution which is working. Can it somehow get more functional/elegant? ...
8
votes
2answers
749 views

Sum of Even Fibonacci numbers in functional programming

I want to solve this problem in functional programming (fp) way only. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
8
votes
3answers
857 views

Partial application in C++

Here is my code: ...
8
votes
1answer
349 views

Functional Programming Library

I have started putting together a functional programming library in C# which is somewhat inspired by scalaz and the book Functional Programming in Scala. I am hoping to get some feedback on the Monad ...
8
votes
2answers
171 views

Compiler for a minimal LISP dialect to run on the Java Virtual Machine

As the title states, this is a compiler written in C with a ruby build script that translates a minimal LISP dialect and spits out an executable jar file. I designed this LISP dialect and named it ...
8
votes
2answers
1k views

Functional composition of member function predicates

In C++11, it is en vogue to use small lambda expressions to produce ad-hoc predicates. However, sometimes it's fun to create predicates in a functional, "point-free" way. That way, no function bodies ...
8
votes
1answer
539 views

“Curious Numbers” (HackerRank PE 34)

I was inspired by a certain recent question to try my hand at this challenge: Project Euler #34: Digit factorials \$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible by \$19\$...
8
votes
1answer
193 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 higher-...
8
votes
1answer
676 views

Deleting from Red Black Tree in F#

Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't ...
8
votes
1answer
165 views

Lazy, Functional Parser Combinators

Parser Combinators are the amazingly elegant way to write parsers that has evolved over on the functional programming side of the world, but have been less available or accessible for imperative ...
8
votes
1answer
233 views

Cookie Clicker Switches

In Cookie Clicker there are Golden cookies, and Wrath Golden Cookies. Golden cookies are Clickable cookies that randomly appear, and when clicked they give Bonus cookies, or temporary boosts to ...
7
votes
3answers
4k views

Checking for balanced parentheses

I wrote a method to check if each parenthesis in a string is closed. It should take into account the order in which a parenthesis is presented, e.g. "hello)goodbye(" should return false even though ...
7
votes
4answers
6k views

Print “n” number of “hello world”

I had come up with the following code: ...
7
votes
3answers
459 views

Overusing JavaScript closures?

I've finally gotten around to learning Lisp/functional programming. However, what I've noticed is that I'm trying to bring ideas back into JavaScript. Example Before ...
7
votes
4answers
763 views

Finding the sum of all the multiples of 3 or 5 below 1000, using list comprehension

I'm trying to compare my own implementation with another solution of Project Euler problem #1, which uses a list comprehension: ...
7
votes
2answers
521 views

My first accumulators

Notes I'm working my way through SICP, and as I got very confused by the section on folds, I decided to try to implement foldr in scheme and javascript to understand how it works differently with ...
7
votes
3answers
273 views

Builder/Wizard API for immutable objects

There are a lot of parameters I would like to configure for my Analysis object, so having some kind of composition helpers is a big thing to simplify proper use of ...
7
votes
2answers
1k views

Erlang code to list all IP addresses

This is some Erlang code I wrote to output a string of all the IP addresses of the machine. The string is simply printed to the user for him to read. ...
7
votes
2answers
139 views

Simple function that simulates survey results based on sample size and probability

What is this: This is a simple function, part of a basic Monte Carlo simulation. It takes sample size and probability as parameters. It returns the simulation result (positive answers) plus the input ...
7
votes
2answers
565 views

Recursive higher-order function

I have implemented a through function for myself in a project. Since I am still quite new in python and want to learn it correctly, I would be happy about any ...
7
votes
1answer
292 views

String Format object extension

I wrote an extension to create a string-representation by an object: ...
7
votes
1answer
149 views

Improving multiple assignment using an iterator function

Often I need to perform multiple assignment from a sequence (e.g. from the result of a split()) but with some semantics that, AFAIK, are not available in the ...
7
votes
2answers
979 views

2D lattice random walk plots in functional style

To practice writing code in the functional programming style, I wrote a program to plot two-dimensional lattice random walks. I'd appreciate any feedback about how to improve its "functionaliness". <...