Haskell is a purely functional programming language, featuring static typing, lazy evaluation, and monadic effects. The primary implementation is GHC, a high-performance compiler with a runtime supporting many forms of parallelism and concurrency.
3
votes
1answer
18 views
Another Brainfuck interpreter in Haskell
I came up with the following Brainfuck interpreter in Haskell after thinking about how to represent the program and the memory functionally using zippers to represent current location. This works ...
4
votes
2answers
61 views
Implementation of Graham Scan algorithm in Haskell
Here is an implementation of Graham Scan algorithm for computing the convex hull of a finite set of points:
...
3
votes
1answer
29 views
Attempt at Abstracted YAML Configuration Loader
I've been playing around with writing a simple static blog generator in Haskell (mostly for experience, since there's probably more than a few already made choices that fit my needs). I don't have ...
3
votes
0answers
14 views
Generation and parsing of English numerals (cardinal and ordinal)
I need to use the English numerals (American) in Haskell, so I looked for a library that did it. I have not found one, therefore I developed the program that I am presenting here. There are actually ...
2
votes
1answer
26 views
Sum of multiples of 3 or 5 below N
How do I improve speed of this code? The problem definition is "Find the sum of all the multiples of 3 or 5 below N".
...
1
vote
1answer
43 views
Selection handler for color picker
At some point, I have this function which updates a color picker according the the mouse position, according to whether the user clicked a mouse button and according to its previous state:
...
1
vote
0answers
29 views
Traversing game state space : more search leads to bad results [closed]
I am trying to solve a problem which i think is TSP on a 2-D grid. So, i am trying to get the best result that i can. However, looking ahead 1 step is producing ...
2
votes
0answers
76 views
Small web service using scotty
I'm writing a small tool that allows to manually protocol dial-in-actions. That means a user can say he dials in to a site or he dials out of a site. (What this means is not important for the sake of ...
1
vote
1answer
33 views
Beauty and the Strings in Haskell
I decided to make a solution in Haskell to a problem that I found on another post here at CodeReview (link: The Beauty and the Strings)
I would like suggestions on how to improve letterFreqs. I have ...
0
votes
2answers
61 views
Fast sums of power algorithm
This code reaches time limit on 1 test case, solving this challenge. The approach that I'm using is from the book Algorithms Functional Programming Approach, which is a backtracking depth searching ...
3
votes
1answer
30 views
Generating all size-k consecutive subsets in Haskell
I am interested in splitting any list into consecutive subsets based on a k-value. For example, [1,2,3,4,5] splits into ...
1
vote
0answers
19 views
Implementing `repsep` Parser
I wrote the following repsep parser.
It consists of (where ~ means followed by) and + ...
4
votes
3answers
61 views
Prime factorization of an integer
I have just started learning functional programming (Haskell) for fun after using imperative languages my whole life. I am looking for quick and simple tips from pros on how the particular code I just ...
3
votes
1answer
73 views
6
votes
3answers
105 views
Sieve of Sundaram for Project Euler 7
This is a sequel to my previous question: Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R
I am trying to implement the Sieve of Sundaram in various languages to ...
0
votes
0answers
12 views
Writing Parser for JSON String [migrated]
As part of trying to write a JSON Parser, I'm working on parsing a JSON String value.
Given the following definition from Prof. Brent Yorgey's Haskell course:
...
2
votes
1answer
61 views
Sudoku validator
I've decided to learn some more Haskell writing a Sudoku validator, the function checkSudoku outputs True if the Sudoku is valid and False if it is not. I did not ...
1
vote
1answer
40 views
Naive primality test and summation
I am starting to learn Haskell, so I coded a naive solution to the primality test and summation of primes (Project Euler Problem 10: sum of all primes under 2 million) . As I have an imperative ...
3
votes
1answer
43 views
UpdateGame function for Tetris
I am writing a Tetris game while learning Haskell and I'm trying to make the following code more concise and easier to read. How can I improve it?
Note that the function is not finished yet (There is ...
5
votes
2answers
79 views
Integers from scratch in Haskell
Inspired by this article about natural numbers from first principles in swift I implemented integers from scratch in Haskell.
Besides obviously being extremely inefficient, is this code idiomatic ...
0
votes
0answers
31 views
Parsec for primes and fibs
I decided to spend some time working with parsec. I've written some code to check for primality and for whether something is a Fibonacci number. I'm mainly hoping for feedback on readability, but if ...
2
votes
1answer
21 views
Haskell: downpair :: (Monad m) => m (a, b) -> (m a, m b) implementation
I'm trying to implement function downpairs which takes monad of pairs and transform it into pair of monad
My current implementation is
...
6
votes
3answers
183 views
3
votes
1answer
32 views
1
vote
0answers
25 views
Traversing trees with Lenses
I've recently started learning about lenses and for practice, I wrote a function that finds all paths from the root to a leaf of a tree for which the total of the nodes' weights is equal to a given ...
5
votes
0answers
67 views
Nim game in Haskell implementing optimal strategy
I was inspired by Stas Kurlin's Nim game to write my own. I'm new to Haskell, and quite unfamiliar with monads, do notation, and -- in general -- functional design patterns.
In the game of nim, two ...
5
votes
2answers
270 views
Am I thinking functionally in these simple Haskell functions?
I'm learning Haskell using the University of Pennsylvania's online materials. I'm a few lessons in and was looking for some feedback about whether I'm thinking functionally enough or porting over my ...
1
vote
1answer
34 views
Simple command line todo-list
Introduction
I've written a simple command line todo-list in Haskell.
The full code can be found here. However, given people's time constraints, I have selected three verbose functions for review.
...
5
votes
1answer
59 views
Popping from a list in state while a condition is true
I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling.
To that end, I'm using ...
6
votes
1answer
111 views
Simulate Random Risk Battle
For Prof. Yorgey's 2013 Haskell course, I'm working on a homework to simulate a Risk battle.
...
1
vote
1answer
33 views
Cutting substrings in Haskell
How can I improve readability of this code? indentChar needs to be reused elsewhere.
...
2
votes
0answers
20 views
Auto-expire key/value database (with different key types) in Haskell using acid-state
I am making a key-value database using acid-state. It has three similar "pools", one for cookie records, one for email verification of new accounts, and the last for resetting passwords.
There are ...
2
votes
0answers
25 views
One-dimensional convolution using Data.Vector
As part of some code I've written, I needed to perform a 1-D convolution. This convolution ends up happening quite often, so I wanted to optimise it (in some way other than using a FFT, though I could ...
3
votes
1answer
70 views
Google Code jam puzzle - Welcome to Code Jam
Here is the link to the problem for reference. The problem is to find all possible sub-sequences of "welcome to code jam" in a given input string [and only return the last 4 digits of the total]
I've ...
2
votes
1answer
65 views
Accessing list elements when counting the number of rectilinear paths
I am trying to solve the RIVALS problem on SPOJ: Starting from (0, 0), how many paths are there to reach point (X, Y), only taking one-unit steps moving to the right or up? Constraints: 0 ≤ X ≤ 106, ...
3
votes
1answer
52 views
All balanced parentheses for a given N
Write a function (in Haskell) which makes a list of strings
representing all of the ways you can balance N pairs of parentheses:
Example:
...
2
votes
1answer
33 views
Parsing DAG from text
This module allows to parse indented text file into Map from node to child nodes identified by Coordinate. This module seems way ...
2
votes
0answers
35 views
Ray→plane and ray→quad intersection
This checks the intersection between a Ray and a Plane and between a Ray and a ...
2
votes
1answer
41 views
Writing Read instances for HList
I'm a total newbie at parsing, so I figured I'd start by writing instances of Read for HList, which does not currently have ...
4
votes
0answers
69 views
Evaluating Fibonacci-sequence-based recurrence relation (SPOJ Flibonakki)
I have a function fib2 which returning two values as Tuple but I want to print the product of tuples returned by function fib2. I am new to Haskell so please ...
1
vote
2answers
102 views
Haskell monads: sum of primes
They say you cannot get out of the monad, but I need to use the result (at least for assertions / unit tests). But print how does it do it?
Otherwise, I worked ...
2
votes
0answers
53 views
Haskell in-place quicksort, Ord a => [a] -> IO [a]
As noted below, this is more or less a direct translation from http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C. I'm fairly satisfied with its readability right now compared to the C code; ...
1
vote
2answers
39 views
5
votes
0answers
65 views
Mucheck - a mutation analysis tool for Haskell programs
We have been working on a mutation analysis tool for Haskell tests called MuCheck. It accepts any Haskell source file, and a function name to mutate, applies a defined set of mutation operators on it, ...
1
vote
0answers
51 views
GTK application in Haskell
I'm new to both GTK and Haskell, so I'd appreciate any in both. I'm making an application which for the purposes of this question is just drawing a window that shows a red circle getting larger until ...
7
votes
1answer
45 views
Compile .tex and remove .div file from Haskell
As a practice for interacting with system commands, I wrote a Haskell program that compiles a .tex file specified by the argument.
When one execute this program:
If no argument is specified, print ...
6
votes
1answer
43 views
'Tis the season for gift-wrapping
When reviewing a Graham scan convex hull algorithm implementation, I wrote the following function in an answer:
...
1
vote
1answer
54 views
Project Euler #4 in Haskell
Project Euler #4 asks:
Find the largest palindrome made from the product of two 3-digit numbers.
The code is as follows:
...
1
vote
1answer
36 views
Project Euler #3 in Haskell
Project Euler #3 asks:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
I've written a general solution for any number:
...
4
votes
1answer
35 views
Implementing `Applicative Cons`
Given the following definition:
data Cons a = Cons a (Cons a)
| Empty
deriving Show
I implemented the following attempt at its ...