Questions tagged [haskell]
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,080 questions
0
votes
0
answers
55
views
Augment vi editing mode in haskeline by implementing the ; and , commands
haskeline is a reimplementation in haskell of the GNU Readline library (the one that by default allows you to delete the word you just typed on your shell's command line by pressing Ctrl+w, for ...
5
votes
1
answer
503
views
How to implement an AVL tree efficient enough in Haskell?
upd: I am very sorry about my mistake. The old version of data is download from luogu, but the website do NOT allow me to download the data of the worst case. In fact, when facing same amount of ...
3
votes
2
answers
198
views
Pattern Finding In Lists of Strings (2d Char Array), Advent of Code Day 04 Solution
This is part 2 of Day 4 of 2024's AoC: The problem is as follows:
It's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this:
...
1
vote
0
answers
96
views
Value-level proofs of type-level membership and subset relations in Haskell
As part of a larger project, we're using type-level strings to identify "parties" (synonymously, "locations").
Critical to the system is the ability to express and enforce ...
5
votes
3
answers
310
views
HackerRank, Haskell simple "compression" algorithm
The question asked is very straight-forward and is simple enough to solve. What I am looking for is that hopefully I can get some understanding for using the constructs and built-ins of the Haskell ...
4
votes
1
answer
108
views
Scraping the calendar of some public libraries from their websites
I've been learning some Haskell as an amateur (to be precise: I started programming with this language, and it has been a year or less since I started seriously). So far, I have realised only small ...
8
votes
1
answer
147
views
Haskell 2-player TicTacToe terminal game
I want to get better at functional programming so I started with this simple 2-player TicTacToe game. Next I want to add a simple min-max algorithm to make it a 1-player game, but before that I'd like ...
3
votes
1
answer
109
views
Parse 2D Cartesian coordinates and output their Polar form
The following code parses a 2D Cartesian coordinate passed as Cart2Pol <x> <y> and prints the coordinate in ...
2
votes
0
answers
88
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 ...
4
votes
1
answer
227
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 (...
1
vote
1
answer
239
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 ...
4
votes
1
answer
139
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 ...
4
votes
2
answers
780
views
Performance of Haskell prime sieve
I have this code, which is a pseudo-Sieve of Eratosthenes for generating primes:
...
3
votes
1
answer
133
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 ...
5
votes
1
answer
185
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 ...
2
votes
1
answer
174
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
...
2
votes
1
answer
167
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 '...
3
votes
3
answers
149
views
Mutable IORef-based factorial example in Haskell
Here is my attempt to write the infamous factorial using Data.IORef.
...
2
votes
2
answers
132
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:
...
2
votes
1
answer
552
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:
...
4
votes
1
answer
269
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 ...
2
votes
2
answers
111
views
Stepwise nested pattern mattching with exceptions
Background
I'm building a lisp-like toy language in Haskell with the following (stripped down) AST:
...
0
votes
1
answer
164
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 ...
4
votes
1
answer
106
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 ...
2
votes
1
answer
108
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....
1
vote
1
answer
87
views
2
votes
0
answers
119
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
1
answer
201
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 ...
2
votes
1
answer
164
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 ...
2
votes
2
answers
507
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 ...
3
votes
1
answer
151
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
1
answer
173
views
Hangman game in Haskell, written using a state monad
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 ...
3
votes
1
answer
183
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 ...
6
votes
2
answers
932
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 ...
2
votes
1
answer
180
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 ...
3
votes
2
answers
502
views
Generic splitting in Haskell
I am new to Haskell and took it upon myself to make a simple generic list-splitting (e.g. string-splitting) function:
...
1
vote
1
answer
113
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:
...
4
votes
1
answer
923
views
Haskell: implementing Read for a custom dynamic value type
I'm using Haskell to interpret a dynamically-typed language. I have a sum type called Value which can represent some basic objects:
...
3
votes
1
answer
163
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
1
answer
146
views
Manacher Algorithm in Haskell
Please review the manacher algorithm in haskell. Find the longest Palindrome in a String.
...
5
votes
1
answer
354
views
Validate Finnish IBANs
I am currently studying an online course in Haskell and there are no "model examples" of the assignments after finishing them. I'm slowly getting the hang of this, but I'd like some feedback ...
2
votes
1
answer
147
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
...
2
votes
0
answers
92
views
Haskell proof checker for FOL with equality
Is this a correct implementation in Haskell of a proof checker for first order logic with equality? I am most interested in if it is correct, and if the functions can be made clearer. I would like it ...
2
votes
1
answer
201
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 ...
2
votes
1
answer
98
views
Haskell Twitter Thread Follower
I'm learning Haskell and even though I have experience with Functional Programming the Typesystem has been a challenge. I did this yesterday (after like 2 days) and I would like to know whether this ...
5
votes
1
answer
531
views
Number to Text converter in Haskell
I've written this code in Haskell to convert a number into its written form. It feels ok but at the same time I feel like it can probably be improved on a lot. I would appreciate help in improving it.
...
3
votes
1
answer
296
views
Efficiently calculating perfect powers in Haskell
I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell
The number 81 has a special property, a certain power of the ...
3
votes
0
answers
208
views
Advent of Code 2021, Day 3 in Haskell
This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal.
...
8
votes
1
answer
617
views
Haskell Tic-Tac-Toe (with automation and GUI)
There are already many Tic Tac Toe posts. But as far as I can tell, none of the ones in Haskell are complete with a GUI
Here is my implementation with Gloss. Gist Link for convenience
...
4
votes
1
answer
1k
views
Generate possible combinations by range and length
I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. ['a'..'z']):
...