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
1k views

mapM for both keys and values of Data.Map

I'm writing a monadic parser instance that transforms Data.Map.Map's: ...
8
votes
2answers
864 views

Generating a tabula recta

I want an experienced Haskeller to critique my code and offer changes/suggestions (so I can learn the idioms of the language and culture around Haskell). I've been using a Tabula Recta for my ...
4
votes
2answers
960 views

Writing an infinitely running( while(true) { } ) user input function in haskell

I'm trying to implement a lexer in Haskell. For easy console input and output, I've used an intermediate data type Transition Table. ...
3
votes
1answer
253 views

Reading a data file for performing a FFT

I'm a bit concerned about function usage. There are so many different libraries/possible ways to do something that I'm not sure if the way I'm working at the moment is reasonable, or what I could ...
2
votes
3answers
1k views

Poker Hand Kata

Similar to, but distinct from Poker hand identifier. I'm working towards solving this kata. The below code doesn't print the result yet, and it reads hand strings rather than game strings. Take 4: <...
2
votes
1answer
321 views

“Unfriendly Number” challenge

I tried to solve the Unfriendly Number problem on InterviewStreet: There is one friendly number, K, and N unfriendly numbers. We want to find how many numbers are there which exactly divide the ...
5
votes
1answer
209 views

Improving General Algebraic DataType type-safe code for AA trees

As an exercise on GADTs I wrote a type-safe implementation of AA trees. I'm quite happy that the AANode data type correctly grasps the properties of the tree. Just ...
5
votes
1answer
298 views

Rewrite of Sokoban using State

I watched this live coding of Sokoban in Haskell and thought I'd take a crack at writing it using State and lenses, since I've never tried that before. My problem is that the control flow seems to be ...
2
votes
1answer
199 views

Using a compiler specified on the command line or automatically detected

Here is part of my build system. ...
3
votes
2answers
269 views

Simple quotes app

I created simple app that read ~ delimited txt file, convert it to [String] and display quotes on screen. How would you improve ...
4
votes
2answers
395 views

Calculating sun rise/set time at various places on Earth

This is the algorithm for calculating sun rise/set time at various places on Earth. I took it as an example of multiple functions inside of one top function. This is Ver 0.3: ...
3
votes
1answer
335 views

Finding the biggest product of two integers formed by the digits 1-9

The question was, which is the biggest product you can make from the digits of 1 to 9 (which is 9642*87531, BTW). It is pretty clear that one number starts with 9 and the other with 8, and that you ...
9
votes
1answer
220 views

Redundant `let`s in list monadic code [closed]

There is a function with bunch of a redundant lets and s inside a list monad. ...
5
votes
1answer
301 views

Kalaha Solver: finding the marbles

As with my other question this is regarding my Kalaha solver. Currently the way I find out the optimal progression of moves is with a command like this: ...
4
votes
1answer
208 views

How to avoid big tuple return types?

I recently got serious about learning Haskell and upon finishing chapter 4 in Real World Haskell, I decided to try out my accumulated knowledge on a project of my own. This code hosted on github is a ...
10
votes
2answers
350 views

Artifact collision in plane module

Here's something I tried putting together as I'm learning. Critiques on anything are welcome. There's also a logic bug in the Plane module I can't identify. The long and the short are that it takes ...
4
votes
3answers
1k views

Simple Gradient Descent Algorithm In Haskell

After becoming interested in various bits of functional programming provided by non-functional languages, I've recently decided to start learning Haskell. As I'm fairly experienced with conventional ...
3
votes
1answer
149 views

Can I use mapWriterT instead of mapM/mapM_ (Haskell)?

First off, I'm just learning Haskell and I'm not proficient in that language yet. I wrote this Haskell module to look for files in a Linux filesystem. It can use regular expressions as search ...
2
votes
1answer
895 views

Language parser in haskell

This is a recursive descent parser for simple language with following grammar: PROGRAM <- {STATEMENT ';'}* RETURN_STMT ';' STATEMENT <- NAME_BINDING | TYPE_DECLARATION TYPE_DECLARATION <- ...
1
vote
2answers
1k views

Haskell: rndFile and [Char] vs IO String error

...
4
votes
1answer
345 views

Dynamic IP-address logging

Inspired by Don Stewart's article on Scripting with Haskell I tried a rewrite of a shell-script I did the other day. I was really astonished how easily it worked but as a whole it is about double the ...
3
votes
1answer
193 views

Haskell recursions, level zero

As a learning process I created 'reverse' function in a few different ways. Tinkering with 'reverse' made currying, folds and other stuff easier to understand. Almost natural! I know these are ...
10
votes
2answers
611 views

Naive Bayes classifier

I just started learning Haskell, and I must say it is unlike anything else. As my first not-entirely-trivial piece of code I tried to write a simple Bayes Classifier. It is in two parts, a classifier ...
4
votes
2answers
2k views

Poker hand identifier

Inspired by this post (along with a number of other people by the looks of it), I created a poker hand identifier with a very similar format. Note that the syntax of the hands is a little different to ...
2
votes
2answers
737 views

