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

2
votes
0answers
16 views

Perfect elimination ordering and high memory usage

The following code calculates a perfect elimination ordering in a special case in Haskell. I am less worried about its correctness than its high use of memory. The following code runs out of memory ...
2
votes
3answers
48 views
3
votes
1answer
44 views

FoldLeft in Terms of FoldRight

I [believe that I] wrote foldl in terms of foldr: ...
1
vote
1answer
23 views

A small module that allows threads to return their result

I have the following that works similar to forkIO, but returns a blocking "channel" that lets you receive the result of a forked IO computation. My main concern is ...
3
votes
2answers
48 views

Project Euler Problem 57 in Haskell

I'm very new to Haskell, and I would like some feedback on my coding style. Is there anything here that could be made more elegant or concise? This is my solution to Project Euler Problem 57. It ...
5
votes
1answer
98 views

Palindrome check in Haskell

I am learning Haskell and I am doing 99 Haskell problems. There is a problem to check if a list if a palindrome. It's obvious solution is ...
2
votes
1answer
25 views

Haskell monad- and error-handling-style

As an answer to excersise 2.3 in Chris Okasaki's book, Purely Functional Data Structures, I've written the following haskell implementations of insertion in a binary heap: ...
1
vote
1answer
23 views

Create Binary, Balanced Tree Attempt #2

Previously, I posted an incorrect implementation of making a binary, balanced tree from a list of a's. Here's my second implementation: ...
0
votes
1answer
23 views

Get Height of Tree

Given the following Abstact Data Type: ...
1
vote
0answers
13 views

Small Map library written in Haskell

I wrote the following Map "library", and would like general feedback. It's my first major use of Binary Trees, so if I'm doing anything dangerous, I'd like to know. Specifically, I "brute-forced" the ...
2
votes
1answer
32 views

Calculate and use a linear equation based on sets of x and y values

The following asks for 2 sets of data (with corresponding x and y values), calculates a linear equation that matches the data as closely as possible, then allows you to "play around" with the equation ...
2
votes
1answer
70 views

Create Binary, Balanced Tree

I wrote a function, which takes a list of Integers, and then makes a balanced binary tree. Please critique it. I'd like to know know how to make it more concise and idiomatic. ...
2
votes
0answers
22 views

Mini Binary Tree “library”

This is my first attempt at learning binary trees. I'm looking for general feedback on how it could be made cleaner, more idiomatic, or more efficient. ...
2
votes
1answer
48 views

Square root calculation with Newton's method

I am currently learning Haskell in parallel of following the Scala course proposed by Coursera. To practice Haskell I try to implement exercices and/or course example from this course. So there is a ...
4
votes
1answer
64 views

Hailstones and the Collatz Conjecture

The Collatz Conjecture is related to a type of problem called a Hailstone problem; because hailstones circulate up and down through a cloud around a planet until they eventually fall. The Collatz ...
1
vote
1answer
34 views

doSkip Function

I wrote a function, doSkip. For an N-sized list, an element at index 0 consists of the entire input. Index 1 consists of every other element, i.e. the odd ...
12
votes
1answer
195 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. ...
2
votes
0answers
12 views

Is this a design pattern for a Haskell main function? [migrated]

After developing several Haskell applications I've found myself rigorously segregating impure code and failable (partial) functions from their pure & total counterparts. These efforts have ...
4
votes
3answers
167 views

Solution to Hackerrank challenge “Sherlock and Queries”

First, here is the full challenge description: Watson gives to Sherlock an array: \$A_1, A_2, ..., A_N\$. He also gives to Sherlock two other arrays: \$B_1, B_2, ..., B_M\$ and \$C_1, C_2, ..., ...
6
votes
1answer
44 views

Implementing `split`

I implemented the split function in Haskell: ...
3
votes
2answers
64 views

Write a function to extract a given number of randomly selected elements from a list

I'm going through the 99 Haskell problems and I have a few question about the solution I implemented for Problem 23. It asks: Extract a given number of randomly selected elements from a list. ...
5
votes
1answer
139 views

A simple version of Conway's Game of Life using ASCII art

I'd like a general review of my version of Conway's Game of Life. Right now, it's very simple, and doesn't lead to anything interesting yet, as the "seed" generation is randomly generated and small; ...
2
votes
0answers
46 views

Existential Types and IO

In my attempts to grasp Existential Types in Haskell I decided to implement an integer-based fixed-length vector data type. I'm using ghc 7.8.3. Specifically I wanted to write a program which asks ...
0
votes
0answers
29 views

Readability of a point-free applicative parser

I am writing an applicative parser, which you can think of as a minimal Parsec, just to educate myself. I got started with the excellent tutorial from this StackOverflow answer. Here is the relevant ...
1
vote
1answer
17 views

splitWith function for splitting a list doesn't seem optimal

