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
1
vote
0answers
23 views

AdventofCode 2021: Day 3 Solution

I am beginner to Haskell. Here is my solution to Advent of Code 2021 Day 3. Let me know what you think. I was looking at the transpose function and decided not to use head & tail function. Given ...
1
vote
0answers
20 views

Implementing a correct `let rec in` interpreter in Haskell with `eval` and `sub` semantics

I'm implementing the toy fb-lang from the principles of programming language book. It's a small interpreted language that uses eval(uate) expression function and <...
1
vote
1answer
49 views

Haskell Twitter Thread Follower

I'm learning Haskell and even though I have experience with Functional Programming the Typesystem has been a challenge. I did this yesterday (after like 2 days) and I would like to know whether this ...
5
votes
1answer
78 views

Number to Text converter in Haskell

I've written this code in Haskell to convert a number into its written form. It feels ok but at the same time I feel like it can probably be improved on a lot. I would appreciate help in improving it. ...
3
votes
1answer
73 views

Efficiently calculating perfect powers in Haskell

I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell The number 81 has a special property, a certain power of the ...
3
votes
0answers
145 views

Advent of Code 2021, Day 3 in Haskell

This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal. ...
8
votes
1answer
406 views

Haskell Tic-Tac-Toe (with automation and GUI)

There are already many Tic Tac Toe posts. But as far as I can tell, none of the ones in Haskell are complete with a GUI Here is my implementation with Gloss. Gist Link for convenience ...
3
votes
1answer
207 views

Generate possible combinations by range and length

I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. ['a'..'z']): ...
4
votes
1answer
310 views

Is there a better way to apply a filter over an Either right value?

Suppose you have an IO (Either String (String, [Int])) and you want to filter the [Int]. Let's say we want to use the following ...
4
votes
1answer
247 views

Reading a CSV file using Haskell

I'm reading a CSV using Haskell. I'm not sure if this is the appropriate way to do it. This is what I'm doing: Read rows from a CSV -> return lazy byte string Parse the headers and rows from the ...
1
vote
3answers
68 views

Word frequency finder

Challenge: find the top three most frequently used words in a string. Only imports from the base package are allowed (source: codewars) I'm looking for feedback on (...
4
votes
1answer
83 views

Small combinator parsing library in Haskell

I recently wrote code to parse lambda expressions written in a lisp like format, using a small hand-rolled parsing library. The goal This code was written as a part of this code-golf challenge not as ...
1
vote
1answer
69 views

Finding the argmaximum of a list in Haskell

I've been doing project euler problems in Haskell, and often I've found the need to get the value that gives the maximum of a function. For example, ...
4
votes
1answer
141 views

Breadth first search on trees in Haskell

I'm writing a breadth first search algorithm in Haskell that supports pruning. It is guaranteed that the search will never encounter nodes that have been visited before, so I implemented the search as ...
4
votes
1answer
171 views

Minesweeper in haskell

I have recently been learning Haskell, and wrote a minesweeper project as an exercise. Here is link to the project. Basically the code is separated into two parts, the pure part (no monads) and impure ...
1
vote
1answer
44 views

Build a fixed-length vector from a recursive factory function