Haskell function to explode a list

I've written the following explode function using break. The intended behavior is, that a list is divided into sublists by a ...
1
vote
1answer
615 views

Search Function With Wildcard in Haskell

I'm teaching myself how to program Haskell, and I decided to make a find function in Haskell. What it does is it takes two strings, such as "hello" and ...
6
votes
1answer
172 views

Representing a Java Swing containment hierarchy in Haskell

A Java desktop application exposes the class/containment hierarchy of its Swing GUI through RPC. I'm building a Haskell client that connects to the application. The objective is to be able to perform ...
9
votes
1answer
743 views

Brainfuck Interpreter

I want to write an example for a language similar to Haskell called Frege. While the interpreter is conceptually easy, it is lengthy and looks still quite messy. Note that I don't want to use Parsec ...
26
votes
1answer
1k views

How can I make my stack monad faster?

I made a stack monad that lets one manipulate and control values on a stack. I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without ...
8
votes
1answer
288 views

Computing a Discrete Cosine Transform matrix

I'm learning Haskell and I needed to work with discrete cosine transform matrices, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix. The elements of ...
4
votes
1answer
901 views

Longest non-decreasing subsequence, in Haskell

OK, so I recently posted this solution in Python to the longest non-decreasing subsequence problem, and cleaned it up with some expert advice. As a next step, I wanted to translate this solution into ...
7
votes
1answer
281 views

Periodically comparing the play count of two Last.FM users

There is some little program (using a Last.FM API wrapper) which gets the play count of 2 specific users every 5 minutes and appends the difference between these 2 numbers to log file. Can you review ...
3
votes
1answer
1k views

The game of life with a truly infinite board

The game of life is often implemented by representing the board as a 2D boolean array. This doesn't scale very well to larger boards -- it starts to consume lots of memory, and without some separate ...
41
votes
1answer
2k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
2
votes
1answer
376 views

How to make following CFD program more idiomatic?

Basically, I'm comparably new to Haskell, which means lacking both knowledge of advanced principles, available libraries and, maybe, some syntax. For educational purposes I hacked together a code ...
5
votes
1answer
499 views

Optimizing ByteString escaping

I wrote a string escaping function in C, and I'm trying to rewrite it to Haskell. The C version, along with comments explaining why it does what it does, can be found on GitHub. Here's a naïve ...
4
votes
1answer
757 views

Reversi (Othello) game engine + command line interface

I have written a game engine for the game Reversi, also called Othello. The game engine works not exactly like the official rules. For example it is possible to place "holes" on the board, places ...
7
votes
2answers
334 views

“Ringing in the New Year (2011→ 2012)” puzzle

I am trying to solve the puzzle RINGING IN THE NEW YEAR. Start at 2011. By moving through the maze and doing any arithmetic operations you encounter, exit the maze with a result of 2012. You may ...
2
votes
2answers
2k views

Sudoku solver in Haskell

I tried to implement a naive brute-force Sudoku solver in Haskell (I know there are loads of good solutions already) and I'd like some reviews from you experts. The solver is very simple and it uses ...
2
votes
1answer
138 views

Haskell: Draw tabulated data given header and rows as lists

I need to draw tabulated data given a header as list and rows as list of lists This is what I came up with. I wouldn't say that I like it much. Could you please have a look if it can be done better (I ...
4
votes
1answer
695 views

Simple Haskell key value file store

As an exercise in learning Haskell, I implemented a simple key value store, where you can put and get values (as ByteStrings). (For reference this is inspired by ...
2
votes
1answer
199 views

(Ab)using scanl to generate a random number stream, is there a better way?

Here is my code to do it: ...
7
votes
2answers
2k views

My Haskell word count program

Here's my first significant Haskell program - it presents a count of each word seen on stdin. Any comments are welcome. ...
5
votes
1answer
1k views

Simple TCP client - memory issues

Does this snippet take too much memory? How can I let the connection opened with the function connectTo outside the forever loop? ...
3
votes
1answer
401 views

“Intelligent” removal of carriage returns that preserves paragraph breaks, headings, etc

It's often useful to strip carriage returns out of a plain text document, for example when copying and pasting into a field that automatically wraps lines. However, it's usually a good idea to leave ...
5
votes
1answer
145 views

Safety, sharing, and laziness

Is there a more succinct way to write code like this that has a lot of sharing between branches of the case statement? (This is the main part of my solution to one of the Round 1 problems of the ...
16
votes
2answers
988 views

Recursive directory tree printer

I wrote this program that recursively prints all the files and directories starting at the current directory: ...
4
votes
2answers
2k views

Multiplication table using a list comprehension

I have just started reading through Learn you a Haskell I got up to list comprehension and started to play around in GHCi, my aim was to make a times table function that takes a number ...
6
votes
1answer
374 views

Turning Conduits into Pipes

Does this look right to you? What are its shortcomings? Strengths? ...
8
votes
4answers
679 views

Printing a factorial from an integer

I am very new to functional programming. I wrote this program where the user can enter an integer and it will print the factorial. If the user enters a negative integer or not an integer at all, it'll ...