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.

Filter by
Sorted by
Tagged with
2
votes
0answers
32 views

Performance issue regarding Project Euler #60 in Scheme

I solved Project Euler #60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 ...
3
votes
0answers
34 views

Haskell test performance for different container types

I want to test the performance for various types of containers in Haskell. So far I got Vector and List. My goal is to learn how to use typeclass, how to use containers etc. Could anyone point out ...
4
votes
1answer
37 views

Feeding stateful and stateful-effectful computations into each other

I am writing code that runs a simulation in an interactive way. The building blocks are: runStep :: I -> State S O runWorld :: World m -> O -> StateT W m I ...
6
votes
1answer
59 views

N Nested squares

The excercise is to print n nested squares. The nested squares are given as input by the user. Example output for n = 4: ...
4
votes
0answers
31 views

Compute a Working Capital Loan

This code takes a list of EBITDA amounts (for a hypothetical business), and computes a loan that would fund that business with working capital in periods of loss. When the business has positive EBITDA ...
2
votes
0answers
58 views

Candy Land in Haskell

I tried to write Candy Land game in Haskell as a step to work on something bigger than those toy programs/functions I used to write. I wrote myself a python version first, with a functional mindset ...
1
vote
1answer
87 views

Poker Hand Evaluator in Haskell

The idea is to represent a hand as a list of cards and create a frequency mapping, which can then be used to identify what rank of hand you have and arrange your hand in a way that allows the Ord type ...
1
vote
0answers
54 views

Print a tic-tac-toe board

I am currently learning Haskell and as an exercise, I am building a simple tic-tac-toe program. I start with ...
2
votes
0answers
28 views

Splitting a list based on a delimeter into n chunks in Haskell. How can I write my functions more effeciently?

Split: Write a function split that takes a delimiter value “c” and a list “iL”, and it ...
2
votes
1answer
51 views

Keep reading user keyboard input if available, while echoing back the latest available

On StackOverflow I have asked a question a few minutes ago, but then by trying a bit more, I found the answer myself, and I'm posting the resulting working code here for review. What the code does, is ...
3
votes
1answer
84 views

Haskell-like function composition function

Much like this question I'm attempting to write in C++ something which can resemble Haskell's (.) function as much as possible, which is basically Chapter 1's ...
3
votes
0answers
40 views

Solution for Gophercises Quiz game in Haskell

Here is my solution for the Quiz game exercise from https://gophercises.com/. The goal is to write a program that will read questions and their correct answers from a CSV file, ask them from a user ...
2
votes
1answer
66 views

HackerRank - Binary tree to compute the Nth power of natural numbers that sum up to X

I'm trying to solve this challenge on HackerRank. In short, given x and n, I have to determine how many ways I can pick numbers ...
2
votes
2answers
63 views

HackerRank - Filter huge list for elements that occur more than a given number of times

I'm trying to solve this problem on HackerRank, which basically requires the solution to read an input like this (comments are mine) ...
5
votes
0answers
99 views

Yet another implementation of Conway's Game of life in Haskell

(Sorry for my bad English) Hi, I'm interested in getting feedback of my own implementation of Conway's Game of Life. Some details: Uses gloss for animation Uses rio for shorter dependency list My ...
5
votes
2answers
48 views

Advent of Code 2019: Day 6 (with Trees)

I've been going through some 2019 AoC challenges and decided to solve Day 6 in Haskell with the help of Data.Tree. In summary, the puzzle provides a list of orbits (...
2
votes
0answers
24 views

Experimental parser based on a Tree of (String, Set a)

The parser function is immutable and is completely based on the forest of strings with associated properties (String,Set a). Changing the forest changes the behavior of the parser. The use of Data....
1
vote
0answers
42 views

Removing Explicit Recurrsion

I have a fairly complicated function to decode an LZSS byte stream. ...
3
votes
0answers
44 views

How to simplify the following distance function for the taxicab ring metric space?

Consider the taxicab ring metric space shown below. This is a discrete metric space in which we have both a grid and concentric diamond rings. This metric space stretches infinitely in all four ...
6
votes
1answer
110 views

Taking n lines from a file which contains m lines, repeating the file lazily if necessary

The desire for such a function came out of the necessity of generating a "source" of Lorem ipsum by repeating over and over the same 50 or something paragraphs of the text. Actually I am ...
2
votes
0answers
44 views

LZ77 Encoding and Decoding in Haskell

I am trying to learn Haskell and figured I would kill two birds with one stone and also learn about data compression. My ultimate goal is to implement the DEFLATE compression algorithm in Haskell. To ...
3
votes
1answer
40 views

Should I unpack a Maybe with maybe or pass value around

I'm beginning (for the third time in 5 years) to learn Haskell and decided to do a "More or less" console game (game pick a random number, you then have to guess which). First the code, then ...
5
votes
2answers
122 views

Removing OO style coding from Haskell

Having coded in Objected-Oriented style my entire programming career, it's hard to adapt to functional style fully. I implemented a simple Hangman game: ...
12
votes
1answer
208 views

Telegram bot in Haskell using custom monad transformers

Note: I show almost all of my code for completeness, but I really only want the review to focus on Session.hs, Handler.hs, and maybe Controller.hs. I can delete the extra code from the review or ...
3
votes
1answer
31 views

Haskell Hspec/Quickcheck test for numeric function

I'm learning to use HSpec and QuickCheck. As example I was implementing the Pseudocode from Wikipedia:Extended Euclidean Algorithm. You can find the project at github for the implementation of the ...
6
votes
0answers
54 views

