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
44
votes
1answer
1k views

Capture the notion of invertible functions

I find sometimes it is useful to capture the notion of invertible functions. The idea is that if two functions f :: a -> b and ...
42
votes
1answer
3k views

Charmander Brainfuck interpreter in Haskell

I just started learning Haskell and this is my first big project (ie not factorials, fibonacci or graphers). This is kind of a gift for somebody so the language is a bit different. The program works, ...
40
votes
1answer
2k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
28
votes
4answers
5k views

I can has(kell) cheezburger?

Edit 13 June: I have made a new and improved version here. Original Question This is a very rudimentary lolcats translator (it only works on the phrase "Can I have a cheeseburger") in Haskell. This ...
25
votes
1answer
987 views

How can I make my stack monad faster?

I made a stack monad that lets one manipulate and control values on a stack. I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without ...
22
votes
1answer
1k views

Decoding Factorio blueprints in Haskell

In the game Factorio there are string-encoded representations of blueprints that I wish to decode. The implementation according to their wiki is the following: This is a technical description of ...
21
votes
2answers
1k views

Calculating Luhn-algorithm checksum digit

Today I decided to learn some basic Haskell, and for starters I made a program for calculating the checksum of a Swedish personal identification number. It uses the Luhn-algorithm, aka. ...
19
votes
3answers
917 views

Enigma machine simulator - improving recursive algorithm performance

I'm new to Haskell and am confused by why my code seems to preform so poorly, and wonder if there's something I've not grasped about the coding philosophy behind the language, or the best way to take ...
18
votes
0answers
252 views

Mucheck - a mutation analysis tool for Haskell programs

We have been working on a mutation analysis tool for Haskell tests called MuCheck. It accepts any Haskell source file, and a function name to mutate, applies a defined set of mutation operators on it, ...
16
votes
2answers
942 views

Recursive directory tree printer

I wrote this program that recursively prints all the files and directories starting at the current directory: ...
15
votes
4answers
2k views

How to shorten this terrible HTTP header parser?

I am trying to read a line ending in \r\n from a Handle. This is an HTTP header. I’m fairly new to functional programming, so I ...
15
votes
4answers
3k views

Script for copying files to the appropriate directory

In the book Real World Haskell, the author writes in the first line of every file that uses, for example the following: file: ch05/PrettyJSON. The chapter slash and ...
15
votes
2answers
168 views

Interactive Brainfuck interpreter in Haskell

Last week I started learning Haskell, and since I have some experience with Brainfuck already, I decided it would be a great idea to implement an interactive Brainfuck interpreter in Haskell. I'll ...
15
votes
1answer
799 views

Finding Local Maxima

The following function finds all local maxima. A local maxima is an element of a list such that it's greater than either of its neighbor elements. An element with 1 neighbor is not a local maximum. <...
15
votes
2answers
230 views

One, two, three, … Un, deux, trois, …, maxBound::Int

I wrote a numbers-to-words converter for English, then tried to adapt the code to work for French. I'm wondering mainly whether any simplifications are possible. In English English is relatively ...
15
votes
1answer
1k views

Simple xkcd comic downloader

I'd really appreciate some harsh/constructive criticism of what I would consider as my first program in Haskell. The program should download all of the xkcd comics into a folder in the current ...
15
votes
1answer
2k views

Execute a function n times, where n is known at compile time

Motivation In this question, a user asked whether it is possible to inline the following function: ...
14
votes
3answers
2k views

Converting to Roman numerals

As an excercise to "Haskell: The Craft of Functional Programming", I created some code to convert an Integer to Roman numerals. This is the first version and I think I'm probably not doing it in the "...
14
votes
3answers
1k views

Using Fibonacci sequence to generate musical melodies

I recently started picking up the Haskell programming language. I've managed to learn other languages rather quickly, but I'm still having a difficult time grasping some of the basics of Haskell. I ...
14
votes
2answers
4k views

Parsing strings with escaped characters using Parsec

I have been working through the exercises in a Write Yourself a Scheme in 48 Hours/Parsing and hacked together something to get parseString to comprehend escaped characters. Also had some inspiration ...
14
votes
2answers
2k views

Blackjack in Haskell

This is my first attempt at creating a game in Haskell, and I would greatly appreciate some feedback. Here is Main.hs: ...
14
votes
1answer
570 views

Converting simple markup to HTML

This is going to be rather long and generic, so apologies in advance. I've been reading a lot about Haskell lately, but I've never really programmed anything with it beyond simple experiments in ghci....
14
votes
1answer
2k views

Prim's algorithm for minimal spanning trees

I want to write an article giving a Haskell introduction specifically to Java developers, and would like to get feedback on my implementation. Please keep in mind that I don't want to be "too clever", ...
13
votes
2answers
445 views

Resistance is futile, Resistors have been dispatched to model your Resistance

Since it was getting boring to always do OOP Languages I decided to dabble in the functional realm of programming. For that I chose the narrowly missed community-challenge by Edward: Resistor Mania, ...
13
votes
3answers
372 views

Haskell FizzBuzz with a type system

The core problem is simple enough, but I've developed a type system that I'm not sure about. The intention is, if the result is a number, calling num $ fizzBuzz 16,...
13
votes
1answer
1k views

Haskell Particle Simulation

