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

4
votes
1answer
24 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
29 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
113 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
23 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
49 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
29 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
36 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
24 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: ...
2
votes
1answer
25 views

Implement `Applicative Maybe`

Typeclassopedia presents the following exercise: Maybe can easily be made an instance of Applicative; writing such an ...
2
votes
1answer
43 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
14 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
15 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
69 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
171 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
50 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
198 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
34 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
61 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
25 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
55 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
23 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: ...
1
vote
0answers
24 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
29 views

Implementing Functor Instance for `ITree`

Looking at this Typeclassopedia exercise, I typed out foldTree on the following type: ...
-2
votes
1answer
55 views

Creating new types that facilitate safety, flexibility, and DRY-ness [closed]

Disclaimer: I realize that a lot of my trouble has to do with how I'm grounded in the OO way of thinking. If you can point out exactly how I'm trying to force OO thought on Haskell, I would be very ...
4
votes
1answer
52 views

Function to get NGrams fast in Haskell

Is this a good way to get all sublists of a sequence/list that have a given length? An inefficient way to do it would be something like ...
2
votes
1answer
89 views

Folding over a Rose Tree : Tree a -> [a]

I posted this question on StackOverflow. Given this algebraic data type: data Tree a = Node { rootLabel :: a, subForest :: [Tree a] } deriving (Show) ...
1
vote
1answer
33 views

Implementing `concat` using `foldTree` on Rose Tree

I attempted (incorrectly) to implement foldTree here. Recently, I updated it per Petr's help: ...
4
votes
1answer
124 views

Implement `fold` on a “Rose Tree”

Given the following algebraic data type, a Rose Tree: data Tree a = Node { rootLabel :: a, subForest :: [Tree a] } I attempted a ...
0
votes
0answers
13 views

Implementing `dropJ` on JoinList Attempt #2

Initially, I implemented dropJ in this post. However, abuzittin-gillifirca found a bug in my program. So, I re-implemented it in the following way: ...
2
votes
1answer
29 views

Optimize calculation of string self-similarly with its suffixes

I am trying to solve a Hacker Rank problem about string suffixes: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. ...
2
votes
0answers
14 views

URL fetcher and parser for XML feeds

Here is a program that will parse and print XML feed URLs. I want to reuse most of it to add post date to each link. This adds a new concern of CLI and output formatting on top of parsing and (poor) ...
2
votes
0answers
47 views

Haskell program to turn off computer

This a program I wrote to execute various power-related function on my computer. It accepts one command-line argument that describes what action to take and then performs that action. Usage looks like ...
5
votes
1answer
60 views

Simple evaluator of Scheme-like expressions in Haskell

This is my first nontrivial Haskell program: ...
10
votes
1answer
94 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, ...
2
votes
0answers
19 views

Implementing `dropJ` to Drop `JoinList` Elements

In the same vein as the (+++) function on JoinList and indexJ on JoinList, I implemented dropJ to drop elements from a JoinList. Here's my attempt: ...
3
votes
0answers
14 views

Searching a Join List for an index Attempt #2

Originally I posted this incorrect attempt - Searching a Join List for an index. Given a JoinList: ...
3
votes
0answers
55 views

Novice implementation of TicTacToe in Haskell

I want to learn Haskell and figured the best way to do it is to write a simple TicTacToe implementation. However the result feels very inelegant and I think it might be the best playground for your ...
7
votes
1answer
59 views
+100

2D Convex hull exercise

I'm reading Real World Haskell, and this is my first try with the language. This is the result of the exercises of chapter 3: Consider three two-dimensional points a, b, and c. If we look at ...
4
votes
1answer
41 views

Copying files in Haskell

I recently watched a video in which the speaker said that Haskell is not suited for real-world tasks, such as copying files from one folder to another. So I tried to write a program that copies a ...
0
votes
1answer
25 views

Searching a Join List for an index

For the Join List algebraic data type: ...
1
vote
2answers
28 views

Implementing (+++) to Join JoinList's

Related to this question, I wrote the (+++) function to join 2 JoinList's: ...
5
votes
1answer
43 views

Retrieve annotation from a tree annotated with a Monoid

Working on this homework from 2013 for self-learning. For the following Algebraic Data Type: ...
6
votes
0answers
50 views

(Yet Another) Conway's Game of Life in Haskell (Naive)

I code Haskell as a hobbyist. I'm interested in feedback on my naive implementation of Conway's Game of Life. Specifically, as stated in the Quick Tour of the website, I am interested in: Best ...
7
votes
1answer
150 views

TicTacToe in Haskell

Are there any ways which I could improve and simplify this code? Is my code idiomatic Haskell? Is the use of a lens library to change an element of a two-dimensional array unnecessary? If so, how ...
1
vote
0answers
27 views

Extract logic applied in a sequence of integers

I've done it in C# before but thought that a functional language would be a good fit for this kind of thing. From this ascending list of integers: [100,103,106,112,118,121] I had to calculate ...
1
vote
2answers
54 views

Monoid Instance for `a -> b` [closed]

I attempted to implement a Monoid' instance for a function a -> b. ...
3
votes
2answers
39 views

Implementing Division of Streams (where it's a stream of polynomial coefficients)

Per this homework, I'm trying to implement a Fractional (Stream Integer) where the stream represents coefficients of polynomials: where Q is defined as Q = ...
1
vote
0answers
45 views

Quick Sort: Mutable or ST Array

This is the most Monadic code I have written to date :-) and I'd welcome comments. I'm also struck how much faster this mutable approach is than the immutable version I first wrote (see end). OK, so ...