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
0answers
12 views

Traversing trees with Lenses

I've recently started learning about lenses and for practice, I wrote a function that finds all paths from the root to a leaf of a tree for which the total of the nodes' weights is equal to a given ...
5
votes
0answers
36 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 ...
4
votes
2answers
225 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 ...
1
vote
1answer
22 views

Simple command line todo-list

Introduction I've written a simple command line todo-list in Haskell. The full code can be found here. However, given people's time constraints, I have selected three verbose functions for review. ...
5
votes
1answer
55 views

Popping from a list in state while a condition is true

I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling. To that end, I'm using ...
6
votes
1answer
70 views
+100

Simulate Random Risk Battle

For Prof. Yorgey's 2013 Haskell course, I'm working on a homework to simulate a Risk battle. ...
1
vote
0answers
18 views

Cutting substrings in Haskell

How can I improve readability of this code? indentChar needs to be reused elsewhere. ...
2
votes
0answers
16 views

Auto-expire key/value database (with different key types) in Haskell using acid-state

I am making a key-value database using acid-state. It has three similar "pools", one for cookie records, one for email verification of new accounts, and the last for resetting passwords. There are ...
2
votes
0answers
20 views

One-dimensional convolution using Data.Vector

As part of some code I've written, I needed to perform a 1-D convolution. This convolution ends up happening quite often, so I wanted to optimise it (in some way other than using a FFT, though I could ...
3
votes
1answer
64 views

Google Code jam puzzle - Welcome to Code Jam

Here is the link to the problem for reference. The problem is to find all possible sub-sequences of "welcome to code jam" in a given input string [and only return the last 4 digits of the total] I've ...
2
votes
1answer
64 views

Accessing list elements when counting the number of rectilinear paths

I am trying to solve the RIVALS problem on SPOJ: Starting from (0, 0), how many paths are there to reach point (X, Y), only taking one-unit steps moving to the right or up? Constraints: 0 ≤ X ≤ 106, ...
3
votes
1answer
46 views

All balanced parentheses for a given N

Write a function (in Haskell) which makes a list of strings representing all of the ways you can balance N pairs of parentheses: Example: ...
2
votes
1answer
28 views

Parsing DAG from text

This module allows to parse indented text file into Map from node to child nodes identified by Coordinate. This module seems way ...
2
votes
0answers
31 views

Ray→plane and ray→quad intersection

This checks the intersection between a Ray and a Plane and between a Ray and a ...
2
votes
1answer
37 views

Writing Read instances for HList

I'm a total newbie at parsing, so I figured I'd start by writing instances of Read for HList, which does not currently have ...
3
votes
0answers
49 views

Evaluating Fibonacci-sequence-based recurrence relation (SPOJ Flibonakki)

I have a function fib2 which returning two values as Tuple but I want to print the product of tuples returned by function fib2. I am new to Haskell so please ...
1
vote
2answers
92 views

Haskell monads: sum of primes

They say you cannot get out of the monad, but I need to use the result (at least for assertions / unit tests). But print how does it do it? Otherwise, I worked ...
2
votes
0answers
44 views

Haskell in-place quicksort, Ord a => [a] -> IO [a]

As noted below, this is more or less a direct translation from http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C. I'm fairly satisfied with its readability right now compared to the C code; ...
1
vote
2answers
37 views

Implementing `sequenceA`

I implemented sequenceA: ...
5
votes
0answers
59 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, ...
1
vote
0answers
43 views

GTK application in Haskell

I'm new to both GTK and Haskell, so I'd appreciate any in both. I'm making an application which for the purposes of this question is just drawing a window that shows a red circle getting larger until ...
7
votes
1answer
43 views

Compile .tex and remove .div file from Haskell

As a practice for interacting with system commands, I wrote a Haskell program that compiles a .tex file specified by the argument. When one execute this program: If no argument is specified, print ...
6
votes
1answer
41 views

'Tis the season for gift-wrapping

When reviewing a Graham scan convex hull algorithm implementation, I wrote the following function in an answer: ...
1
vote
1answer
45 views

Project Euler #4 in Haskell

Project Euler #4 asks: Find the largest palindrome made from the product of two 3-digit numbers. The code is as follows: ...
1
vote
1answer
33 views

Project Euler #3 in Haskell

Project Euler #3 asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I've written a general solution for any number: ...
4
votes
1answer
31 views

Implementing `Applicative Cons`

Given the following definition: data Cons a = Cons a (Cons a) | Empty deriving Show I implemented the following attempt at its ...
3
votes
0answers
30 views

2 4 tree insert function

I'm after creating an insert function for a 2 4 tree in Haskell. I'm just wondering if this is the best way to implement it (especially when handling the Root4s), ...
7
votes
2answers
125 views

