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
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 ...
2
votes
1answer
48 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
37 views

Implementing `split`

I implemented the split function in Haskell: ...
3
votes
0answers
22 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. ...
4
votes
0answers
108 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
40 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
23 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
16 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
17 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
24 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
33 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
33 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
25 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
40 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
52 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
34 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
37 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
32 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
45 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
54 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
67 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
48 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. ...
2
votes
1answer
48 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
107 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
75 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
25 views

Binomial Heap in Haskell

Here's a partial binomial heap implementation in Haskell (just merge and insert): ...
2
votes
0answers
37 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
112 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
31 views
7
votes
1answer
40 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 ...
5
votes
0answers
61 views

Website using Persistent, Blaze-html, and Scotty

I know that my let configFilePath = Prelude.head args is unsafe and was wondering how I could handle it better. My deployment almost always has a file at ...
12
votes
3answers
118 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 ...
4
votes
1answer
73 views

Finding Shortest Path

Working on Functionally Solving Problems from Learn You a Haskell, I worked on the "Heahtrow to London" shortest path problem. I'm working on a reduced set of this problem in order to solve a simple ...
3
votes
1answer
65 views

Haskell idioms in functions/arguments handling

I came up with this function rangedReplace as an exercice to use recursion and try different ways to make it work (I made at least 3 completely different versions). ...
5
votes
1answer
61 views

Reverse Polish Notation Calculator

Working through Learn You a Haskell, I made a Reverse Polish Notation calculator. Please critique it. ...
2
votes
1answer
48 views

Folding with trees

I was trying to implement a foldTree function to generate a balanced binary tree from a list of values using foldr (Question 2 ...
5
votes
0answers
77 views

Thinking in 'Haskell' - when to use (state) Monads

I really enjoy Haskell but feel I still have a total beginner's style, and would like to move beyond that. The code below - for Dijkstra's shortest path algorithm - is a case in point. I feel as ...
5
votes
1answer
73 views

Brute force Caesar Cipher decrypter

I wrote the following that tries to crack a message that was encrypted via a simple Caesar cipher through brute force. I'm fairly new to Haskell, so any and all input is appreciated. Because there are ...
3
votes
1answer
30 views

Simplification of consecutive `map`s

I've written the following code: ...
5
votes
2answers
151 views

Merging time series

Is there a better way to do this? A time series, data Model a where Variant :: [(Day, a)] -> Model a deriving (Show) ... where type ...
5
votes
0answers
57 views

Project Euler Problem 18 (Haskell) - Maximum path sum I

I've implemented the solution to Project Euler Problem 18 in Haskell and I'd like to get some thoughts on my implementation. Its the dynamic programming solution, working from the bottom up. ...
3
votes
1answer
26 views

Implementing `randoms`

Learn You a Haskell presents the randoms function. I implemented it as follows: ...
10
votes
1answer
91 views

Random Coin Toss in Haskell

Learn You a Haskell gives an exercise to implement the following function: ...
3
votes
1answer
46 views

Haskell encryption tips

I wrote a variation of the Caeser Cipher and would like some feedback. Is it idiomatic? Can you generally see anything that can be improved? Use example: ...
3
votes
3answers
38 views

Push List Element to Top

Please evaluate this function. It takes a list [a] and an Int, i.e. the index, and returns a new list with the selected item at ...
2
votes
2answers
43 views

Implementing Todo in Haskell

Per Learn You a Haskell, I implemented a simple command-line program, Todo, that accepts 1 of 3 arguments: view or ...
2
votes
2answers
257 views

Counting occurrences of Char8s in a file

To learn some Data.Map and Control.Monad.State, I have written the following code, which should count the occurrences of ...