Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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.

5
votes
1answer
27 views

Finding duplicated entries

Since the Esteemed Academia wants me to learn Haskell, and Haskell seems just weird for me, I thought that to train some basic Haskell skills I'd write a simple script I now need in Haskell. This is ...
0
votes
1answer
27 views

Haskell: How to split the main:: IO() to a main::IO() and a function

This code is to recreate the game 'Earthworms'. The part I need help with is the main :: IO() part. I want to split this part ... ...
2
votes
0answers
86 views

Fast Hamming sequence generation in Haskell

I found some months ago that I could generate Hamming multiples of 3 and 5 multiples (3^x & 5^x) in one list comprehension. There are many fewer 3 and 5 Hamming multiples in a Hamming sequence. I ...
4
votes
1answer
89 views

Stable marriage in Haskell

I implemented a stable marriage problem in Haskell few month ago. It's not optimized at all and I'd like to know how to make it better from performance and readability perspective. ...
1
vote
1answer
61 views

Subtracting composits from wheel for primes in Haskell

Calculating many remainders for each prime and composite consumes more time. I use a factoring function to find factors of single values. When I use a factoring function to find lists of primes, I ...
8
votes
1answer
389 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 ...
3
votes
2answers
84 views

Number of possible numbers in roman number string

I just started learning programming a few months ago, and I'm intrigued by Haskell. To learn a bit I tried to adapt some code I have in Java so I can see what are equivalent solutions in Haskell. The ...
5
votes
2answers
73 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 ...
3
votes
2answers
31 views

Parse a date in various formats

I have a problem similar to the question, namely reading in text which describes a date - in various formats. I want to use the parseTimeM function from ...
1
vote
1answer
62 views

The quicksort algorithm in Haskell

I am learning Haskell programming language mainly from this source. And there I have encouraged with "an elegant" realization of the quicksort sorting algorithm (the Quick, sort! section). Here it is: ...
0
votes
0answers
72 views

Cellular Automaton in Haskell

I've written a sort of library in Haskell to help create cellular automata by specifying the rules and the data-type of each cell. The problem is, it runs extremely slowly on larger "boards". A 64x64 ...
4
votes
2answers
91 views

Implementation of partitionM

I needed a monadic version of partition today. I settled on the following version: ...
2
votes
2answers
41 views

Implementing Traversable for Coproduct

Given the following definitions of Functor and Coproduct from fp-course: ...
13
votes
1answer
108 views

Brainfuck to NASM compiler in Haskell

After reading this article on writing a Brainfuck interpreter in Haskell and achieving awful performance with it (for example, mandelbrot generating 37.5 minutes on an old Intel Atom powered laptop) I'...
2
votes
1answer
52 views

Modelling Immerman–Szelepcsényi in Haskell

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. ...
2
votes
0answers
30 views

Solving the wooden snake chain puzzle

My code tries to solve the wooden snake chain puzzle: I do so by generating all possible link configurations which are then tested. I was hoping that laziness would take care of the very many ...
4
votes
1answer
118 views

Writing monadic Haskell to evaluate arithmetic expression

I have been studying Haskell by myself for about a little over a year. And I have been stuck at monad/monad transformers for quite a while until recently some examples I read online enlightened me. So ...
1
vote
0answers
53 views

Max heap in Haskell

I wrote a (max) heap in Haskell which is balanced after every (public) operation. Not based on any documentation. Focus is on: speed, that is the right time-complexities (not necessarily optimal); ...
3
votes
0answers
66 views

Kattis Ants challenge

I am trying to learn Haskell doing some contest problems. I have worked a bit with the language but still have a very long way ahead. Right now I am working with a problem called Ants: An army of ...
3
votes
1answer
107 views

Infix to postfix notation in Haskell (Shunting-yard algorithm)

I've written an infix to postfix converter in Haskell using the Shunting-yard algorithm. Example of how it works: ...
1
vote
0answers
44 views

Parsing expressions with combinators

I'm very new to Haskell's ReadP library, and the entire concept of parser combinators, so I was wondering whether there are better ways to do some things in this program: ...
0
votes
1answer
28 views

Using foldl to add numbers, while validating that they are nonnegative

I have a function that will calculate the sum of a list of integer, however if any of the number is negative, it will should an error instead (not throwing exception). The following is a working ...
1
vote
1answer
83 views

Reverse Polish Notation evaluator in Haskell

I've created an RPN evaluator in Haskell, as an exercise because I'm new to this language. It runs well: $ ./rpn 2 3 4 5 + - + -4 And the source code: ...
1
vote
2answers
83 views

Haskell Hamming Sequence Logic

It was suggested I place this code here. I had posted it on StackOverflow for a kind of review. I have tried to generate Hamming numbers using primes but the speed of the generation slows the higher ...
2
votes
0answers
64 views

Project Euler #81 in Haskell: minimal path sum through a matrix

I just completed Project Euler Problem 81 in Haskell: In the 5 by 5 matrix below, ...
3
votes
1answer
124 views

Find the length of a frequency-change cycle (Advent of Code 2018)

