17
votes
Accepted
Decoding Factorio blueprints in Haskell
There's not much to say, to be honest. The type signatures are all there, which is a plus.
Communicate possible errors and make functions total
However, bpDecode ...
16
votes
Accepted
Interactive Brainfuck interpreter in Haskell
Good job on getting it to work! I've used a string reversal program to check your interpreter and it works well. However, it also uses ~36MB of memory, which is too much.
A tape goes both directions ...
16
votes
Accepted
Given a Haskell list, return all sub-lists obtained by removing one element
Here's a simpler way to implement it:
subOneLists :: [a] -> [[a]]
subOneLists [] = []
subOneLists (x:xs) = xs : map (x :) (subOneLists xs)
11
votes
Accepted
Haskell BigInt addition
Your code contains at least one bug, therefore this review is a little bit shorter than usual since you need to fix that bug either way.
So let's instead have a look at testing and how you can find ...
11
votes
Accepted
10
votes
Check if an integer equals the sum of its digits to the fifth power
I'm not familiar with either Haskell or Python, but I'd like to challenge the way you're tackling this problem.
First of all, seven 9s will give you a sum of 7 * 95 = 413343. That's six digits, so ...
10
votes
Accepted
Hamming distance between two strings
When you have a function where not every possible input value can be mapped to one of the possible output values, you have three options: Allow fewer inputs, allow more outputs, or declare that your ...
9
votes
Accepted
Advent of Code 2018 day 1 part 2: find the first repeated number after some increases and decreases
Small things
Data.List.Split
I don't see the need for this module. I see what you're going for with splitOn "\n", however Haskell has a function in Prelude called ...
9
votes
Accepted
Introduction to Haskell: Validating credit card numbers
The way you have divided the problem into subproblems seems fine, so I'll comment on the way you have solved each subproblem.
toDigits: With the strategy of using <...
9
votes
How to implement an AVL tree efficient enough in Haskell?
As I said in a comment, I can't verify that your program as written uses 40MB - your profiling data and my own runs of your program show 3MB, in the same range as the C++ performance you refer to. ...
8
votes
Accepted
Disjoint set in Haskell
Naming
While it's usually not a big deal to have names like d and d' flying around, seeing ...
8
votes
Accepted
Porting functional programming code to Linq
I've hardly written a line of Haskell in my life... but hopefully that isn't too important since you're happy with plain old concrete types here.
As Adriano Repetti said in his comment, working with <...
8
votes
Accepted
Simple Credit card validation
First of all, it's great that you've used type signatures. So let's have a look at the contents of your functions.
Use divMod instead of ...
8
votes
A Haskell implementation of Conway's Game of Life, viewable on the console, no external libs
Since you haven't specified any focus points, I'll focus on readability.
To speed things up, you may want a Matrix or Vector to ...
7
votes
Accepted
takeWhile, groupBy and group higher order functions
struct equal is kind of useless. There's std::equal_to, which does the same thing.
You can make the design more flexible (and ...
7
votes
Accepted
A type for prime numbers
Unfortunately, it's not safe. That's due to the records. If I know any Prime, I can construct a new Prime:
...
7
votes
Accepted
Porting Haskell list comprehensions to Standard ML
Feedback:
The Haskell pyths is not very efficient, and it contains duplicate answers.
fun instead of ...
7
votes
Accepted
Compute the perimeter of a polygon
consec will wrap around and pair the last element of your list as consecutive with the first. This isn't documented in the comment and IMO a little bit problematic. ...
7
votes
Pascal Triangle in Haskell
I don't know if this is more idiomatic, but ever since I've seen an infinite list construction for the Fibonacci numbers, I've been in love with it, so here goes nothing.
...
7
votes
Calculating Maclaurin series for sin(x)
I am not a Haskell expert. Few words from a numerical analyst point of view.
Your concern about recalculating factorial is very well founded. I recommend to take one more step and realize that ...
7
votes
Given a Haskell list, return all sub-lists obtained by removing one element
List as an abstract concept can have many representations.
In particular, with a list being represented by its "zipper" - a pairing of a reversed prefix and a suffix, it becomes possible to have a ...
7
votes
Given a Haskell list, return all sub-lists obtained by removing one element
Look out for standard functions that can help you!
...
7
votes
Accepted
Prime factors and perfect square
We can replace some custom functions or constructs by standard library ones:
\(x:_) -> x is called head
...
7
votes
Accepted
Removing OO style coding from Haskell
Prelude
First of all, good work! I can see the effort you put into grokking something so foreign, and I would like to commend you for it. I will be focusing on reviewing what I think you can improve, ...
7
votes
Accepted
Taking n lines from a file which contains m lines, repeating the file lazily if necessary
Even though module Main is implied when no header is given, I'd write it.
...
6
votes
Simple guessing game in Haskell
Great job on writing readUntilValid as a separate function instead of inlining it in playWith. That being said, we can go a ...
6
votes
Accepted
Simple DFA using the State Monad
Use traverse instead of foldM + accumulate
In a fold, you usually use a function that reduces (or folds) your input into a ...
6
votes
Accepted
Hex string to Base64 in Haskell
Ok, for starters, it mentions on the first challenge:
Always operate on raw bytes, never on encoded strings. Only use hex and base64 for pretty-printing.
Since ...
6
votes
Accepted
Haskell Twitter Thread Follower
Big disclaimer: Whilst I review a lot of code, I'm not even close to a Haskell expert, so some of these ideas are probably not perfect, or even plain wrong, so take as starter points.
A few style ...
6
votes
Accepted
Simple number-guessing game in Haskell
This is pretty good for your first project!
And it mostly works!
Wall
Using the option -Wall will get the compiler to complain more about little ambiguities in your ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
haskell × 1080beginner × 199
programming-challenge × 101
performance × 93
functional-programming × 92
monads × 49
parsing × 47
reinventing-the-wheel × 45
strings × 42
algorithm × 41
recursion × 33
tree × 27
primes × 25
parsec × 18
game × 17
random × 17
mathematics × 17
comparative-review × 16
interpreter × 16
time-limit-exceeded × 15
combinatorics × 15
tic-tac-toe × 14
homework × 14
graph × 13
computational-geometry × 13