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.
0
votes
0answers
12 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
19 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
55 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
26 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
16 views
Implementing `repsep` Parser
I wrote the following repsep parser.
It consists of (where ~ means followed by) and + ...
4
votes
3answers
57 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
50 views
6
votes
2answers
78 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
49 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
36 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
40 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
71 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
30 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
19 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
177 views
3
votes
1answer
29 views
1
vote
0answers
19 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
56 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 ...
4
votes
2answers
257 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
29 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
56 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
109 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
18 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
22 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
68 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
64 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
50 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
31 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
31 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
39 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 ...
3
votes
0answers
57 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
98 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
50 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
38 views
5
votes
0answers
63 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
49 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
44 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
42 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
46 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
34 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
33 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 ...
3
votes
0answers
31 views
2 4 tree insert function
I'm after creating an insert function for a 2 4 tree in Haskell. I'm just wondering if this is the best way to implement it (especially when handling the Root4s), ...
7
votes
2answers
127 views
Calculating tournament tables
This my first program in Haskell. I'm organizing a ping-pong tournament and I want to calculate a tournament table automatically. The table should contain scores in all games and some statistics ...
0
votes
1answer
33 views
Implement `flatten` for `Cons`
Given the following definition of Cons:
data Cons a = Cons a (Cons a)
| Empty
deriving Show
I ...
0
votes
1answer
54 views
Squashing multiplication identity in an expression
I'm learning Haskell, and one exercise was to implement squashing of identity-multiplications, e.g.:
\$5 + (2*1) => 5 + 2\$
Here is my implementation:
...
1
vote
1answer
42 views
Sieve of Eratosthenes in Haskell
I've implemented the Sieve of Eratosthenes algorithm in Haskell. Please take a look. Any suggestions are greatly appreciated :)
...
0
votes
0answers
85 views
Haskell version of HackerRank problem solution “NumberTheory/Restaurant”
Link to the challenge:
https://www.hackerrank.com/challenges/restaurant
Rip this code apart and embarrass me. I want to know about anything and everything you find wrong with it.
The problem is ...
0
votes
2answers
38 views