I tried to do the second part of the 1. December challenge of Advent of Code in Haskell. I'm fairly new to Haskell but I have plenty of experience in other (procedural) languages. I struggled with the ...
7
votes
1answer
1k views

Advent of Code 2018 day 1 part 2: find the first repeated number after some increases and decreases

Here is the problem: Part Two You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. ...
1
vote
1answer
30 views

Stack Exchange API Reader

I've been working on some code to pull questions from the realtime feed on stackexchange.com and query more information about them from the API. It works, but I'd love some feedback on how I could ...
1
vote
1answer
41 views

Implement State Monad transformer in Haskell from scratch

When I was studying Monad Transformer, I decided to create StateT s m a from scratch with instances for Functor, ...
3
votes
0answers
81 views

Vocabulary memory game in Haskell

As a beginner I try to implement a vokable memory game. It is still missing some feature (Loading, Display), but I would like to hear how to improve what is already there. The user should identify ...
3
votes
1answer
113 views

Determining whether (x,y) points in the input constitute a function

I'm learning Haskell, and I've finally gotten around to coding up some Haskell. This code passed my tests. This code takes a line from standard in which tells it how many cases it's going to have (1 ...
5
votes
2answers
183 views

A simple queue implementation in Haskell

I'm a member of a discord channel and sometimes people post simple coding exercises for fun. This time the exercise was: Implement the following operations of a queue using stacks. push(x) -- Push ...
9
votes
3answers
1k views

Given a Haskell list, return all sub-lists obtained by removing one element

I am trying to write a Haskell function which takes a list ls and returns all sub-lists obtained by removing one element from ls....
2
votes
1answer
77 views

Implementing foldl1 in Haskell

As an exercise (scroll to the first set of exercises) for learning Haskell, I have to implement foldl1. I believe I have implemented it successfully and while ...
1
vote
1answer
142 views

Expression tree in Haskell with support for differentiation

A simple binary expression tree in Haskell without operator precedence and without parentheses. Any comments would be much appreciated. ...
4
votes
0answers
44 views

Functional blob counting

I have image files consisting of black and white pixels encoded as RGB8. I want to count the number of blobs i.e. contiguous areas of white pixels. I rewrote this algorithm in haskell. The algorithm ...
2
votes
1answer
78 views

Graham Scan Algorithm in Haskell

I have just begun learning functional programming and Haskell. This is my attempt to implement a solution to Graham Scan Algorithm in Haskell. Note that I am not even sure if this is indeed Graham ...
4
votes
2answers
60 views

Determine whether path A→B→C on a plane constitutes a left or right turn

I have recently started learning functional programming and Haskell. I have encountered this problem: Consider three two-dimensional points a, b, and c. If we look at the angle formed by the line ...
4
votes
1answer
133 views

Maze solver BFS in Haskell

I am really excited that I just wrote my Haskell maze solution in bfs. This is my very first haskell (and I still haven't tried to build a maze in haskell so that maze is hard coded xD) ANY ...
2
votes
1answer
81 views

Haskell/Yesod - Butchering use of MaybeT

The following is some code that is used to provide the frontend with certain parameters when rendering a form. The parameters are conditional based around what data is being changed, ...
4
votes
1answer
38 views

Find labels in string in Haskell

I wrote code that parses a table header string in order to obtain two string tags, one for variable name (like GDP) and another for unit of measurement (like ...
3
votes
2answers
193 views

Caesar Cipher in Haskell, on every other character

I'm learning Haskell, and I tried to do an exercise which it is an implementation of the Caesar Cipher method. The problem asks for cipher a text which it is in lower case and can contain characters ...
3
votes
1answer
98 views

Printing right triangles recursively in Haskell

I've implemented a simple program to print out 4 right triangles oriented in different ways to learn Haskell. I'm sure there are more efficient ways of doing what I have done, and I just want some ...
1
vote
1answer
71 views

Simple calculator that sums numbers

This is a calculator that only sums numbers: ...
3
votes
1answer
93 views

Monoidal tree interview in Haskell

I was working on the following interview question: Given an array of integers, return a new array such that each element at index i of the new array is the ...
2
votes
1answer
42 views

Haskell 'n' layered ANN forward pass

I'm trying to write a simple 'n' layered ANN in haskell for supervised learning, it will eventually have back prop and you'll be able to use it in a step by step fashion through a GUI which will graph ...
2
votes
1answer
80 views

String Calculator kata in Haskell

In order to practice some Haskell, I tried this kata, where the task is to add some numeric inputs that are delimited by commas or newlines. I have the below solution in Haskell which passes my tests,...
7
votes
1answer
191 views

A simple brainf*** interpreter in Haskell

I am very new to Haskell and come from languages like C++, although I do have some experience with Scheme. Here, I wrote a simple brainf*** interpreter, which so far is my largest project. I followed ...
3
votes
1answer
46 views

Simplifying if statement in a StateT monad transformer

While learning the basics of Haskell I decided to challenge myself with seemingly simple task - write a program that would push the user input into a stack if it's not an empty string or pop the value ...