Feedback on LZSS implementation

Recently, I've been trying to get back into Haskell, so I tried coding up a LZSS implementation. I realize this is much more easily implemented imperatively, but I wanted to challenge myself. The last ...
2
votes
1answer
75 views

How can I use the State monad effectively in Haskell?

I have written a simple fibonacci function in Haskell that uses the State monad to save solutions to overlapping sub-problems. Now despite the function working I am not really happy with the solution, ...
2
votes
1answer
65 views

Print numbers in a spiral from the center

...
2
votes
0answers
40 views

Finding number of brackets sequences of length n containing a specific string s

I am trying to solve a problem where I need to find the number of bracket sequences \$p\$ and \$q\$ such that for a given bracket sequence s. I have that \$p + s + q\$ is a valid bracket sequence. ...
0
votes
1answer
30 views

Find a n x m binary matrix with exactly a 1's in all rows and b 1's in all columns

[Base on https://codeforces.com/contest/1360/problem/G] So my logic is to process each column at a time and find b rows such that the total 1s in them is less than ...
2
votes
1answer
54 views

Feedback on simple DFS

I am implementing a simple recursive Depth-First Search algorithm on graphs, using StateT and ReaderT for encapsulating all the required information. Pre-requisite definitions ...
4
votes
1answer
43 views

Feedback on simple Merge algorithm

I am writing a simple merge algorithm in Haskell. I wanted to add simple logging, hence am using the Writer Monad to include logging. ...
3
votes
0answers
87 views

Unique Distancing Problem, Memoization in Haskell

note: You might be scared seeing the length of the post, but it's actually not that long because you don't need to read the compiler logs or the python code to understand my code (I wish StackExchange ...
1
vote
1answer
53 views

Basic tic-tac-toe matrix in Haskell

Beginner functional programmer... (but not beginner programmer) Currently, I have the following code: ...
1
vote
0answers
36 views

Feedback on Haskell game server

I am working on a hobby project implementing a card game server with scotty and websockets. The implementation of the game itself is more or less done. Now i am working on the server and I have an ...
2
votes
0answers
47 views

Project Euler #14: Longest Collatz sequence on HackerRank

The following is the conclusion in a long chain of attempts to solve Project Euler problem #14 (Longest Collatz sequence) on HackerRank in the Haskell programming language. The problem is defined as ...
3
votes
2answers
203 views

Caesar-Cipher Implementation

Background I am a total beginner in Haskell, so after reading the Starting out-chapter of "Learn you a Haskell", I wanted to create my first program that actually does something. I decided to do the ...
5
votes
0answers
143 views

A simple chess engine in Haskell

This is my first Haskell project so I don't really have a good feel for what makes Haskell code clean, so they'll be lots of things that can be improved. Things I have a gut feeling are bad design: ...
4
votes
3answers
137 views

Reading String data into a Tree like nested grid structure (like Sudoku Board)

Context The original idea is to create an efficient grid structure for a Sudoku like board but this can be applied to many such grid structures (like wavelet transform on images, JPEG2000 etc). This ...
2
votes
0answers
39 views

Longest Substring Without Repeating Characters in ReasonML/Ocaml

LeetCode Problems 3. Longest substring without repeating characters Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
1
vote
1answer
38 views

Closed form Fibonacci using Integer

I'm implementing the closed form of Fibonacci numbers. I figure using a custom data type I can do so without leaving Integer. It isn't more efficient than the "...
2
votes
0answers
38 views

Project Euler Problem 54 poker hands in OCaml

I've been refactoring my OCaml solution for Project Euler problem 54, which is about comparing poker hands. While I'm mostly satisfied with my second iteration of the refactor, I stumbled upon two ...
2
votes
2answers
153 views

Yraglac's transit woes

I decided to dive into the world of functional programming since my programming so far has been mostly in C/C++, Java, and Python. I've gone through a couple Haskell tutorials and played around in ...
1
vote
0answers
33 views

Convert LaTeX document to HTML

For a web application, I have to transform a LaTeX document on the fly into an HTML string, that is delivered to connected clients via websockets. Thus I installed a filewatcher that waits for file ...
3
votes
2answers
90 views

Parsing nested JSON with Haskell and Aeson

I'm trying to reduce nested JSON data using Haskell and Aeson without creating data/record types. The following code works, but seems ugly and unreadable. Any advice on cleaning this up would be great....
3
votes
1answer
41 views

Existential quantification versus explicit types

I developed a card game engine for a german three player card game called Skat. The operating code lives in a StateT SkatEnv (WriterT [Trick] IO) Monad. ...
4
votes
1answer
46 views

Loading Files from a Directory in Haskell

I'm a very new Haskell programmer, and I've written the following code for loading TSV files. I think it can be improved, but I'm not sure how. I feel like the giant "do" block in loadData is ...
5
votes
2answers
95 views

Bloom Filter in Haskell

I recently implemented a Bloom Filter in Haskell and, although I am not new to functional programming, I am a beginner when it comes to Haskell itself. I'll gladly take any feedback regarding the ...
1
vote
1answer
82 views

Speeding up naive backtracking Sudoku Solver in Haskell

After watching a recent computerphile video on building a very simple sudoku solver I tried to implement the same in Haskell. From this CR question I learned that it is probably a better idea to use ...
1
vote
1answer
76 views

Hands of Straights (LeetCode) Arrange the card

Tried this leetcode question Hands of Straights. https://leetcode.com/problems/hand-of-straights/ Description is Alice has a hand of cards, given as an array of integers. Now she wants to rearrange ...

1
2 3 4 5
21