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
-3
votes
1answer
394 views
5
votes
1answer
164 views

Euler 1 but pointless

I've been teaching myself basic haskell this week in order to be able to better read literature about functional programming (about 80% of which in haskell by my completely off-the-cuff statistic). ...
3
votes
0answers
168 views

Sudoku solver in Haskell using Reader+ST

While trying to understand monad transformers in Haskell I came up with a sudoku solver based on a combination of the ST and Reader monad. I am positively surprised with the performance, however ...
0
votes
3answers
387 views

All possible combinations of colors for Mastermind

Just started out with CIS 194 on Haskell and wonder what the more idiomatic way to solve this problem would have been. This code is supposed to generate all possible combinations of 6 given colors up ...
6
votes
1answer
181 views

CIS 194 Homework 2: Parsing an error log

Here is another reference solution, that I discovered after writing my own: https://insight.io/github.com/beloglazov/haskell-course/blob/HEAD/hw2.hs I am following this lecture course as a ...
0
votes
1answer
41 views

Foldr code snippet

The function traverse takes an element and a map, and returns another element and a new (updated) map. Given a list of elements ...
4
votes
2answers
730 views

Leap year check in Haskell, using pattern matching or bind operator

One of the first Haskell puzzles on http://exercism.io/ is to implement a leap year check. I've done this twice. Using pattern matching: ...
3
votes
1answer
136 views

Parsing n lines to count vowels - HackerEarth

I have written a haskell program for the following 'Code Monk' Challenge at HackerEarth. Here is the challenge description. Basically, we are looking for the number of vowels in a string. The first ...
4
votes
1answer
208 views

Vigenere Cipher - Haskell Implementation

I'm reading 'Haskell Programming from First Principles' book written by Christopher Allen and Julie Moronuki. As part of the exercises, I'm supposed to implement encryption and decryption functions ...
4
votes
2answers
114 views

Next lexicographic permutation of a list

I began learning Haskell last week. I wrote the following to get the next lexicographic permutation of a list. It works perfectly but I feel like I'm just writing a c# method. My long list of where ...
0
votes
1answer
308 views

Reinforcement learning example (chap. 1) from Sutton's book

