Skip to main content

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

Over-engineered fizzbuzz

I've got this fizzbuzz project I am using for a blog series, among other things. In this version, the fizzbuzz function is fed from a Fibonacci generator. I'm particularly concerned with the ...
Michael Litchard's user avatar
1 vote
0 answers
864 views

Expression parser in Haskell using operator precedence table

This is my first non-trivial Haskell project, an expression parser implemented using the Pratt Parser's technique for managing precedence as a layer on top of Parsec. It simply builds an expression ...
Jules's user avatar
  • 421
0 votes
2 answers
112 views

Chaining Applicatives

I wrote this code to append Maybe's: ...
Kevin Meredith's user avatar
0 votes
3 answers
793 views

All possible combinations of colors for Mastermind

Just started out with CIS 194 on Haskell and wonder what the more idiomatic way to solve this problem would have been. This code is supposed to generate all possible combinations of 6 given colors up ...
AdHominem's user avatar
  • 728
0 votes
1 answer
8k views

Producing all possible combinations of a list

I've written a function that produces all combinations of elements in a given list: ...
Babra Cunningham's user avatar
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: ...
Jir's user avatar
  • 201
0 votes
1 answer
105 views

Unbalanced Parenthesis correction

I'm prepping for a coding interview, and am examining the task of correcting unbalanced parentheses. The finger tree seems to be the right data structure. As a proof of concept I've used ...
Michael Litchard's user avatar
0 votes
1 answer
2k views

Haskell insertAt solutions

I was working on Haskell Problem 21: Insert an element at a given position into a list. Example: * (insert-at 'alfa '(a b c d) 2) (A ALFA B C D) I have ...
Heman Gandhi's user avatar
0 votes
1 answer
131 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 ...
Jir's user avatar
  • 201
0 votes
2 answers
411 views

CRUD App in Haskell with Servant/Opaleye

I was trying to learn how to use libraries like Opaleye and Servant. I wrote this toy Create/Read/Update/Delete App. ...
Agnishom Chattopadhyay's user avatar
0 votes
1 answer
70 views

Optimized list filtering on implementation of Project Euler 23

I'm new to Haskell, the part of my code I'm concerned with is the isSumAbundant function. Surely there must be a better way, in an imperative language I might use a ...
Tristan McPherson's user avatar
0 votes
2 answers
266 views

Fast sums of power algorithm

This code reaches time limit on 1 test case, solving this challenge. The approach that I'm using is from the book Algorithms Functional Programming Approach, which is a backtracking depth searching ...
Dulguun Otgon's user avatar
0 votes
1 answer
64 views

Squashing multiplication identity in an expression

I'm learning Haskell, and one exercise was to implement squashing of identity-multiplications, e.g.: \$5 + (2*1) => 5 + 2\$ Here is my implementation: ...
j-a's user avatar
  • 591
0 votes
1 answer
274 views

Pure fixed length queue

I am modeling an infectious disease with a fixed incubation period. I chose a queue to keep track of when people become symptomatic. I imagined using some operations like so: ...
recursion.ninja's user avatar
0 votes
1 answer
216 views

Sum of fractions

Objective: Create a function to sum a list of fractions (represented as pairs) Rules Only Prelude functions allowed Notes I was debating if I should create a ...
cgoates's user avatar
  • 155
0 votes
1 answer
296 views

Pairwise summation in Haskell, take two

Here's my second try at pairwise summation in Haskell: ...
Pierre Abbat's user avatar
0 votes
1 answer
45 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 ...
RE60K's user avatar
  • 1,456
0 votes
1 answer
32 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 ...
Ignat Insarov's user avatar
0 votes
1 answer
54 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 ...
Wong Jia Hau's user avatar
0 votes
1 answer
114 views

Haskell Servant - login endpoint with two error states

Here is one a handler for dealing with logins, I've recently refactored it to try and make dealing with the different error cases a bit more elegant, though I still think there is room for improvement:...
danbroooks's user avatar
0 votes
1 answer
360 views

Project Euler # 3 in Haskell: largest prime factor of some number

The program works, but is extremely slow. Project Euler problem 3 Problem: What is the largest prime factor of the number 600851475143? ...
UGPhysics's user avatar
  • 159
0 votes
1 answer
55 views

Foldr code snippet

The function traverse takes an element and a map, and returns another element and a new (updated) map. Given a list of elements ...
akonsu's user avatar
  • 273
0 votes
1 answer
165 views

Finding Largest Integer Palindrome within a Set

I've "solved" Project Euler Question 4 and I was wondering if I could make my answer more efficient (I'm using Project Euler to help me learn Haskell). The problem reads: Find the largest ...
Sleep Deprived Bulbasaur's user avatar
0 votes
1 answer
112 views

Naïve optimization by stepping until the error falls below a threshold

As an exercise, I wanted to rewrite this toy Python code in Haskell: ...
Tobias Hermann's user avatar
0 votes
1 answer
49 views

Automation of entity reading in yesod

I'm trying to automate entity reading in my yesod application. This is what I have: ...
user avatar
0 votes
1 answer
400 views

Reinforcement learning example (chap. 1) from Sutton's book

I ported the Lisp Tic Tac Toe code from Chapter 1. to Haskell. The original code repo is down for some reason. I believe I have completely rewritten that in Haskell (Less functional than one would ...
Mohan Radhakrishnan's user avatar
-1 votes
1 answer
70 views

Function to Map `[a] -> [[a]]` [closed]

Given [1,2,3], I wrote the following to get [[1],[2],[3]]: ...
Kevin Meredith's user avatar
-2 votes
1 answer
73 views

Capture some state in Haskell

I want to capture some state in a Haskell function. For instance, I have many thread trying to print on the console and I want the to play nice with each other. So I want to have some XX to make the ...
nicolas's user avatar
  • 171
-3 votes
1 answer
866 views

Project Euler # 1: Sum of multiples of 3 or 5 less than 1000 in Haskell [closed]

...
UGPhysics's user avatar
  • 159
-6 votes
3 answers
151 views

Refactor code to be more succinct but yet preserve the distinction of the `if` [closed]

the below code does what it needs to do. However I would like to know if there are better (shorter) ways to express the below while maintaining the explicitness of showing the decision like with the ...
robkuz's user avatar
  • 129

1
18 19 20 21
22