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
4
votes
1answer
77 views

Cracking Caesar Cipher

I'm new to Haskell, so I wrote a program to crack Caesar Ciphered text for practice. The program calculates the frequency of each letter in the input, and then checks to see which shift minimizes the ...
2
votes
0answers
23 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 ...
5
votes
3answers
816 views

Nearest Neighbour classification algorithm

The following code is from a university assignment of mine to write a classification algorithm (using nearest neighbour) to classify whether or not a given feature set (each feature is the frequency ...
3
votes
1answer
71 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. ...
3
votes
1answer
81 views

Haskell - Caching third party API token across requests

The following code is designed to cache a (UTCTime, Text) value that keeps the Text token around until it expires, preventing ...
1
vote
1answer
35 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
38 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 ...
5
votes
3answers
886 views

Haskell functions to extract and reverse integers hiding in strings

There may not be a "right" way to do it, but I'm inexperienced in functional programming. I'd like some feedback on how the code can be written in a more idiomatic way. Here it is: ...
2
votes
1answer
35 views

Square the sorted array using haskell

I want inputs on how I can square the sorted Array more efficiently in haskell. I wrote a very naive algorithm to solve the problem. What I am doing is comparing the head and the last element of list ...
0
votes
0answers
19 views

Complete IntCode Computer - AdventOfCode day 2, 5 and 9 in Haskell

I am new to Haskell and currently trying to port my solutions for the 2019 installment of the coding challenge AdventOfCode to Haskell. So, I would very much appreciate any suggestions how to make the ...
2
votes
1answer
38 views

Haskell creating a greedy zip function

I am trying to implement a greedy zip method in Haskell where it does not drop the elements, instead, it will use some default value. I appreciate any feedback to make it more compact. ...
1
vote
1answer
32 views

Name for mconcat implementation for applicative monoid

I have implemented a function mcollect which is effectively mconcat only for applicative monoids: ...
3
votes
1answer
67 views

Balanced number checking

Problem Balanced number is the number that the sum of all digits to the left of the middle digit(s) and the sum of all digits to the right of the middle digit(s) are equal. The middle digit(s) should ...
2
votes
1answer
61 views

Trying to convert imperetive code to functional -Haskell

I'm very new to Haskell and I was trying to implement a DFT which is very imperative into Haskell and I wanted to get a feedback. More specially how can I avoid so many helper functions and I avoid ...
1
vote
1answer
69 views

Color highlighter / annotator in Haskell

I'm a Haskell beginner, and I wanted to make a color annotator or color highlighter, one which takes a text as standard input, and outputs that text, with its color words highlighted using the colors ...
2
votes
1answer
26 views

Parse Wavefront OBJ using ReadP

I've been reading Haskell tutorials and books for a while, but I never actually did serious stuff with it. This is my first attempt. It parses an OBJ-file in text format. Later on I will add some ...
2
votes
1answer
39 views

“Reflecting” addition

I'm implementing the following function for signed integer numbers: given endpoints of a closed interval lo and hi, and inputs <...
1
vote
1answer
27 views

Sequences of given addenda whose sum is equal to a given number

Utility to generate sequences of predetermined addenda that add up to a given number. There is also a function for orderly printing and one for converting list of lists in sequence of sequences. The ...
4
votes
1answer
58 views

Manipulate a tree layer wise

I built a tree in Haskell where every node has a number that is unique in its path from root to leaf. Nodes have a dedicated list for children that are leaves. ...
2
votes
2answers
65 views

Concatenate the square of all the digits of a number

Task: given a number (positive or negative), square every digit of it and concatenate them, forming a resulting number. For example: 9119 should become 811181 = 9^2*10^0 + 1*10^1 + 1*10^2 + 9^2*10^3 ...
2
votes
1answer
63 views

AdventOfCode 2019 day 6 in Haskell

I am new to Haskell and currently trying to port my solutions for the 2019 installment of the coding challenge AdventOfCode to Haskell. So, I would very much appreciate any suggestions how to make the ...
1
vote
0answers
38 views

Advent of Code 2 - Intcode Interpreter in Haskell

Problem The problem definition is here. For a quick summary: an IntCode program is an array of ints the program counter starts from index 0, where it reads an opcode, followed by 0 or more ...
2
votes
1answer
68 views

Berlekamp–Massey Algorithm in Haskell

I was recently tasked to write an implementation of the Berlekamp–Massey algorithm (for GF2) from a given inductional proof and decided to fresh up on my Haskell, since converting a proof by induction ...
1
vote
1answer
71 views

Monad to sample without replacement

I created a monad in Haskell that lets you sample without replacement from user-defined urns, and then at the end gives you a list of all possible outcomes. It looks like it's similar to the list ...
3
votes
1answer
88 views

Read file only once

I have a function that returns the contents of a file. Since reading files from disk is expensive, I'd like to avoid having to read the file again after the first read. I've come up with the ...
5
votes
2answers
63 views

Advent of code #2 Haskell solution

I've tried to solve AoC day 2 challenge in Haskell (here - don't worry, it's not a competition so sharing a solution here is OK). The goal is to implement a very simple VM with opcodes 1 (add), 2 (...
4
votes
1answer
79 views

Iterated Prisoner Dilemma Haskell implementation

A collegue and me implemented a simulator the iterated prisoner dilemma from game theory in haskell. We would appreciate any feedback on the quality of the code, how things could be worked out more ...
7
votes
1answer
76 views

Cis 194: Homework 3 (Histogram)

I am following CIS 194: Introduction to Haskell (Spring 2013) online to teach myself Haskell. Following is my response to third exercise of Homework 3, namely Histogram. In which ways I could improve ...
5
votes
1answer
55 views

Beginner's Implementation of Guess The Word

As the title suggests, I'm a complete beginner in Haskell. I've just made my way through the "Input and Output" section of Learn You A Haskell For Greater Good and I thought it would be good to try my ...
3
votes
1answer
67 views

CIS 194: Homework 3

I am following CIS 194: Introduction to Haskell (Spring 2013) online to teach myself Haskell. Following is my response to first exercise of Homework 3. Since I don't have anyone to show my code, I am ...
2
votes
1answer
146 views

Advent of Code 2019, Day 2 in Haskell

This is my solution for Day 2 of Advent of Code 2019. It's the eval function I want to get reviewed. Is this acceptable Haskell code? Is it even close to being ...
1
vote
2answers
83 views

Advent of Code #4 in Haskell - Ascending digits with double digit

This problem is from Advent of Code day 4 (part 1). The problem is to find the number of ints in the given range satisfying: all digits are non decreasing there is at least one group of at least two ...
6
votes
1answer
103 views

Read HTTP header from TCP socket

I'm growing a web server in Haskell that interfaces with TCP sockets using network. To read the HTTP header of the client's message, I use the following function: ...
8
votes
1answer
3k views

Towers of Hanoi in Haskell

Of course the recursive version is trivial: ...
3
votes
0answers
38 views

find indices of 2 numbers in array that sums up to an number [closed]

I would like someone to review my code on find indices of 2 numbers in array that sums up to an number. Following is the code that I have tried and it works. The real issue in the code is I am doing ...
1
vote
1answer
54 views

Using Data.Array to solve Sierpinski in Haskell

Here is an earlier attempt to solve the original problem: Solving Sierpinski Triangle in Haskell I was never satisfied with my solution and found it was awkward and twisty. Here is another attempt to ...
2
votes
1answer
168 views

Fisher-Yates shuffle in Haskell

This is the Haskell version of my recursive Fisher-Yates shuffle in JS. ...
5
votes
2answers
429 views

Solving Sierpinski Triangle in Haskell

I am a Haskell beginner with a background in C++ and Python. I have been teaching myself Haskell for about half a year on and off and recently I started doing Hackerrank problems to improve my Haskell ...
1
vote
1answer
42 views

Dynamic field access in Haskell

I have to transform a response into the internal Coordinate record, some of the fields are lists and I need to handle empty lists case. Records: ...
4
votes
1answer
95 views

Extensible Fizzbuzz in Haskell

I am getting used to how things should be written/thought about in (idiomatic) Haskell. I wrote a FizzBuzz program that prints to the console. I wanted to generate things from the core info of the ...
3
votes
1answer
103 views

Longest Substring Without Repeating Characters, Haskell

I started learning Haskell a while ago and now I am in this dangerous state where I can produce code that does things but which probably makes experienced developers hit their heads against the wall :)...
2
votes
1answer
61 views

