Questions tagged [haskell]

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.

Filter by
Sorted by
Tagged with
22
votes
1answer
1k views

Decoding Factorio blueprints in Haskell

In the game Factorio there are string-encoded representations of blueprints that I wish to decode. The implementation according to their wiki is the following: This is a technical description of ...
6
votes
1answer
72 views

Haskell Convert 1-800 Numbers

This little app converts 1-800 numbers (with letters) to actual numbers. I'm very frustrated by the insertDashes function as it's very brute force. I'm sure there's a far more elegant solution. I'd ...
2
votes
1answer
78 views

Haskell sentence segregation

I am trying to implement sentence segregation using Haskell, I have achieved a decent bulk of it using the NLP.FullStop library, but this doesn't seem to account ...
4
votes
1answer
73 views

Performance concerns when converting GTK image to greyscale

I have a function which takes GTK Image (It is RGB) and returns a representation of this image as list of grey levels. This is my code: ...
1
vote
2answers
68 views

Three Haskell functions to show filtered results from a list of films

I'm currently working on a simple command line application in Haskell and I have three functions that are quite repetitive. The three functions: ...
4
votes
1answer
240 views

Caesar Cipher in Haskell

I've come up with this simple implementation of the Caesar cipher. It takes an integer argument and a file to produce the cipher text like so: ...
2
votes
1answer
103 views

Monad Transformers

I've run into the same scenario involving Monad Transformers a few times now, and I'm looking for some "best-practice" advice. Bear with the introduction, the issue itself is really simple: Say you'...
3
votes
0answers
405 views

Snake in Haskell with Ncurses

I've created the Snake implementation in Haskell. User input and graphic is handled by the Ncurses library. The goal of this question is to get the feedback on what can I improve to make it more ...
2
votes
2answers
85 views

Populating a list with user input

I am trying to learn me some Haskell because I found it to be an interesting language. Right now, I am trying to implement a function in Haskell to get acquainted with the language. The function just ...
5
votes
1answer
819 views

Type safe, easy to understand matrix multiplication

I always hated matrices (as they are taught in those linear algebra course books that I have browsed), because it's an obscure way of saying "a tuple of linear functions of same arity". It is very ...
3
votes
2answers
160 views

Haskell API for accessing a SQLite database

I have a SQLite database, and I'm trying to make a web API for it. I've been writing it in Haskell, and using scotty as the server. I templated out the website from ...
3
votes
2answers
180 views

CodeWars - Three-pass compiler for arithmetic expressions

I'm looking for feedback on my solution to the Tiny Three-Pass Compiler kata on CodeWars. The kata is to implement a compiler for an arithmetic language in three passes - parsing to an AST, constant ...
2
votes
1answer
67 views

AoC Day 22: Sporifica Virus Part 1, a Solution in Beginner's Haskell

Until recently, I was very much only devoted to imperative languages (mainly C++ and C, to be precise), when I decided to venture into unknown waters by picking up a new, completely different language,...
4
votes
2answers
375 views

Custom maximumBy and minimumBy in Haskell

Going through the magnificent Haskell Programming from first principles, I'm currently reimplementing functions from standard libraries such as maximumBy and ...
2
votes
0answers
127 views

CIS 194 - UPenn Haskell Course (2013) - Homework 4 - Tree Folding

I have been self studying the UPenn Haskell course, and I am unable to get feedback/grading on the assignments complete. This specific portion that I am having concerns with asks to write a function <...
5
votes
2answers
192 views

Porting functional programming code to Linq

I am very new to C# programming, so for practice I thought I would try to port a simple haskell function over to Linq. From learn you a haskell, there is the following implementation of powerset: <...
4
votes
1answer
60 views

Content extraction and persistence using Pandoc & Lenses

