Skip to main content
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 ...
Zeta's user avatar
  • 19.6k
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 ...
Zeta's user avatar
  • 19.6k
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)
castletheperson's user avatar
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 ...
Zeta's user avatar
  • 19.6k
11 votes
Accepted

Bubble sort in Haskell

Here's your shortening including a fold. ...
Gurkenglas's user avatar
  • 3,804
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 ...
Glorfindel's user avatar
  • 1,113
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 ...
Sara J's user avatar
  • 4,221
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 ...
cole's user avatar
  • 626
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 <...
sshine's user avatar
  • 741
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. ...
amalloy's user avatar
  • 675
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 ...
Phil Kiener's user avatar
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 <...
VisualMelon's user avatar
  • 7,591
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 ...
Zeta's user avatar
  • 19.6k
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 ...
sshine's user avatar
  • 741
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 ...
kraskevich's user avatar
  • 5,660
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: ...
Zeta's user avatar
  • 19.6k
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 ...
sshine's user avatar
  • 741
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. ...
Vogel612's user avatar
  • 25.5k
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. ...
Eman Yalpsid's user avatar
  • 1,569
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 ...
vnp's user avatar
  • 58.7k
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 ...
Will Ness's user avatar
  • 1,036
7 votes

Given a Haskell list, return all sub-lists obtained by removing one element

Look out for standard functions that can help you! ...
leftaroundabout's user avatar
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 ...
Zeta's user avatar
  • 19.6k
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, ...
cole's user avatar
  • 626
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. ...
HTNW's user avatar
  • 301
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 ...
Zeta's user avatar
  • 19.6k
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 ...
Zeta's user avatar
  • 19.6k
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 ...
hololeap's user avatar
  • 176
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 ...
declension's user avatar
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 ...
ShapeOfMatter's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible