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,077
questions
1
vote
1
answer
128
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 ...
3
votes
1
answer
90
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
699
views
Performance of Haskell prime sieve
I have this code, which is a pseudo-Sieve of Eratosthenes for generating primes:
...
2
votes
1
answer
85
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
139
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
135
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
1
answer
107
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
94
views
Mutable IORef-based factorial example in Haskell
Here is my attempt to write the infamous factorial using Data.IORef.
...
1
vote
0
answers
152
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 ...
2
votes
2
answers
86
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
412
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
211
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
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:
...
0
votes
1
answer
125
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
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
1
answer
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....
1
vote
1
answer
56
views
2
votes
0
answers
89
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
145
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
119
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
449
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
129
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
117
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
141
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
849
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
142
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
401
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:
...
0
votes
1
answer
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:
...
4
votes
1
answer
770
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
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
1
answer
108
views
Manacher Algorithm in Haskell
Please review the manacher algorithm in haskell. Find the longest Palindrome in a String.
...
5
votes
1
answer
310
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
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
...
2
votes
0
answers
76
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
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 ...
2
votes
1
answer
70
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
435
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
247
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
188
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
575
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
989
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']):
...
4
votes
1
answer
726
views
Is there a better way to apply a filter over an Either right value?
Suppose you have an IO (Either String (String, [Int])) and you want to filter the [Int].
Let's say we want to use the following ...
5
votes
1
answer
2k
views
Reading a CSV file using Haskell
I'm reading a CSV using Haskell. I'm not sure if this is the appropriate way to do it.
This is what I'm doing:
Read rows from a CSV -> return lazy byte string
Parse the headers and rows from the ...
1
vote
3
answers
87
views
Word frequency finder
Challenge: find the top three most frequently used words in a string. Only imports from the base package are allowed (source: codewars)
I'm looking for feedback on (...
5
votes
1
answer
171
views
Small combinator parsing library in Haskell
I recently wrote code to parse lambda expressions written in a lisp like format, using a small hand-rolled parsing library.
The goal
This code was written as a part of this code-golf challenge not as ...
1
vote
1
answer
221
views
Finding the argmaximum of a list in Haskell
I've been doing project euler problems in Haskell, and often I've found the need to get the value that gives the maximum of a function.
For example,
...
5
votes
1
answer
368
views
Breadth first search on trees in Haskell
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 ...
4
votes
1
answer
691
views
Minesweeper in haskell
I have recently been learning Haskell, and wrote a minesweeper project as an exercise. Here is link to the project.
Basically the code is separated into two parts, the pure part (no monads) and impure ...
1
vote
1
answer
66
views
Build a fixed-length vector from a recursive factory function
I need a function of type forall (n :: Nat). RandomGen q => q -> Vec n q. Obviously this is possible to do (correctly, don't just ...
1
vote
1
answer
54
views
Suggestions on making this parsing/unparsing format more human-friendly
I am working on some application which involves regular expressions with counting. Also, these regular expressions are not necessarily over some fixed alphabet, but over some class of predicates over ...