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.
4
votes
2answers
61 views
Find two numbers in a sorted array whose sum is closest to a given number
Given a sorted array and a number x, find a pair in array whose sum is closest to x.
Here's my solution:
...
2
votes
2answers
61 views
Taking change - convergent iteration through iterate
For the Code Review community challenge "Implement StackSTV", the algorithm requires a "convergent iterative scheme" to calculate the keep ratios of candidates that have been elected.
To simplify the ...
1
vote
1answer
62 views
Project Euler problem 2 in Haskell
I have just started Haskell, and I want to check if my code is following the spirit of the language.
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find ...
1
vote
0answers
44 views
Haskell ERP (API Backend)
I'm building a mini ERP, with some basic functionalities, I'm doing the Back End in Haskell. However, my code feels very imperative, so any tips and critiques will be highly appreciated.
Repo: https:/...
3
votes
1answer
77 views
Haskell REST API + PostgreSQL
I'm making some small REST API, which I have never done before. I've got some basic stuff working.
Now my job is to add new entities to this, but all my work is reduced to copy-pasting code I have ...
2
votes
1answer
47 views
HashCash Algorithm header generation in Haskell
A thought exercise on my part as I'm relatively new to Haskell. I wanted an interesting project to work on so I decided to implement the Hashcash Algorithm, which is most commonly used as the basis of ...
0
votes
1answer
49 views
Producing all possible combinations of a list
I've written a function that produces all combinations of elements in a given list:
...
2
votes
0answers
43 views
Locally encrypt/decrypt credentials
I wrote some code to encrypt and decrypt some user credentials for services that a locally run application needs to work.
I get a password from the user, use it to stretch a key via Scrypt, and then ...
0
votes
2answers
68 views
Are nested fmap calls idiomatic Haskell? [closed]
Given:
*Main> :t text
text
:: (Selectable s, StringLike str, Ord str) => s -> Scraper str str
I need to perform "second level" ...
2
votes
1answer
53 views
Re-implementing basic list operations
I'm re-implementing the common core functions that work on list as a learning exercise. I'm new to Haskell and often find myself staring at what I've written trying to determine the simpler or more ...
4
votes
1answer
87 views
Haskell command line todo list
I've implemented a command line todo list in Haskell. I've run hlint and build with -Wall, but is there anything else I can ...
1
vote
1answer
60 views
Handling multiple dimensions of arrays with speed
I'm looking to learn how to write efficient Haskell code. This snippet works, but the run time is slow. How can I write faster Haskell code?
Input: maxPrice = 7
...
1
vote
0answers
57 views
Abstracting Haskell types to increase code reuse [closed]
I am updating some code I have. I noticed a lot of repeated code, so I took that as a good sign that some abstraction was needed.
Original Full Source: https://github.com/LambdaScientist/CLaSH-by-...
6
votes
1answer
99 views
Filter Duplicate Elements in Haskell
I'm working on HackerRank to try to improve my Haskell skills along side with reading Haskell Programming from first principles. I wrote a program that works, but it seems to time out on large input ...
5
votes
1answer
102 views
Generating smooth numbers in Haskell
I wrote a smooth function that returns a list of all smooth numbers below a certain limit from a list of prime:
...
1
vote
1answer
58 views
List comprehension for 7x7 board
I have a 7x7 board and I want to select some elements from it. The elements I want to select are marked o, the other ones are marked ...
5
votes
1answer
67 views
D-flop with enable and clear, translated from VHDL to Haskell
I am in the process of translating an implementation of dflop_en_clr from VHDL to Haskell:
...
1
vote
1answer
47 views
A push style parser combinator in Haskell
Usually, parser combinators in Haskell based on the parser type like
newtype Parser t r = Parser ([t] -> [(r,[t])])
This allows back tracking and multiple ...
6
votes
1answer
90 views
Shortest Path (BFS) through a maze
Background
I have decided to use this year's Advent Of Code to learn Haskell. I feel like I vaguely understand the language and can solve most of the problems with relative ease. However, the code I ...
5
votes
1answer
42 views
Pandoc filter to allow embedding arbitary HTML in latex documents
I wrote a Pandoc filter that allows me to embed arbitrary HTML snippets in LaTeX documents, which are then printed out as-is when the document is converted to HTML. It is slightly more generic than it ...
5
votes
2answers
116 views
Transform a Japanese word to furigana
I developed a script to transform a Japanese word in Furigana thanks to the jisho website. But the code is very ugly, especially the extractHiraganaFromHTML and <...
4
votes
1answer
72 views
An attempt at a Haskell Servant API - repetition of Left/Right case matching
I'm attempting to learn more about Haskell by completing a "hobby" project - a simple API to save/retrieve content for pages - used with Hakyll to generate static sites.
I have got something working ...
3
votes
1answer
36 views
Encoding text to keypresses on old phone keyboard (0-9*#)
I am going through "Haskell Programming from first principles" for the first time and I would like to get some pointers on what can be improved in my code, which is the following:
...
5
votes
2answers
132 views
Yet another FizzBuzz in Haskell
Time for the most original question of the year: writing a FizzBuzz in Haskell!
So here is what I came up with:
...
1
vote
3answers
84 views
Select a list from a 2D list, take the last item from its nearest non empty left neighbour and put it at its head
I've just got into Haskell a few days ago and I love it. I'm looking for some pointers and best practices on how to organise and write Haskell code specifically when it comes to managing errors, which ...
4
votes
2answers
79 views
Caesar Shift in Haskell
I started learning Haskell a couple of days ago and decided to build a Caesar shift in it.
...
7
votes
1answer
70 views
Vigenere cipher in Haskell
I implemented vignere cipher in haskell as a part of exercises for haskell programming from first principles.
Though the code isn't all that long, I feel it could use some refactoring to simplify ...
4
votes
1answer
52 views
Kattis, Speed limit; read irregular input
I am able to solve this challenge but when look at my code I know it is not good.
The challenge:
Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don’t know ...
7
votes
2answers
76 views
Generating double linear sequence in Haskell
Need some comments on making the below code more effective. I'm pretty new to Haskell.
The sequence in generateSeq is generated by the rule that if ...
5
votes
2answers
137 views
Calculating the count of integer partitions of a number (uses stateful vectors internally)
I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem:
$$P(n) = ...
5
votes
1answer
74 views
HackerRank Ransom Note, solved using Data.Map as a hash table
I try to solve this hackerrank using Haskell but not sure if I use Data.Map corretly.
Problem in brief:
given 2 strings, magazine and ...
6
votes
2answers
67 views
Repeat an action for a set of elements until all succeed, or progression halts
Context
I'm trying to write a function that drops a list of tables from a database (e.g., tables A, B and C).
This function has the following type, it returns a list of booleans indicating whether ...
3
votes
1answer
43 views
Mad Libs using recursive IO for user input
I'm writing my first small programs in Haskell and still getting a feel for the syntax and idioms. I've written this Mad Libs implementation using recursive IO. I've used IO actions throughout and I'm ...
3
votes
1answer
96 views
Text-based menu to manipulate a database text file
I am making a program that lets a user manipulate a database (a text file).
In the code I am posting, I show only 2 of the menu choices, namely "createdb" and "deletedb", and a few functions I made ...
5
votes
1answer
22 views
Interpreting database values as times and integers
I am working through Chapter 10 of Haskell Programming from First Principles.
I've gotten the code to work, but I am uneasy about the fact that a few of my functions - namely, ...
4
votes
2answers
57 views
Scanl expressed as fold
Inspired by the learn you a haskell exercise to express map with fold I wrote an implementation of scanl by means of a fold.
...
0
votes
1answer
38 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 ...
3
votes
0answers
67 views
Naive implementation of Naive Bayes in Haskell
A simple implementation of Naive Bayes, as I'm a Haskell beginner I've tried to put an emphasis on clarity and documentation. I've tried to incorporate the feedback from a similar question. This is ...
8
votes
1answer
199 views
Haskell code to verify credit number
I am new to Haskell, and wrote a script to verify credit number.
I did some tests, the script worked, but can it be improved further?
...
1
vote
1answer
47 views
Project Euler #45 in Haskell
I've got a solution for Project Euler's problem 45.
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
$$\begin{array}{lll}
\textrm{Triangle} & T_n=n(n+...
6
votes
2answers
138 views
Imperative Sieve of Eratosthenes using destructive updates in Haskell
I've implemented the prime sieve of Eratosthenes in Haskell using a mutable array of unboxed Bools instead of the usual pure and immutable datastructures.
My main concern with this code is speed. For ...
3
votes
2answers
94 views
Count numbers whose digits are only increasing or decreasing
The goal is described here: basically, it is to compute the number of numbers below \$10^n\$ such that its digits are either increasing or decreasing (like 112 or 211, but not like 121).
The original ...
1
vote
1answer
64 views
Logical contradiction type definitions
(Homework alert)
Working my way through "The Haskell Road...", not sure about my solution to exercise 2.15 on page 48 of the second edition:
A propositional contradiction is a formula that yields ...
5
votes
2answers
103 views
Large Power Mod - Extreme Efficiency
I've implemented my own 'power-mod' procedure which will compute a^b 'mod' n for some large b and even larger ...
4
votes
1answer
142 views
Calculating a circle with bezier curves
I am new to Haskell, and have been reading Learn You a Haskell for Great Good!.
I've rewritten a problem that I recently solved in JavaScript in Haskell to practice what I have been reading.
A ...
5
votes
1answer
64 views
Using monads and monad transformers (simple matching engine)
Like most of the folks here, I'm learning Haskell, so I figured an interesting exercise would be to build a matching engine that I could use to build a financial exchange. I'm wondering primarily if I ...
1
vote
0answers
57 views
1
vote
3answers
84 views
Haskell function to format a floating-point number with some precision
I have not yet developed a satisfying coding style in Haskell. In the code snippet below, there is a lot wrong to my taste:
Helper functions which should be local to ...
2
votes
1answer
66 views
Efficient Prime Sieve - Haskell
I'm new to Haskell, and am trying to learn the basics with a simple function that will calculate the list of primes up to a given value (using the Sieve of Eratosthenes). Here is my code so far, which ...
1
vote
1answer
35 views
Inefficient Parsec parser to skip unreachable block
In a parser written with Parsec 3.1.11, I have a performance issue with parsing (or better, skipping) the unreachable branch of a if-then-else statement.
The syntax to be parsed is as follows:
...