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.

learn more… | top users | synonyms

1
vote
1answer
29 views

Function with excessively complex “where” clause

I'm writing a program to differentiate functions (perform basic calculus) in Haskell. The program works, but there's one function that looks very ugly to me: ...
3
votes
1answer
20 views

How to simplify Regex with Data.Text?

This function tells that elements of content either (maybe) match regexes that you like or match regexes that you don't like. This messy code requires ...
3
votes
0answers
56 views

Aho-Corasick string matching in Haskell

I implemented Aho-Corasick string matching in Haskell. It is a purely functional implementation compared to many other implementations. The input to build an automata is ...
4
votes
2answers
64 views

replacing every pair in a list

I need a function (I named it applyToEveryPair) that works on lists, e.g. [x0,x1,x2,x3,...], and uses a function ...
2
votes
1answer
39 views

What's more idiomatic in Haskell?

I'm writing the data structures for my program (a toy compiler), and I'm trying to understand what's the best way to define the AST: Current code ...
10
votes
2answers
169 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: ...
5
votes
1answer
78 views

Revised: AI for 2048 in Haskell

This is a revised version of an AI for the game 2048, written in Haskell. Link to original thread: Poor AI for 2048 written in Haskell I think this version is a lot cleaner, thanks to the tips from ...
3
votes
1answer
40 views

Splitting a List

I wrote the following split function. It takes a list, an element and an ...
6
votes
1answer
69 views

Is a List Sorted?

This function checks if a list is sorted. ...
6
votes
1answer
91 views

Poor AI for 2048 written in Haskell

I'm learning Haskell and thought it would be fun to write an AI for the game 2048 in Haskell. In my implementation I got rid of the randomized aspects of the game. This makes the program ...
2
votes
2answers
23 views

Implement a fold-like Function in Haskell

Let's say I need to write a function that applies a function to each item in a List, and then appends it to an accumulator. When the List is empty, return the accumulator. ...
5
votes
2answers
43 views

Decomposing bitfield with Haskell: is recursion the only way to do this?

Here's a program to take a bitfield like 7 and decompose it into the flags [1,2,4]. Ignore that the algorithm for doing this doesn't use bit shifting/is stupid. Problems: it seems like I have to have ...
3
votes
1answer
35 views

BFS implementation that walks a tile-based field

I wrote a BFS implementation that walks a tile-based field. It takes a function that should return true for walkable tiles and false for walls. It also takes the start and end points. It currently ...
10
votes
1answer
143 views

Probably unneeded returns

This is my first "useful" Haskell program. It's invoked with filenames as arguments where the last filename is the destination to which the content of all other files will be concatenated. As far as I ...
12
votes
0answers
132 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 ...
5
votes
2answers
60 views

Beta Reducer in Haskell

This is my first Haskell application, so any non-name-calling tips will be taken extremely well! It is just a beta reducer: ...
5
votes
1answer
68 views

Using Parsec for simple arithmetic language

I've been reading Types and Programming Languages and I wanted to try to implement the first language in Haskell to understand it properly I have barely written any Haskell before and not used Parsec ...
3
votes
1answer
42 views

Knuth's algorithm M that produces mixed-radix numbers

This is the C++ code of my implementation of Knuth's algorithm M that produces mixed-radix numbers: ...
10
votes
1answer
112 views

Finding the next higher digital permutation of a number

This is my solution for CodeEval challenge 44. The function followingInteger takes a number in its decimal representation and returns the next higher permutation ...
5
votes
1answer
106 views

Project Euler #15 in haskell

I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types: ...
2
votes
1answer
51 views

Solve a maze in the form of a 2D array using BFS - Haskell

Suggestions for improving coding style are greatly appreciated. ...
3
votes
1answer
70 views

DSL for describing circuits

I am working on a micro project: a Haskell DSL for describing circuits. (You can find the code here) I'm pretty happy with everything so far, but there is an ugly function ...
5
votes
1answer
48 views

Find index of lowest unique integer in each line of the file

The code below finds the index of the lowest unique integer on each line of the file. The numbering starts at 1, and when there's no unique value, the 0 should be ...
3
votes
1answer
61 views

Split a string on spaces, accounting for backslash as escape character, in Haskell

This code works, but since I'm just learning Haskell I'm wondering if it could have been done in a more idiomatic way. The main function is called tokenize, and it ...
5
votes
1answer
48 views

Conversion from decimal to negabinary and vice versa in Haskell

Recently I set about to writing conversion functions in Haskell between decimal and negabinary. I tried to write them in as much functional a style as possible, also aiming at brevity. Below I present ...
8
votes
3answers
887 views

PPM/PGM Image processing library in Haskell

EDIT: I changed encodePixel to use Builder, so this is how it looks: ...
7
votes
1answer
119 views