As an exercise from RWH, I needed to write a function that splits a list every time the predicate is false (words == ...
1
vote
1answer
21 views

Find Element in Tree Given a List of Directions

Looking at Learn You a Haskell, I implemented a function that, given a binary tree, i.e. left and right branches, give a list of Directions and give the element at ...
3
votes
0answers
27 views

Splitting and Joining Machines

A small program I use as my "hello world" of streaming libraries is the following: For each line of stdin Interpret the line as a file-name If the file ...
4
votes
1answer
43 views

Simulating the martingale betting system with roulette

I wrote a program that simulates many instances of trying the martingale betting system with roulette in Haskell. At the answerer's suggestion I opted to leave the ...
3
votes
1answer
40 views

Count frequency of characters in a file

Some patterns are emerging ("fmap (b->a) . fmap (c->b) . .. . (IO z)"). Also infix zip is kind-of a hack. What is: Best practice in point-free style? Best ...
2
votes
0answers
26 views

Abstract Key Value Store

I'm attempting to define an abstract interface for a key value store. Some requirements: Once a key has been written it should never be overwritten (although it may be deleted Transactions with ...
4
votes
2answers
41 views

First multi-line Haskell program, extensive use of Maybe type

I'm reading through Write Yourself a Scheme after finishing going through Learn You a Haskell. I attempted one of the early exercises: writing a program to get an operator and two numbers and do a ...
3
votes
1answer
21 views

Update only specific field of specific item (data) in List from YAML

I don't like the logic to update [Repository] list here because I need to map whole list to change only specific field of specific node, I especially don't like ...
4
votes
1answer
55 views

Writing a faster mutable trie

I am implementing a mutable trie. I tested and it produces correct results. However, it is very slow. I benchmark it against plain old Data.Map, which is more than ...
4
votes
1answer
38 views

Safe Reverse Polish Notation

I implemented the following (what I believe to be) safe Reverse Polish Calculator. Now I'm using foldM to take advantage of the power of Monads. Previously, I was ...
2
votes
2answers
39 views

Safely getting the next element of a list

I'm looking for general review and improvements on this code that safely gets the next element of a list (and wraps to the first element if you exceed the list). It just seems a little excessive for ...
3
votes
1answer
37 views

Implementing “Pierre the Tight-rope” Walker from LYAH

Learn You a Haskell presents an excellent introduction to >>= with an example. Basically, Pierre is a tight-rope walker ...
3
votes
1answer
48 views

How can I make this Euler/RK4 implementation more elegant?

One of the things that I'm doing to teach myself is converting some numerical methods from existing Python code (they seem to me to lend themselves to functional programming quite well). I'd like to ...
4
votes
1answer
57 views

A simple database

After failing miserably to get SQL to work with Haskell, I decided to try making my own system. It's fairly simple, but works well for simple jobs (I made it to handle highscores for a number guessing ...
3
votes
1answer
81 views

Random Schedule Generator

In an attempt to try something new, and possibly help out at work, I tried creating a random schedule generator that generates schedules based on 3 inputs (Rotation length, Staff list, and Shift ...
4
votes
1answer
51 views

Using quickCheck for “99 Haskell problems” - problem 1

I'm working on learning Haskell, and I've implemented a solution to the first of the 99 Haskell problems. Here is my code: ...
3
votes
1answer
56 views

Getting the index (x,y) of a char in a “2D” list in Haskell

I have this working function circuitFind that I really don't find nice because I feel there is a better and simpler way to accomplish what it does. ...
3
votes
1answer
55 views

Type dispatch based on runtime value

Suppose we're implementing an interpreter for the bytecode of some stack machine. Let every element of the stack be a Word8, and let the stack be represented by a ...
5
votes
1answer
109 views

Using phantom types to represent amounts and exchange rates of currencies

I posted the following snippet to StackOverflow, and someone said there was much to be improved. ...
4
votes
1answer
85 views

Computation for finding the largest prime factor of 600851475143 is slow

I implemented the following for Project 3 in Project Euler: ...
2
votes
0answers
28 views

Binomial Heap in Haskell

Here's a partial binomial heap implementation in Haskell (just merge and insert): ...
2
votes
0answers
45 views

A solution to the AST Typing Problem

Expression trees are the bread and butter of functional programming but when it comes to adding additional information to an established tree it can be difficult to incorporate such changes without ...
11
votes
2answers
126 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. ...
7
votes
1answer
1k views

Update Map in Haskell

I wrote a function that inserts or updates a Map key value depending on whether the key is already in the ...
3
votes
1answer
32 views
7
votes
1answer
42 views

Primitive stack-based code interpreter

I've written an interpreter for a simple assembly-like language and it's performing slower than I would like. It's split into 3 files: the Parser that converts the source to a vector of ints, the VM ...