Compute text area given letter heights and a text

I have solved the designer pdf question with haskell. The code works. I am posting the code here to know how I could have done it better. First line contains the weight of each alphabet Second ...
2
votes
1answer
120 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 ...
5
votes
2answers
101 views

Haskell Graphing Module (Gloss)

I've been slowly learning Haskell over the past few months. I made a small module to graph functions using Gloss, and I would like feedback on how idiomatic it is (looking for ways to simplify using ...
0
votes
1answer
29 views

Apply labels from a stream to a Bitraversable

Labelling Traversable containers is an ancient and honorable test of skill. My task here is to create a generic labelling mechanism for a ...
4
votes
1answer
319 views

Monitoring Traces for Satisfaction of Temporal Logic Properties

I am trying to implement a monitor for a certain temporal logic. What this means is the following: There is some external source, from which a trace of items are coming. An item looks like a ...
2
votes
1answer
40 views

This is a Monoid instance I wrote for a Tree data type. Is this the most terse way to express mappend?

Here's my type: data Tree a = Empty | Node a (Tree a) (Tree a) Here's the instance declaration for Monoid: ...
6
votes
2answers
14k views

Palindrome test in Haskell

I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the functional way of doing things. I built this short module to test if a given string ...
3
votes
1answer
88 views

Transitive graph

What follows is a small but useful set of functions on transitive graphs and graphs that must be conformed to transitivity. Natural language is rich in transitive relationships expressed in a ...
2
votes
1answer
202 views

Meta-circular interpreter for lambda calculus in Haskell

For learning purpose, I've written a simple lambda calculus interpreter (plus 'Add'). I would like it to be the cleanest and most idiomatic possible. Bonus question: how would you use ...

1
2 3 4 5
20