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.
1
vote
1answer
19 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
101 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
33 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 ...
3
votes
1answer
32 views
Encoding text to keypresses on old phone keyboard (0-9*#)
I am going through "Haskell Programming from first principles" for the first time and I would like to get some pointers on what can be improved in my code, which is the following:
...
4
votes
1answer
68 views
Yet another FizzBuzz in Haskell
Time for the most original question of the year: writing a FizzBuzz in Haskell!
So here is what I came up with:
...
1
vote
3answers
77 views
Select a list from a 2D list, take the last item from its nearest non empty left neighbour and put it at its head
I've just got into Haskell a few days ago and I love it. I'm looking for some pointers and best practices on how to organise and write Haskell code specifically when it comes to managing errors, which ...
4
votes
2answers
65 views
Caesar Shift in Haskell
I started learning Haskell a couple of days ago and decided to build a Caesar shift in it.
...
6
votes
1answer
61 views
Vigenere cipher in Haskell
I implemented vignere cipher in haskell as a part of exercises for haskell programming from first principles.
Though the code isn't all that long, I feel it could use some refactoring to simplify ...
3
votes
1answer
40 views
Kattis, Speed limit; read irregular input
I am able to solve this challenge but when look at my code I know it is not good.
The challenge:
Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don’t know ...
6
votes
2answers
67 views
Generating double linear sequence in Haskell
Need some comments on making the below code more effective. I'm pretty new to Haskell.
The sequence in generateSeq is generated by the rule that if ...
5
votes
2answers
130 views
Calculating the count of integer partitions of a number (uses stateful vectors internally)
I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem:
$$P(n) = ...
4
votes
1answer
45 views
HackerRank Ransom Note, solved using Data.Map as a hash table
I try to solve this hackerrank using Haskell but not sure if I use Data.Map corretly.
Problem in brief:
given 2 strings, magazine and ...
6
votes
2answers
60 views
Repeat an action for a set of elements until all succeed, or progression halts
Context
I'm trying to write a function that drops a list of tables from a database (e.g., tables A, B and C).
This function has the following type, it returns a list of booleans indicating whether ...
3
votes
1answer
41 views
Mad Libs using recursive IO for user input
I'm writing my first small programs in Haskell and still getting a feel for the syntax and idioms. I've written this Mad Libs implementation using recursive IO. I've used IO actions throughout and I'm ...
2
votes
1answer
83 views
Text-based menu to manipulate a database text file
I am making a program that lets a user manipulate a database (a text file).
In the code I am posting, I show only 2 of the menu choices, namely "createdb" and "deletedb", and a few functions I made ...
4
votes
1answer
19 views
Interpreting database values as times and integers
I am working through Chapter 10 of Haskell Programming from First Principles.
I've gotten the code to work, but I am uneasy about the fact that a few of my functions - namely, ...
3
votes
2answers
51 views
Scanl expressed as fold
Inspired by the learn you a haskell exercise to express map with fold I wrote an implementation of scanl by means of a fold.
...
0
votes
1answer
32 views
Haskell insertAt solutions
I was working on Haskell Problem 21:
Insert an element at a given position into a list.
Example:
* (insert-at 'alfa '(a b c d) 2)
(A ALFA B C D)
I have ...
2
votes
0answers
59 views
Naive implementation of Naive Bayes in Haskell
A simple implementation of Naive Bayes, as I'm a Haskell beginner I've tried to put an emphasis on clarity and documentation. I've tried to incorporate the feedback from a similar question. This is ...
7
votes
1answer
192 views
Haskell code to verify credit number
I am new to Haskell, and wrote a script to verify credit number.
I did some tests, the script worked, but can it be improved further?
...
1
vote
1answer
45 views
Project Euler #45 in Haskell
I've got a solution for Project Euler's problem 45.
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
$$\begin{array}{lll}
\textrm{Triangle} & T_n=n(n+...
5
votes
2answers
130 views
Imperative Sieve of Eratosthenes using destructive updates in Haskell
I've implemented the prime sieve of Eratosthenes in Haskell using a mutable array of unboxed Bools instead of the usual pure and immutable datastructures.
My main concern with this code is speed. For ...
3
votes
2answers
89 views
Count numbers whose digits are only increasing or decreasing
The goal is described here: basically, it is to compute the number of numbers below \$10^n\$ such that its digits are either increasing or decreasing (like 112 or 211, but not like 121).
The original ...
1
vote
1answer
56 views
Logical contradiction type definitions
(Homework alert)
Working my way through "The Haskell Road...", not sure about my solution to exercise 2.15 on page 48 of the second edition:
A propositional contradiction is a formula that yields ...
4
votes
2answers
97 views
Large Power Mod - Extreme Efficiency
I've implemented my own 'power-mod' procedure which will compute a^b 'mod' n for some large b and even larger ...
4
votes
1answer
109 views
Calculating a circle with bezier curves
I am new to Haskell, and have been reading Learn You a Haskell for Great Good!.
I've rewritten a problem that I recently solved in JavaScript in Haskell to practice what I have been reading.
A ...
5
votes
1answer
59 views
Using monads and monad transformers (simple matching engine)
Like most of the folks here, I'm learning Haskell, so I figured an interesting exercise would be to build a matching engine that I could use to build a financial exchange. I'm wondering primarily if I ...
1
vote
0answers
54 views
1
vote
3answers
80 views
Haskell function to format a floating-point number with some precision
I have not yet developed a satisfying coding style in Haskell. In the code snippet below, there is a lot wrong to my taste:
Helper functions which should be local to ...
2
votes
1answer
60 views
Efficient Prime Sieve - Haskell
I'm new to Haskell, and am trying to learn the basics with a simple function that will calculate the list of primes up to a given value (using the Sieve of Eratosthenes). Here is my code so far, which ...
1
vote
1answer
34 views
Inefficient Parsec parser to skip unreachable block
In a parser written with Parsec 3.1.11, I have a performance issue with parsing (or better, skipping) the unreachable branch of a if-then-else statement.
The syntax to be parsed is as follows:
...
1
vote
2answers
139 views
Key phone in Haskell
Here is my solution for an exercise, which requires translation of strings to key presses on a phone keypad (for example, to get 'b' the digit '2' needs to be pressed twice).
It's taken from the book ...
5
votes
0answers
40 views
Haskell tool for find @SuppressWarnings in Java source code
I put together a little tool for finding where people have suppressed warnings, and to see if they have commented why. Its in Haskell for fun and some practice. Its split into two files, the thinking ...
8
votes
3answers
103 views
A guarded FizzBuzz
Vogel612 and I decided to take a shot at the StackSTV challenge in Haskell. This is part of the CRitter Collaboration challenge. Except I don't know any Haskell. So let's try a FizzBuzz first!
I'm ...
2
votes
1answer
31 views
Basic number property checker
I made a small program that tests numbers against some properties:
Welcome to Numbers!
Is it odd? 4
No
Is it a multiple of 18? 38
No
Is it big? 100
Yes
That's basically it :)
My code is:
...
3
votes
1answer
47 views
Factorials and Powers calculator
I just started learning Haskell, and I made a simple program which can calculate factorials and powers:
Input:
What do you want to do (0=quit, 1=factorial, 2=power) 1
Enter a number: 10
The ...
2
votes
0answers
117 views
Lambda calculus interpreter in Haskell
This code is a representation of lambda calculus using an AST instead of text.
...
4
votes
1answer
549 views
Count occurrences of an element in a list
I've been learning Haskell from LYAH for quite some time, and as a first practice for Chapter 7: Modules, I decided to make a simple numTimesFound function: it ...
2
votes
1answer
64 views
Overly complicated parser combinator
I recently started to learn Haskell in order to write some small tools for me. Currently I'm working on a program which calculates how much steam a (railcraft) boiler of a given size outputs per tick.
...
3
votes
2answers
50 views
Haskell Arithmetic Quiz
I'm currently learning Haskell, and as one of my first "proper" programs have created a mathematics quiz. It works like this:
A question is generated, with two numbers from 1 to 10 which need to be ...
2
votes
3answers
56 views
CodeAbbey #21 Array Counters
I'm trying to learn some Haskell by working my way through the CodeAbbey problems. I really struggled to find a nice functional (but still efficient) way to solve problem #21: Array Counters.
The ...
4
votes
3answers
56 views
Textbased User Interface for user and program taking turns
I wrote this program to model interactions between a user and an artificial player, both playing by the same rules (not enforced here for simplicity).
The game played is here is "your next word has to ...
1
vote
2answers
54 views
Small haskell text-processing script
I'm a bioinformatician and mainly use python, but I'm trying to learn Haskell. So far I like this language because it's beautiful and fun, but my Haskell scripts usually end up being much slower than ...
3
votes
1answer
42 views
“Log in”, extract number from a map, increment it, and log out
Basically, you just run main and it allows the client to "log in", and extract their number from a map, increment their own number, and log out.
It all compiles ...
1
vote
1answer
53 views
Encoding and decoding in Haskell — 99 Problems exercise 13, 14
I've been working on these solutions to the Haskell 99 questions, encoding and decoding series for a while now, so I figured I ought to present them to see how I screwed up the implementation.
...
9
votes
1answer
294 views
Neural Network in Haskell
Following this website I wrote a neural network which uses the MNIST training data to recognize digits. The author writes that it should take a couple of minutes to train the network with 30 epochs of ...
3
votes
1answer
77 views
Haskell Parsec parser of Verilog-style number literals
I've set myself the task to write a function that parses Verilog-style number literals. In Verilog, numbers are written like this:
8'b10101100, ...
4
votes
2answers
105 views
Number Guessing Game in Haskell
I've been learning a lot about functional programming lately and I've recently started learning Haskell to which I'm very new.
I've written a simple number guessing game and I would like to have ...
3
votes
2answers
46 views
Finding Permutations in Haskell
I wrote a function to find all the possible permutations of a list in Haskell. I know it can definitely be optimized, but I'm not sure how. I'm pretty sure foldl or ...
4
votes
1answer
56 views
Implementation of Point, Velocity and Acceleration in Haskell
I'm trying to implement point, velocity and acceleration types.
They should be connected by some derive function which:
takes time and velocity and returns a ...