I need a function of type forall (n :: Nat). RandomGen q => q -> Vec n q. Obviously this is possible to do (correctly, don't just ...
1
vote
1answer
43 views

Suggestions on making this parsing/unparsing format more human-friendly

I am working on some application which involves regular expressions with counting. Also, these regular expressions are not necessarily over some fixed alphabet, but over some class of predicates over ...
4
votes
1answer
98 views

Haskell - Convert an Image to Ascii Art

I'm currently learning haskell, and I wanted a simple project to get started. This project uses the JuicyPixels package to handle image reading. The logic of the image to ascii art algorithm is quite ...
3
votes
2answers
244 views

Parsing custom text file using haskell

I am working on writing code for find difference between two text files that should be ideally same. the format of file is ...
1
vote
1answer
51 views

State monad and pattern matching on data constructors

I am writing a Settlers of Catan server in Haskell for fun. Currently I am passing around state manually. I want to learn more about the State monad and want to incorporate it into my project. However,...
3
votes
2answers
103 views

Haskell Function to get the List representation of an Integral

This is a simple practice problem. The task is to write a function getLR that receives an Integral, ...
1
vote
1answer
52 views

Find circles for `f(z, c) = z ^ 2 + c` of length 6 in rational numbers

I've found pretty simple problem on Numberphiles channel: suppose we have a recursive function $$ \begin{equation} \begin{split} f_0 &= Z ^ 2+ C \\ f_i &= f_{i-1}^2 + C \; | \; i = 1 \dots \...
1
vote
1answer
43 views

Equivalent partition sums

I'm looking for feedback on my solution to the following prompt: Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements ...
1
vote
1answer
80 views

Fuzzy Finding in Haskell

In learning haskell, I'm writing a fuzzy menu. At the moment, my executable reads in a 'dictionary' from stdin, and ranks each word according to how well it fuzzily matches a search pattern given in ...
1
vote
0answers
39 views

Count number of days within each date range in a list of date ranges

Happily picked up Haskell a couple days back and working on the following use case. Given a list of JSON objects with date fields and a start date, I want to create a list of weeks (here a tuple of ...
3
votes
1answer
65 views

Haskell implementation of Needleman-Wunsch

The code below is a Haskell implementation of Needleman-Wunsch algorithm for sequence alignment (and string edit distance). It's an experiment in trying to closely imitate the dynamic programming ...
6
votes
2answers
1k views

Hamming distance between two strings

I wrote this module to find the Hamming distance between two strings. (It's a problem from exercism.io's Haskell track.) As I saw it, the problem has two distinct ...
2
votes
2answers
169 views

How can I make a shorter binary rule in haskell?

Here is a code I experimented with recently: let br = [0]:[n:(concat $ take n br) | n <- [1..]] in concat br This code produces the binary rule ...
1
vote
1answer
41 views

Haskell program with basic CLI parsing, file reading, and decoding file contents into specified types

I recently completed the following exercise, but wanted some feedback on how idiomatic etc. my haskell program is. This is from a course which introduces us to file IO before we cover the theory of ...
3
votes
2answers
45 views
6
votes
1answer
142 views

Linear Regression in Haskell

After quite some time away from Haskell I am trying to brush up. To do so I am writing some basic linear regression functionality. The code produces the output expected. In essence I am trying to ...
1
vote
1answer
66 views

Generating the N-bonacci numbers

I'm new to Haskell, and this is one of the more interesting programs I've made with it so far. I understand there are already solutions to this problem that use much less code, but to me this one ...
0
votes
1answer
69 views

Sum of fractions

Objective: Create a function to sum a list of fractions (represented as pairs) Rules Only Prelude functions allowed Notes I was debating if I should create a ...
7
votes
1answer
182 views

A beginner's brainfuck interpreter in Haskell

I am rather new to haskell, and could use some feedback on my code and the decisions I had to make. In my previous project, I made a JSON parser, but relied heavily on guidance from a university ...
0
votes
1answer
123 views

Pairwise summation in Haskell, take two

Here's my second try at pairwise summation in Haskell: ...
2
votes
1answer
129 views

Pairwise summation in Haskell

I'm new to Haskell, and I figured that pairwise summation is something I could do easily. I wrote this: ...
1
vote
1answer
55 views

Changing an element in a list when a predicate holds

My current project is a Settlers of Catan server in Haskell. I often manage to achieve my goals within Haskell, but the code is getting messier as the project grows. My question is about the ...
1
vote
1answer
60 views

Unique elements, long runtime Haskell

I have two functions. Both have to have unique elements, one with Integers and the other a String which returns a list of ...
1
vote
1answer
250 views

Tic Tac Toe (Haskell)

I implemented tic-tac-toe in Haskell. I'm trying to incorporate suggestions from my last question (which mostly revolved around algorithmic logic) while trying something new - IO logic. What kind of ...
3
votes
1answer
41 views

Haskell - saving content of HTTP request in selected file

As a Haskell beginner I'm currently playing around the IO monad and prepared simple program which gets from the user two information: URL (http) Output file path Then it performs ...
2
votes
1answer
64 views

Haskell maxheapify

I'm a Haskell beginner and trying to hone my skill by solving algorithmic problems. Here's what I got for maxheapify from ...
4
votes
2answers
265 views

Connect-Four winner-checking algorithm

I'm trying to practice some functional techniques. I haven't worked much in Haskell, so any language-specific tips would be very appreciated, but what I care for even more are general tips towards my ...
2
votes
1answer
62 views

Haskell Dynamic Programming on a Tree

Here is my shot at Homework 8 of CIS-194 (from Spring '13). The problem is about a hierarchy of employees at a company (a tree), each node being of type Employee, ...
1
vote
1answer
106 views

String tokenizer

Objective: Create a function called wordsAndSpaces that splits a string on groups of spaces, preserving each group of space characters as a single token. Example: <...
3
votes
1answer
44 views

Text replacement with Räubersprache ("Røversprog")

I've been toying with Haskell again and implementing a simple text replacement program that replaces all consonants c in a text by coc, i.e., inserting an 'o' in between: ...
5
votes
1answer
104 views

Two player random number guessing game

I've created a two-player number guessing game in Haskell. My main objective was to practice dealing with "state" in a purely functional language (such as player scores, whose turn it is, ...
2
votes
0answers
75 views

Partial Function composability in Haskell

Below is my solution for the CTFP chapter 4 challenges which essentially involves composing partial functions (that don't have defined outputs for all possible inputs i.e. returning a Maybe). The ...
1
vote
1answer
90 views

"Sequence full of colors" challenge on HackerRank

This is the challenge: You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the ...
2
votes
1answer
68 views

Can this parser (concerning about infinite hierarchy of operators) be implemented purely in ReadPrec?

In Haskell, I tried to implement a parser for expressions containing hyperoperations, and finally succeeded. Valid expressions shall contain: Parentheses. Nonnegative integers. Addition represented ...
2
votes
0answers
118 views

Custom HTML parser in Haskell

For the last couple of months, I have started to learn Haskell and since I am following a course on functional programming soon, I thought I would test my current skills. So what I did was create an ...

1
2 3 4 5
22