Endpoints to save a Pandoc document to the database using persistent. Prior to being stored, the code strips out all of the paragraph content (the [Inline]'s) and ...
2
votes
3answers
106 views

Quick sort with a predicate

I want to pass a predicate into quick sort. The issue I'm running into is that the predicate must have two arguments, the pivot and the element of the list's tail. As far as I know though, predicates ...
3
votes
0answers
108 views

Haskell Laplace determinant

I have written a code in Haskell that calculates the determinant of a matrix using the laplace expansion. As I have just started learning Haskell, I would like some opinions on how well (structured) ...
2
votes
2answers
231 views

Primality predicate in Haskell

I wrote a primality test for UniHaskell however, it seems complicated in terms of conditionals. Here it is, rewritten to not use Unicode and other functions in the code: ...
2
votes
1answer
117 views

Haskell merge sort inversions

I'm working on a task from the one of Coursera programming courses. The purpose is to estimate the amount of inversions that are required to sort the array of numbers. Also I'm trying to learn some ...
1
vote
1answer
60 views

Modelling deadlock in cyclic pipelines in Haskell with coroutine libraries

I'm modelling two processes which have been put into a cyclic pipeline - the output of each feeds into the input of the other - so as to work out when they've deadlocked (i.e., neither can progress ...
1
vote
1answer
75 views

Haskell searching through a large textfile efficiently

I have been given a list xs and a function f, and I want to know stuff like how many ...
2
votes
1answer
161 views

Group list of words by occurrence / inverse index of strings

I'm currently working through Coding the matrix, though I'm trying to work through it using Haskell rather than Python. One of the exercises has you write a function where you take a list of strings, ...
6
votes
2answers
242 views

Simple DFA using the State Monad

I've been getting to grips with some Monads in Haskell recently, and to get some practice I plucked a Mealy Machine out of thin air and decided to implement it using the State Monad (it's a simple ...
0
votes
1answer
52 views

Optimized list filtering on implementation of Project Euler 23

I'm new to Haskell, the part of my code I'm concerned with is the isSumAbundant function. Surely there must be a better way, in an imperative language I might use a ...
6
votes
2answers
311 views

Bubble sort with counting swaps and comparsions

I have bubble sort code below, which has to count swaps and comparisons of elements. How can it be made more elegant and clear, if it is possible? I think using lots of tuples is not the best way to ...
0
votes
1answer
62 views

Haskell Servant - login endpoint with two error states

Here is one a handler for dealing with logins, I've recently refactored it to try and make dealing with the different error cases a bit more elegant, though I still think there is room for improvement:...
5
votes
3answers
625 views

Advent of code: day 1

I am learning Haskell, and what is better than advent of code to do so? The day 1 problem is about adding together the digits that are followed by the same digit from a "circular" string (the next of ...
6
votes
2answers
238 views

Disjoint set in Haskell

I think my error-handling here is atrocious, but I'm really new to Haskell so hoping one of you sages can help me out. This program is a command-line tool which you use by typing one of two commands: "...
1
vote
1answer
55 views

Handling multiple IO operations that return optional values

The following Haskell code reads a Pandoc document from the DB and then serves it to the user after making a transformation, after the first run it is stored in memory via ...
3
votes
1answer
167 views

Advent of Code 2017 - day 8 solution

Today I solved the Advent of Code - Day 8 challenge in Haskell. Although the code runs fine and produces the correct results, I'm sure there are lots of improvements to be made, as I am a Haskell ...
12
votes
1answer
128 views

Solving alethic modal logic formulas using truth trees

Disclaimer: this first section is about alethic modal logic and truth trees. It's important to the question but significant parts of the code can probably be reviewed without it. You're welcome to ...
3
votes
2answers
185 views

Segementing a recursive tree in haskell

Could somebody help me work out how to abstract the recursion from this code for me please? I'm trying to write something that takes a pandoc structure, and subdivides the tree whenever it finds a ...
1
vote
1answer
136 views

Bubblesort using Writer monad

I still consider myself a newbie to functional programming, and I still have some trouble wrapping my head around a lot of functional concepts. Anyway, here goes: ...
2
votes
1answer
53 views

Conduit Exercise

conduit offers the following exercise: Write a conduit that consumes a stream of Ints. It takes the first Int from the stream, and then multiplies all subsequent Ints by that number and sends them ...
2
votes
2answers
417 views

Extracting an integer command-line argument and printing a sum of numbers up to that limit

The below code works fine but I have the feeling that there must be something more idiomatic way to do this within the do-notation without having to resort to the ...
3
votes
0answers
186 views

Converting English words to numbers in Haskell

A few weeks ago, I finished a number to word converter and received an excellent review. It caused me to make several fundamental changes to numToWord, such as ...
2
votes
1answer
92 views

Storing values in an N x N grid

I am trying to write a program to store/display a grid of size N x N with cells containing either a 1 or a 0 in preparation for further computation: ...
4
votes
1answer
147 views

Converting anki-furigana to HTML-furigana without parser libraries

I wrote a converter from anki-style furigana to HTML-style furigana. Eventually I want to do it as a parser, but as a first step I do it without. Furigana is used to write the pronunciation over ...
3
votes
1answer
120 views

Programming Contest - Snuke Festival

Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three ...
7
votes
2answers
321 views

Simple guessing game in Haskell

Here is a simple Guessing Game I implemented in Haskell ...
12
votes
2answers
526 views

Compute the perimeter of a polygon

This is taken from HackerRank, which I hope is okay. I've been playing around with Haskell and I haven't really been able to find anything that really goes beyond toy examples in terms of how to ...
5
votes
1answer
509 views

A Public and Private Key generator for RSA

I made an RSA encryption public and private key generator and I would like some feedback. In particular, as this is cryptography related I want to know if I have done anything that might be considered ...
7
votes
1answer
883 views

Converting numbers to words in Haskell

Here's a program I wrote to convert numbers into English words using Haskell. ...
5
votes
1answer
198 views

Porting Haskell list comprehensions to Standard ML

Out of curiosity I'm porting the Haskell exercises of Programming in Haskell by Graham Hutton to Standard ML. At the beginning everything seemed pretty similar until I reached list comprehensions: ...
2
votes
1answer
197 views

Haskell todo list

I don't have much experience with Haskell or functional programming, but I wrote a working todo list. My main question is if there's any idiomatic shortcuts I could take and if my code is idiomatic ...
4
votes
2answers
79 views

Polishing partitions - Reimplementing a partitionOn

So I've read an F# question on partitioning a list in F# and wondered whether I could cleanly write the concept down in haskell and if that would help me review the code ... Now I have a haskell ...
2
votes
0answers
161 views

Game of Life in Haskell with Nested Zippers, Comonads, etc

I was trying to implement Game of Life in Haskell. Here is my approach: ...
1
vote
1answer
52 views

Functions that build a path to the model and command files for some tests

I'm currently working in a model-based testing tool. I'm writing some integration tests for it, which require two kind of input: Model files: which contain models to be parsed and run by the tool. ...