99 Haskell problems, problem 9: Pack function

Today I started to tackle the 99 Haskell problems (http://www.haskell.org/haskellwiki/99_questions). I had to struggle with problem 9 which requires to Pack consecutive duplicates of list elements ...
10
votes
1answer
116 views

(How) should I avoid writing procedural code in Haskell?

I'm trying to implement a left leaning red black tree as described here. This is their snippet for insert ...
1
vote
1answer
48 views

replacing explicit recursion with a fold

as an exercise I wanted to rewrite this toy python code in haskell. ...
6
votes
1answer
116 views

Game of Life implementation in Haskell

I've written a small Game of Life module in Haskell, as well as a small testing application. I'm relatively new to the language, so any kind of comment about the code is welcome. The most important ...
2
votes
1answer
37 views

optimizing a rollercoaster queue

I am working on a haskell exercise where I have to compute the amount of people riding a rollercoaster in a day. I have the following data: the number of rides in a day, the number of seats, and the ...
4
votes
1answer
50 views

Project Euler Problem 1 - Multiples of 3 and 5

I wrote this function for Project Euler Problem 1. ...
3
votes
1answer
94 views

99 Haskell Problems - Problem 2

Background This is my first experience with functional programming and totally self-study. I just have 2-3 days' worth experience in Haskell. Now let's continue with actual code. For Problem 2 of ...
2
votes
2answers
139 views

“Hell Difficulty” Haskell Fast & Hard

I'm a complete neophyte to Haskell with only a smidge of FP experience – I did some Racket programming academically and have written some semi-FP JavaScript professionally, but now I'm trying to learn ...
3
votes
1answer
84 views

Bresenham-like line algorithm

I implemented an algorithm that gives me a list of points that should be drawn in order the get a line between two points. Please note: it works only in a coordinate system whose origin (0,0) is in ...
7
votes
1answer
955 views

A boolean expression parser, written in Java

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 ...
6
votes
1answer
110 views

Better or more idiomatic way to apply a sequence of functions in Haskell

This is one of my Haskell solutions to a variation of the N-Queens problem, where the queens can move like knights in addition to their normal moves. It has been optimized somewhat to avoid ...
4
votes
1answer
183 views

Function to produce unique random numbers

I've been learning Haskell for a few weeks after coming from a C# background. I've written a function to return a number of unique Ints from a specified range: ...
1
vote
1answer
95 views

block comment parser implementation for “monadic parser combinators”

I'm reading monadic parser combinators. On the page 23, they leave an exercise for defining a Gofer block comment parser, and I try to implement it in Haskell. My code is here: ...
5
votes
1answer
92 views

Simple prefix tree

I've written a simple function for building a prefix tree (and searching): ...
3
votes
1answer
63 views

Rearrange content string

From https://www.codeeval.com/browse/115/: You have a string of words and digits divided by comma. Write a program which separates words with digits. You shouldn't change the order elements. I ...
4
votes
0answers
673 views

Performance of List representation of MonadPlus versus Tree representation

I am working on a code where I represent a MonadPlus using a Tree data structure and then explore it, summing over all of the ...
1
vote
3answers
112 views

How to simplify the record syntax with pattern matching?

I've just finished reading Learn You a Haskell and I've started to experiment on my own. I just wanted to create a very simple game system where player A can attack player B. Now I have 2 questions: ...
0
votes
0answers
87 views

Optimizing my Quadratic Sieve, with advice on style?

I'm still new to Haskell, and I'd like others' opinions on optimizing my basic quadratic sieve, in addition to feedback on the code's clarity and functional style. The ...
1
vote
0answers
57 views

Toy Forth interpreter

So I've been reading too much papers and writing too little code. These are my first 300 lines of Haskell: ...
1
vote
1answer
84 views

Math formulas in Haskell

I wrote some math formulas in Haskell and was wondering about how to clean the code up and make it more readable. ...
2
votes
2answers
210 views

Usage of lens for concise update of records

I'm new to Haskell. I'm developing a game-like simulation. I try to use lenses to update the state of the world. Current iteration of code works, but looks clumsy. I am trying to improve it, e.g. I ...
6
votes
1answer
141 views

Automata theory, state reachability in Haskell

I wrote a small library to learn Haskell while studying Automata theory. I have some concerns on my algorithm to evaluate state reachability. That is, I think it might be improved if I can avoid ...
2
votes
2answers
204 views

Haskell grep simplification

I am new in haskell and for start I choosed to write simple grep. Now I want to ask if there is some simplier/shorter way to write it. For example if there is any way to avoid recursion. ...
2
votes
1answer
106 views

Improve Trie manipulation in Haskell code

I have the following data structure: ...