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.

1,079 questions
Filter by
Sorted by
Tagged with
149 views

### Last Stone Weight Problem in Haskell using list insert

Background Saw this problem on TheJobOverflow which seems to be a LeetCode question. It bothered me that the "challenge" of this problem was to recognize the need for a specific data-type (...
25 views

### Last Stone Weight Problem in Haskell Using fold

A previous solution of this code has been posted on Code Review before. This solution is more complicated then that one, but more performant (see the below) Why is this another Question instead of a ...
1 vote
241 views

### Changing an element in a list when a predicate holds

My current project is a Settlers of Catan server in Haskell. I often manage to achieve my goals within Haskell, but the code is getting messier as the project grows. My question is about the ...
1 vote
56 views

...
1 vote
135 views

### Haskell code optimization for short Pi approximator

Very new in Haskell, as a first easy program I went for an old algorithm of mine to approximate pi by counting points within a circle. The snippet below is what I could get working. I had quite an ...
1k views

### Introduction to Haskell: Validating credit card numbers

I have implemented the introductory challenge of University of Pennsylvania's CIS 194: Introduction to Haskell (Spring 2013) course. I have added the most important information of the problem ...
2k views

### Implementing Haskell's unwords

Learn You a Haskell explains the unwords function. \$unwords ["hey","there","mate"] "hey there mate" Here's my implementation. ...
723 views

### UPenn Homework 3: skips function

I've started learning Haskell by following along the CIS 194 Course from UPenn. In the first lessons there is talk about wholemeal programming and certain ways idiomatic Haskell code looks like. Now, ...
1k views

### Sum of divisors in Haskell

I decided to write a function divisorSum that sums the divisors of number. For instance 1, 2, 3 and 6 divide 6 evenly so: $$\sigma(6) = 1 + 2 + 3 + 6= 12$$ I ...
785 views

### Simple prime factorization program in Haskell

I'm finally learning Haskell this summer and I have a few questions about conventions. I made a simple prime factorization program which is surprisingly fast, much faster than the ones I made in C++ (...
778 views

### Prime factors and perfect square

I want to convert an integer to a perfect square by multiplying it by some number. That number is the product of all the prime factors of the number which not appear an even number of times. Example ...
97 views

### Autocomplete system with prefix tree

I am quite new to Haskell, and this problem is from dailycodingproblem.com: Implement an autocomplete system. That is, given a query string s and a set of all ...
709 views

### Performance of Haskell prime sieve

I have this code, which is a pseudo-Sieve of Eratosthenes for generating primes: ...
89 views

### Solve a letter digit substitution game in Haskell

I am working on a Haskell problem from exercism, which is a learn-to-code website. The problem statement is as follows. Write a function to solve alphametics puzzles. Alphametics is a puzzle where ...
389 views

I'm writing a breadth first search algorithm in Haskell that supports pruning. It is guaranteed that the search will never encounter nodes that have been visited before, so I implemented the search as ...
2k views

### Speedup for Project Euler 44 - pentagon numbers

I'm trying to solve the problems of Project Euler with Haskell within less than 10s with optimized code (ghc -O2). Unfortunately, I'm struggling to find a correct ...
159 views

I am trying to model the proof of Immerman–Szelepcsényi Theorem with Haskell since it heavily uses non-determinism. An explanation of what the point of this is can be found here. ...
143 views

### Ackermann-Péter function call count using Writer monad

I'm quite new to Monads and I tried add function call counting to the Ackermann function code. The goal was simplicity, not performance. I want to have code review on the ...
141 views

### Tic Tac Toe game (Haskell)

I have written a tic-tac-toe game in Haskell and was wondering if anyone could provide any hints on how it could be improved ...
1 vote
116 views

### Count islands in a binary grid

This is the No of Island code challenge. Please review my implementation in Haskell. I know there must be some better way of doing this. Given an m x n 2D binary grid grid which represents a map of '...
100 views

### Mutable IORef-based factorial example in Haskell

Here is my attempt to write the infamous factorial using Data.IORef. ...
76 views

### Stepwise nested pattern mattching with exceptions

Background I'm building a lisp-like toy language in Haskell with the following (stripped down) AST: ...
1 vote
158 views

### Haskell SDL2 Yellow Snow Game. My first program [closed]

I have been working hard trying to learn Haskell, or at least understand it enough to make simple programs. This is my first program. I have been working on it for about a month now. I had already ...
220 views

### Two Sum Implementation on Haskell Brute Force and Optimized approach

Two Sum Problem: Given an array of integers A and an integer K return True if there are two elements two elements xi, xj (i != j) such that xi + xj = K. Return False otherwise. I am implementing the ...
88 views

### Slow Bioinformatics algorithm - Clump finding algorithm in Haskell

I'm working on the famous clump finding problem to learn Haskell. Part of the problem involve breaking nucleotide sequences, called kmers, into subsequences as follows: ...
448 views

### Update ith element from Array of List[Int] in haskell

I am implementing a function that receives a list of list integers and updates the list appending to the ith element a number x, for example: ...
128 views

### Unit testing and alternative to mocking in Haskell

Let's say you have a simple pure function that applies a discount of 30% if the total price of a list of Items is over 30.00 (let's not delve into the fact that I'm ...
81 views

### Generate varied values of some parameters over a neighboring interval

I was recently tasked with creating a function that could generate a "varied" version of some collection of parameters. As in, it should take in a list of parameters, and then vary the value ...
1 vote
74 views

### Meta Collatz Sequence

Context Chapter 6 of Learn You A Haskell contains a function called chain, which outputs the Collatz sequence of a given input. (In short, it takes a natural number....
93 views

### Source map file generator

I'm trying to use this library in my haskell program to generate a source map file, but getting some performance issue. The size of the mapping file generated was about 30M bytes, and it took almost ...
1 vote
151 views

### Haskell function that executes each action until a predicate returns True

The following function executes each action from the list until a predicate returns True. I have a feeling that this function can be rewritten using ...
458 views

### Implement a Queue in Haskell

I teach a data structures and algorithms course. Students can choose C++ or Java. As an exercise for myself, I am doing the assignments in Haskell. My primary goal is to understand what aspects of my ...
120 views

### Project Euler 11 Haskell - Largest product in a grid

Intro I have been learning haskell and functional programming using random Project Euler problems. Currently, I have solved Problem 11. What is the greatest product of four adjacent numbers in the ...
130 views

### Rendering a cross in ASCII art

I've recently tried to write my functions by using composition. But this one, renderCross' is especially difficult to convert fully. How would I write this ...
1 vote
120 views

I recently made a simple hangman game in Haskell but soon wanted to explore the state monad, since it could possibly simplify the code. The result was this (see below), which is exactly 30% more lines ...
145 views

### A simple hangman game in Haskell

I just finished a course of functional programming in uni and continued to study Haskell because I found it very interesting! I made a simple hangman game and would like to hear any of your thoughts ...
856 views

### Simple number-guessing game in Haskell

I've been learning Haskell for 2 weeks now which is I'm very new to it. I would like to have feedback on what is good/bad about my code and how it could I improve in learning functional programming ...
147 views

### Simple Manual Lexer in Haskell

As a beginner exercise, I made small manual lexer that recognizes three types of inputs: integers: /[-]?[0-9]+/ strings, inside double quotes, with backslash ...
1 vote
100 views

A part of my day job is load-testing of our infrastructure. I wanted a tool to quickly write a load scenario for some application (DB, HTTP, ...). I have tried to write something in Haskell (a fairly ...
415 views

I am new to Haskell and took it upon myself to make a simple generic list-splitting (e.g. string-splitting) function: ...
364 views

I'm new to Haskell, and I figured that pairwise summation is something I could do easily. I wrote this: ...
1k views

### My first Haskell: dice rolling

Yesterday morning I decided to stop procrastinating and start learning me some Haskell. So far I've made this, which is a simple cli 'dice rolling' utility that can be used like: ...
1k views

### Longest non-decreasing subsequence, in Haskell

OK, so I recently posted this solution in Python to the longest non-decreasing subsequence problem, and cleaned it up with some expert advice. As a next step, I wanted to translate this solution into ...
74 views

### Haskell solution to Day 2 problem of Advent of Code '21

I won't restate the problem in full, but in a nutshell you have to parse a file with a "direction" and a "magnitude", for instance: ...
177 views

### AdventofCode 2021: Day 3 Solution

I am beginner to Haskell. Here is my solution to Advent of Code 2021 Day 3. Let me know what you think. I was looking at the transpose function and decided not to use head & tail function. Given ...
118 views

### Advent of Code 2021 Day 4

Here is my attempt at Advent of Code Day 4 using Haskell. A file contains list of number in first line. And subsequent lines have the bingo Cards ...
808 views

I'm using Haskell to interpret a dynamically-typed language. I have a sum type called Value which can represent some basic objects: ...
136 views

### Function to sum all Armstrong numbers within a range

I've tried to solve a challenge posted on a LinkedIn forum using Haskell - a language I'm still learning the basics of - and, while the code works correctly, I would like to get some feedback on the ...
1 vote