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

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
vote
0answers
32 views

Parallel Miller-Rabin Prime Test in Haskell

I implemented a prime number finder using the Miller-Rabin prime test in Haskell and it seems to be working. You enter a number and it finds the next prime following that number. I also tried to make ...
2
votes
0answers
29 views

Haskell API for manipulating Tree/Forest

I'm experimenting how a Relation (a cartesian product's subset) can be implemented in Haskell using different data classes. Forest and Tree allow to keeps together in a single data structure ...
5
votes
2answers
66 views

Check if an integer equals the sum of its digits to the fifth power

I can do this in one line in Python: sum([i for i in range(9,9999999) if i == sum([int(x)**5 for x in str(i)])]) Not very fast, but works nicely. I thought it ...
-3
votes
0answers
20 views

Simple Haskell program for displaying 2 digits input by user [closed]

I am trying to write simple programs to get used to using IO in Haskell. The following code, based on chapter 10 of Graham Huttons "Programming in Haskell (second edition)", should prompt the user to ...
3
votes
1answer
52 views

Modifying a random String stored in the clipboard

I wrote a simple program, that will make a string 'noisy' if the clipboard contains one. What disappoints me, is that I should manually check what I got from ...
2
votes
0answers
37 views

Command line utility for school service in Haskell [closed]

This is a program which uses wreq to either request information from a school utility called Ion or sign up for new activities. I feel the error handling is poor and that I've overused the IO Monad. ...
6
votes
2answers
53 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++ (...
4
votes
1answer
33 views

Entropy calculation function in Haskell

I've written a function in Haskell for calculating the entropy of a collection. I'd like feedback on how the function could be rewritten to be more flexible/reusable, and also how to profile the ...
2
votes
1answer
28 views

Performing an action which may return other actions to be performed, concurrently

I have a program which, at its core, involves repeatedly performing an action on some value, and based on that action also returning a list of new values to perform that action on. The pure version of ...
0
votes
0answers
61 views

Rewrite a Haskell function to be total

I've written this function to give the neighbours of a vertex in a graph: ...
5
votes
1answer
65 views

3-function program computing connected components of a point cloud given a distance matrix

I wrote this code in Haskell (instead of Python) for the educational benefit. Can anyone suggest ways to improve this code? I'm guessing that I'm using fromIntegral...
4
votes
2answers
59 views

Simple INI file parser in Haskell

I've written a rudimentary parser for INI files: ...
4
votes
1answer
92 views

Simple decision tree in Haskell

I've been trying to get better at Haskell for a while, and have recently been working on a lot of small projects with it. This constructs a binary decision tree. The command to run it is: ...
4
votes
3answers
653 views

Classic cryptography toolbox: Caesar, Vigenere and ADFGVX ciphers

I wrote a program in haskell that aims to let the user encrypt, decrypt and crack/cryptanalyse pre-electromechanical era ciphers in Haskell. I want to know your opinion on it since this is my first ...
2
votes
1answer
58 views

Minimal Haskell Unit Testing Framework

I'm trying to come up with a unit testing framework for Haskell that is small and self-contained produces TAP-compatible output exits abnormally on failure (instead of relying on the TAP consumer to ...
1
vote
1answer
39 views

Unique elements of a list and corresponding indices in Haskell

Given a list vs, I want to get the list vs' of the unique elements of vs, as well as the ...
5
votes
1answer
56 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 ...
3
votes
0answers
162 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
107 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. ...
2
votes
3answers
202 views

Determining primality by removing select composits

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
410 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
90 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
85 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
32 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
101 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
89 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
104 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
116 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
53 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
31 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
146 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
85 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
71 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
165 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: ...
2
votes
1answer
64 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
30 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
88 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
86 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
73 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
127 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
32 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
42 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
87 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
117 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
349 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
102 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
153 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. ...