I ported the Lisp Tic Tac Toe code from Chapter 1. to Haskell. The original code repo is down for some reason. I believe I have completely rewritten that in Haskell (Less functional than one would ...
7
votes
1answer
958 views

Haskell Text-Adventure Game

I just started making a text adventure game in Haskell. Because this is the largest project I have done in Haskell, I wanted to ask about it here before I got too far on it. I am still pretty new to ...
3
votes
1answer
186 views

Caesar and Vigenère ciphers in Haskell, Take 2 (not so simple this time)

I've posted my simple ciphers on Code Review several days ago (link: here). I refactored my code and tried to define a more general "cipher" function, according to Zeta's excellent advice. I've split ...
2
votes
1answer
195 views

Angle type in Haskell

I wanted to create a type or class, which can be used to handle angles. I started with defining a class, to make it possible to store degrees in Integral, radians in Floating, etc... But I realized, ...
3
votes
1answer
83 views

Conversion of Haskell CBOR decoding code into Rust

I was interested in converting the following Haskell code, that does decoding of CBOR into Rust: ...
5
votes
1answer
265 views

Caesar and Vigenère ciphers in Haskell the simple way

There are two ciphers, Caesar and Vigenère, both with an encoder and a decoder. Both work with spaces and can be passed any case (the output will be always lowercased, though). I'm a complete Haskell ...
1
vote
0answers
76 views

One-off string detection

Problem spec from CareerCup. Given two strings, return boolean True/False if they are only one edit apart. Edit can be insert/delete/update of only one character in the string. Eg. True xyz,xz xyz,...
-1
votes
1answer
66 views

Unbalanced Parenthesis correction

I'm prepping for a coding interview, and am examining the task of correcting unbalanced parentheses. The finger tree seems to be the right data structure. As a proof of concept I've used ...
6
votes
1answer
2k views

String splitting function in Haskell

I need to write a function which selects a run of repeated characters from the start of a string, with the run comprising at most nine characters. ...
5
votes
1answer
2k views

Binary Search in Haskell

I have been trying to pick Haskell back up so I decided to try to implement binary search as practice. I am aware that binary search in Haskell in inefficient because Haskell's lists are implemented ...
3
votes
2answers
98 views

Monadic transformation on a list, done in three ways

I am working my way through the Haskell Book and ran into the exercises at the end of the Monad chapter(18). One in particular asked to define a function with the following signature: ...
7
votes
2answers
190 views

A port of a simple logger

I'm looking at porting a simple logger I wrote a while back in Python to a language which would result in less runtime overhead from logging. As an informal benchmark, I try to log a message, ...
5
votes
2answers
126 views

Simple Prefix Matching Library in Haskell

For some context, I'm trying to write a streaming tokenizer in Haskell and noticed that I was writing a lot of functions with the type signature ...
3
votes
2answers
71 views

Static web server with a bit of error handling

I am looking for a review on this code, which is a simple static web server, with a small bit of error handling. It's feeling a bit "messy" / "imperative" at the moment, so advice would be welcome. <...
3
votes
1answer
65 views

Ricochet Challenge: Robust IO and working with different types of numbers in Haskell

Background I've tried to solve /r/DailyProgrammer Challenge #303 [Easy]: Ricochet (summarised below) in Haskell. The code below is now the second Haskell script I've ever written, so I'd consider ...
2
votes
0answers
65 views

Genetic operators in Haskell

I have implemented two genetic operators, which is really just a fancy way of mangling lists. In particular OX-1 (illustration) and displacement mutation. I found it necessary to extract out the ...
4
votes
2answers
137 views

Pearson Correlation in Haskell

As an exercise to help me learn Haskell, I decided to write a small "program" to find the Pearson Correlation Coefficient for 2 lists of numbers. I'm pretty unhappy with how it turned out, because I ...
3
votes
0answers
79 views

Flexible port scanner library

I have tried to generalize the concept of turning an IP address into a boolean. The save format is an overly complicated way of storing consecutive IP addresses as strings of bits Example usage: <...
15
votes
1answer
2k views

Execute a function n times, where n is known at compile time

Motivation In this question, a user asked whether it is possible to inline the following function: ...
4
votes
2answers
212 views

Find two numbers in a sorted array whose sum is closest to a given number

Given a sorted array and a number x, find a pair in array whose sum is closest to x. Here's my solution: ...
3
votes
2answers
89 views

Taking change - convergent iteration through iterate

For the Code Review community challenge "Implement StackSTV", the algorithm requires a "convergent iterative scheme" to calculate the keep ratios of candidates that have been elected. To simplify the ...
1
vote
1answer
179 views

Project Euler problem 2 in Haskell

I have just started Haskell, and I want to check if my code is following the spirit of the language. By considering the terms in the Fibonacci sequence whose values do not exceed four million, find ...
1
vote
0answers
144 views

Haskell ERP (API Backend)

I'm building a mini ERP, with some basic functionalities, I'm doing the Back End in Haskell. However, my code feels very imperative, so any tips and critiques will be highly appreciated. Repo: https:/...
2
votes
1answer
346 views

Haskell REST API + PostgreSQL

I'm making some small REST API, which I have never done before. I've got some basic stuff working. Now my job is to add new entities to this, but all my work is reduced to copy-pasting code I have ...
2
votes
1answer
76 views

HashCash Algorithm header generation in Haskell

A thought exercise on my part as I'm relatively new to Haskell. I wanted an interesting project to work on so I decided to implement the Hashcash Algorithm, which is most commonly used as the basis of ...
0
votes
1answer
3k views

Producing all possible combinations of a list

I've written a function that produces all combinations of elements in a given list: ...
2
votes
0answers
169 views

Locally encrypt/decrypt credentials

I wrote some code to encrypt and decrypt some user credentials for services that a locally run application needs to work. I get a password from the user, use it to stretch a key via Scrypt, and then ...
0
votes
2answers
438 views

Are nested fmap calls idiomatic Haskell? [closed]

Given: *Main> :t text text :: (Selectable s, StringLike str, Ord str) => s -> Scraper str str I need to perform "second level" ...
2
votes
1answer
67 views

Re-implementing basic list operations

I'm re-implementing the common core functions that work on list as a learning exercise. I'm new to Haskell and often find myself staring at what I've written trying to determine the simpler or more ...
3
votes
1answer
153 views

Haskell command line todo list

I've implemented a command line todo list in Haskell. I've run hlint and build with -Wall, but is there anything else I can ...
1
vote
1answer
117 views

Handling multiple dimensions of arrays with speed

I'm looking to learn how to write efficient Haskell code. This snippet works, but the run time is slow. How can I write faster Haskell code? Input: maxPrice = 7 ...
6
votes
1answer
5k views

Filter Duplicate Elements in Haskell

I'm working on HackerRank to try to improve my Haskell skills along side with reading Haskell Programming from first principles. I wrote a program that works, but it seems to time out on large input ...
6
votes
1answer
162 views

Generating smooth numbers in Haskell

I wrote a smooth function that returns a list of all smooth numbers below a certain limit from a list of prime: ...
1
vote
1answer
82 views

List comprehension for 7x7 board

I have a 7x7 board and I want to select some elements from it. The elements I want to select are marked o, the other ones are marked ...
5
votes
1answer
106 views

D-flop with enable and clear, translated from VHDL to Haskell

I am in the process of translating an implementation of dflop_en_clr from VHDL to Haskell: ...
1
vote
1answer
86 views

A push style parser combinator in Haskell

Usually, parser combinators in Haskell based on the parser type like newtype Parser t r = Parser ([t] -> [(r,[t])]) This allows back tracking and multiple ...
6
votes
1answer
387 views

Shortest Path (BFS) through a maze

Background I have decided to use this year's Advent Of Code to learn Haskell. I feel like I vaguely understand the language and can solve most of the problems with relative ease. However, the code I ...
5
votes
1answer
89 views

Pandoc filter to allow embedding arbitary HTML in latex documents

I wrote a Pandoc filter that allows me to embed arbitrary HTML snippets in LaTeX documents, which are then printed out as-is when the document is converted to HTML. It is slightly more generic than it ...
5
votes
2answers
182 views

Transform a Japanese word to furigana

I developed a script to transform a Japanese word in Furigana thanks to the jisho website. But the code is very ugly, especially the extractHiraganaFromHTML and <...
3
votes
1answer
107 views

An attempt at a Haskell Servant API - repetition of Left/Right case matching

I'm attempting to learn more about Haskell by completing a "hobby" project - a simple API to save/retrieve content for pages - used with Hakyll to generate static sites. I have got something working ...