I recently started learning Haskell and as my first project I decided to port a particle simulation I had written in C. The simulation is pretty simple. We have a cubic box with particles (spheres) ...
13
votes
1answer
121 views

Brainfuck to NASM compiler in Haskell

After reading this article on writing a Brainfuck interpreter in Haskell and achieving awful performance with it (for example, mandelbrot generating 37.5 minutes on an old Intel Atom powered laptop) I'...
12
votes
2answers
467 views

Vigenère Cipher in Haskell

I wrote a Vigenere cipher in Haskell, but I feel like I way overdid it. This is the second version of the program that allows custom cipher tables, removing the limit of just having letters from A to ...
12
votes
1answer
17k views

Boolean expression parser

I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to ...
12
votes
1answer
2k views

Simple chat server in Haskell

I've been struggling with concurrent programming in Haskell for a while. It's so hard to reason about, especially when exceptions come into the picture. As a learning exercise, I implemented a ...
12
votes
1answer
2k views

DFA and NFA in Haskell

I've written a determinstic & non-deterministic finite state machine. I've scrubbed the code quite a bit but I wonder if it could perhaps be scrubbed even more. Suggestions for code clarity, ...
12
votes
2answers
526 views

Compute the perimeter of a polygon

This is taken from HackerRank, which I hope is okay. I've been playing around with Haskell and I haven't really been able to find anything that really goes beyond toy examples in terms of how to ...
12
votes
1answer
547 views

Finding the next higher digital permutation of a number

This is my solution for CodeEval challenge 44. You are writing out a list of numbers.Your list contains all numbers with exactly Di digits in its decimal representation which are equal to i, for ...
12
votes
1answer
714 views

m,n,k-game (i.e. generalized tic-tac-toe)

I'm back after Tic-Tac-Toe in Haskell with a new version. I added Haddock documentation and wrote a generalized version known as the m,n,k-game. By doing so, I had to redefine ...
12
votes
1answer
1k views

Detecting cycles in a directed graph without using mutable sets of nodes

I recently came across the classic algorithm for detecting cycles in a directed graph using recursive DFS. This implementation makes use of a stack to track nodes currently being visited and an extra ...
12
votes
1answer
128 views

Solving alethic modal logic formulas using truth trees

Disclaimer: this first section is about alethic modal logic and truth trees. It's important to the question but significant parts of the code can probably be reviewed without it. You're welcome to ...
11
votes
4answers
1k views

Am I thinking functionally in these simple Haskell functions?

I'm learning Haskell using the University of Pennsylvania's online materials. I'm a few lessons in and was looking for some feedback about whether I'm thinking functionally enough or porting over my ...
11
votes
4answers
10k views

Approach to string split by character in Haskell

I'm trying to learn Haskell and the mindset of programming functionally. I have started off by trying to understand the basics by writing code without any Monads in ...
11
votes
2answers
1k views

Game of Life in Haskell

I wondering what people think of this game of life. I don't think it is working properly, but I am interesting in what people think of the general design. ...
11
votes
2answers
149 views

“Vc” as in Vancouver, or Valencia?

It is common to shorten city names when writing, or at least in Sweden. "Göteborg" (Gothenburg) is often referred to as "Gbg" "Uddevalla" is commonly written as "Ua" "Trollhättan" is often written as ...
11
votes
1answer
484 views

On Implementing a Lisp

Background: This began with James Colgan's Lisp-Dojo for Ruby. My implementation can be found here. I then moved on to Write yourself a scheme in 48 hours. This question has to do with one of the ...
11
votes
1answer
176 views

A different code?

I have a xxs list: ...
11
votes
1answer
478 views

The ugly Christmas tree, Haskell style

Inspired by a few inverse tree ascii art F# questions, I wanted to give it a shot in Haskell. As seen in the linked questions, the resulting program reads an Int ...
11
votes
1answer
507 views

Nim game in Haskell implementing optimal strategy

I was inspired by Stas Kurlin's Nim game to write my own. I'm new to Haskell, and quite unfamiliar with monads, do notation, and -- in general -- functional design patterns. In the game of nim, two ...
10
votes
3answers
1k views

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

I am trying to write a Haskell function which takes a list ls and returns all sub-lists obtained by removing one element from ls....
10
votes
2answers
954 views

Processing text files for data extraction and analysis

I started learning Haskell to see if I can use it at my job. A lot of my work is processing text files for data extraction and analysis. For my first test, I added a counter at the end of each line ...
10
votes
3answers
1k views

PPM/PGM Image processing library in Haskell

I've written a small library for reading and writing PGM/PPM images. The format is described here. I attach the library itself and a small utility to convert binary encoded images to ASCII encoding. ...
10
votes
3answers
381 views

Project Euler #1 in Haskell

Looking for feedback/critiques/alternatives to my solution for the 1st Project Euler question: ...
10
votes
2answers
275 views

Enigma machine simulator

As my first (keep that in mind!) Haskall program (full code at end) I've written a simple Enigma machine and would like feedback on the core code related to its stepping and encoding — stripped of ...
10
votes
1answer
459 views

Graph generator for undirected graphs

I am still pretty new to Haskell and am working on a graph generator for undirected unlabeled graphs containing loops and I have a bottleneck in the following functions. So far, I have not given any ...