Calculating tournament tables

This my first program in Haskell. I'm organizing a ping-pong tournament and I want to calculate a tournament table automatically. The table should contain scores in all games and some statistics ...
0
votes
1answer
29 views

Implement `flatten` for `Cons`

Given the following definition of Cons: data Cons a = Cons a (Cons a) | Empty deriving Show I ...
0
votes
1answer
53 views

Squashing multiplication identity in an expression

I'm learning Haskell, and one exercise was to implement squashing of identity-multiplications, e.g.: \$5 + (2*1) => 5 + 2\$ Here is my implementation: ...
1
vote
1answer
39 views

Sieve of Eratosthenes in Haskell

I've implemented the Sieve of Eratosthenes algorithm in Haskell. Please take a look. Any suggestions are greatly appreciated :) ...
0
votes
0answers
60 views

Haskell version of HackerRank problem solution “NumberTheory/Restaurant”

Link to the challenge: https://www.hackerrank.com/challenges/restaurant Rip this code apart and embarrass me. I want to know about anything and everything you find wrong with it. The problem is ...
0
votes
2answers
38 views

Chaining Applicatives

I wrote this code to append Maybe's: ...
2
votes
1answer
33 views

Markov Chain generator

I'm not sure if a Markov Chain generator is the proper term for this, really all it does is create the chain, it doesn't generate any text from it. The code is below, and I'd appreciate any feedback: ...
3
votes
1answer
27 views

Implement `Applicative Maybe`

Typeclassopedia presents the following exercise: Maybe can easily be made an instance of Applicative; writing such an ...
2
votes
1answer
46 views

Parsing 2D matrix: “[[1,2][3,4]]”

I feel I am over-complicating things, and that there should be a succinct way to achieve this - perhaps using concepts I have not learnt - or some prelude function I have missed out on. How can I ...
1
vote
0answers
16 views

XML processing, hopefully avoiding explicit arguments

I'm stuck trying to refactor code below into one that would be reusable in different contexts. I would like to print another triple, for "parent" sub-tree but without explicitly passing lens to each ...
0
votes
1answer
23 views

Generation of all numbers of arbitrary length and base

quux (['0'..9'] ++ ['A'..F']) 2 generates hexademical numbers of length 2 (with leading zeros), but it's obviously possible to generate any base and any length. ...
2
votes
1answer
21 views

Simplify XML parsing using HXT

Here is code that will output maven coordinates from given pom.xml file. How can I remove boilerplate (possibly convert it to xml picklers)? ...
2
votes
0answers
70 views

Delegating which module's functions to use based on user input

My main concern with this code is this problem - given that this program could generate a prompt string from Bash, Zsh, Fish, etc., I would like to make this code easily extendable so people can add ...
7
votes
2answers
183 views

Brainfuck interpreter in Haskell

Okay, so I just started learning Haskell around a week ago and this is my first real program that I worked on all of yesterday with a lot of help from IRC. I know that using indicies and arrays is not ...
3
votes
1answer
55 views

How many guards/patterns is too many?

I'm working one of the recommended tutorials -- actually, the UPenn online course CS194 -- for learning Haskell, and I have a working solution to the final "challenge exercise" for HW 2. But it seems ...
2
votes
2answers
199 views

Gather first letter from each string in a list of strings

I'm learning Haskell on my own, and I'm wondering if this is idiomatic Haskell. In particular: is it a common pattern to "wrap" the result in a list in order to make a function total? (that's what I ...
1
vote
1answer
35 views

insertBST exercise

I'm just learning Haskell on my own, and did an exercise to implement insertBST. Is this idiomatic Haskell? ...
0
votes
1answer
66 views

Pure fixed length queue

I am modeling an infectious disease with a fixed incubation period. I chose a queue to keep track of when people become symptomatic. I imagined using some operations like so: ...
3
votes
0answers
30 views

Random numbers, IO monad, and pure code

To get used to Haskell, I wrote a little program using the Diagrams package which generates 100 random dots (larger dots are more likely to be in the center). ...
1
vote
2answers
64 views

Formatting a list of strings as a comma-separated string

I'm learning Haskell on my own and I'm following the material of a course. I would like to know if this is idiomatic Haskell. ...
1
vote
1answer
24 views

Assorted Date Parser

I've written a date parser that parses different types of dates using Parsec. Credit for the original problem goes to here. The following formats are as such: ...
2
votes
0answers
28 views

Expressing computations on values as State

I was writing an application with a few Monads in a transformer stack. The top level application state resides in a TVar, and various components of the application ...
0
votes
0answers
31 views

Implementing Functor Instance for `ITree`

Looking at this Typeclassopedia exercise, I typed out foldTree on the following type: ...