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.

learn more… | top users | synonyms

4
votes
1answer
36 views

Simple prefix tree

I've written a simple function for building a prefix tree (and searching): import qualified Data.List as L import qualified Data.Map as M data Tree a = Empty | Node a [Tree a] deriving (Show, Eq) ...
2
votes
1answer
36 views

Rearrange content string

From https://www.codeeval.com/browse/115/: You have a string of words and digits divided by comma. Write a program which separates words with digits. You shouldn't change the order elements. I ...
4
votes
0answers
615 views

Performance of List representation of MonadPlus versus Tree representation

I am working on a code where I represent a MonadPlus using a Tree data structure and then explore it, summing over all of the leaves (whose type must be an instance of Monoid); I need to use a Tree ...
1
vote
3answers
17 views

How to simplify the record syntax with pattern matching?

I've just finished reading Learn You a Haskell and I've started to experiment on my own. I just wanted to create a very simple game system where player A can attack player B. Now I have 2 questions: ...
0
votes
0answers
62 views

Optimizing my Quadratic Sieve, with advice on style?

I'm still new to Haskell, and I'd like others' opinions on optimizing my basic quadratic sieve, in addition to feedback on the code's clarity and functional style. The qs function currently runs out ...
1
vote
0answers
39 views

Toy Forth interpreter

So I've been reading too much papers and writing too little code. These are my first 300 lines of Haskell: {-# LANGUAGE NoMonomorphismRestriction, TemplateHaskell #-} module Forth where import ...
1
vote
1answer
58 views

Math formulas in Haskell

I wrote some math formulas in Haskell and was wondering about how to clean the code up and make it more readable. import Math.Gamma pdf :: Double -> Double -> Double -> Double -> Double ...
2
votes
2answers
198 views

Usage of lens for concise update of records

I'm new to Haskell. I'm developing a game-like simulation. I try to use lenses to update the state of the world. Current iteration of code works, but looks clumsy. I am trying to improve it, e.g. I ...
3
votes
0answers
84 views

Automata theory, state reachability in Haskell

I wrote a small library to learn Haskell while studying Automata theory. I have some concerns on my algorithm to evaluate state reachability. That is, I think it might be improved if I can avoid ...
2
votes
2answers
69 views

Haskell grep simplification

I am new in haskell and for start I choosed to write simple grep. Now I want to ask if there is some simplier/shorter way to write it. For example if there is any way to avoid recursion. parseLines ...
2
votes
1answer
61 views

Improve Trie manipulation in Haskell code

I have the following data structure: data XComposeString = XComposeString { keyEvents :: [Event], s :: Result } deriving (Eq, Show) data XComposeFile = XComposeFile { strings :: [XComposeString] } ...
4
votes
0answers
70 views

Mixed Drink Calculator in Haskell

This is a simple mixed drink calculator written in Haskell. There are two input files. The drinks file contains a list of simply formatted recipes for mixed drinks: screwdriver:vodka,orange juice ...
2
votes
1answer
122 views

Graham Scan convex hull algorithm

I'm beginning learning Haskell. I've implemented the Graham Scan algorithm for detection of convex hull following the Real World Haskell book. I'm looking for general advice regarding the style and ...
1
vote
1answer
103 views

Too much IO/State passing around

I've written a vocabulary trainer which does a lot of passing state around, as I have an ACID-database and a temporary state. In my experience with Haskell I've learnt that overusing IO () is a code ...
2
votes
1answer
49 views

Code Review of Haskell PBKDF2

Moved from Programmers.SE. I have written a new version of the PBKDF2 algorithm in Haskell. It passes all of the HMAC-SHA-1 test vectors listed in RFC 6070, but it is not very efficient. How can I ...
0
votes
1answer
92 views

99 Haskell problems, problem 18

The problem is here, the solutions are here. I don't see a solution like mine (maybe the 4th), it seems to work though. -- --------------------------- -- 18 (**) Extract a slice from a list (idx ...
1
vote
1answer
77 views

Hex to ASCII conversion in Haskell

I wrote a simple program in Haskell which takes Hex input from stdin, converts the input to ascii and writes it to stdout. An example use: $ echo -n '48656c6c6f2c2043522e534521' | unhex Hello, CR.SE! ...
2
votes
1answer
56 views

Reading [String] where each item have a different type in Haskell

I have a data structure called ClientSession which I convert to a String separated by | for each element and back to the data structure. 18 data ClientSession = ClientSession ...
1
vote
0answers
55 views

Optimizing AVL tree

As a part of learning Haskell, I've implemented an AVL tree. As of now, I've only implemented insertion. I've compared its performance to a Java implementation I've picked at random ...
4
votes
1answer
65 views

Unix tail in haskell

I am trying to write a simple version of the unix tail utility in haskell to improve my understanding of monads. Here is what I have now. I am pretty sure that this is not quite "Haskell enough" yet. ...
1
vote
0answers
92 views

New to Haskell; Looking for critique of my KenKen solver

I'm new to Haskell and I've made a very short KenKen solver. Any input is welcome. import Data.List import Control.Monad set :: [Int] -> Bool set x = x == nub x mats :: Int -> [[[Int]]] mats ...
3
votes
1answer
97 views

Calculating chromosome coverage of a set of regions

Some background: I work mostly in Python (specifically numpy), doing Bioinformatics type work. I am interested in moving towards Haskell. Initially, I hope it will be possible to replace some of the ...
5
votes
0answers
134 views

A program to proxy MDNS requests to the DNS server

I wrote a program to proxy MDNS requests in local network to the DNS server. This is useful because in some private networks, host names ending in ".local" are configured in the DNS server. But ...
1
vote
0answers
57 views

Implement step function in Haskell

I try to implement a (restricted version of) step function in Haskell. A step functions is a function that is constant on a finite number of half intervals, and mempty everywhere else. (equivalently, ...
1
vote
0answers
95 views

Regular Expression Generator

This library allows you to call functions to describe a regular expression, and then check if a string matches that regex- or replace things in a string based on that regex. I am trying to improve my ...
0
votes
0answers
48 views

Haskell Bencoded Dictionary Parser

I have been working on a Bencoded string parser in order to improve my knowledge of Haskell. After running the code through hlint, I still have a few questions: As I noted in the comments, the key ...
1
vote
1answer
47 views

How can I improve this action?

I have this action and it works but looks rather clunky to me. Is there any way I could improve that? transMit :: Serialize a => Socket -> POSIXTime -> KEY -> a -> TPSQ -> TMap a ...
2
votes
1answer
126 views

How to improve my Haskell code?

I started learning my first functional programming language (Haskell) yesterday and I have been working on a lexer for an expression evaluator. The lexer is now basically feature complete, but I'm not ...
5
votes
2answers
155 views

What mistakes am I making with this Haskell implementation of merge sort?

I've decided to learn Haskell by following the current Coursera algorithms course using Haskell to implement the algorithms discussed. First up is merge sort, which I've implemented as shown here. ...
3
votes
1answer
95 views

Simple netwire program - is there some way to write this simpler?

I've written a simple program to test out the capabilities of netwire (or rather, how to write programs using netwire). The goal is to have an application that shows a window, starting out as ...
2
votes
0answers
124 views

Implementing recursive filters with Haskell/Repa

I recently learned Haskell, and I am trying to apply it to the code I use in order to get a feeling of the language. I really like the Repa library since I manipulate a lot of multi-dimensional data. ...
4
votes
1answer
225 views

Project Euler #14 (Longest Collatz Sequence) in Haskell

You can check the problem here: http://projecteuler.net/problem=14 My first approach in Haskell was this: import Data.Ord import Data.List computeCollatzSequenceLength n = let compute l n ...
2
votes
1answer
59 views

tree heap Haskell code

I'd like a review of Haskell tree heap code in Turning a tree into a heap in Haskell. module Heapify where data Tree a = Leaf a | Node (Tree a) a (Tree a) deriving Show ourTree = Node (Node ...
3
votes
1answer
112 views

Correct way to define a HasPostgres instance for IO?

I want to write my database access code for a Snap application in a way that makes the queries easy to test from the ghci repl, while also working within the Snap context. My solution so far is to ...
2
votes
0answers
116 views

How to improve readability and memory footprint of this haskell script?

I have this small haskell script that I wrote some time ago to parse a set of financial CSV files to produce other CSV files. I've recently had a problem with large input files (around 300Mb) that I ...
7
votes
1answer
257 views

Haskell Particle Simulation

I recently started learning Haskell and as my first project I decided to port a particle simulation I had written in C. The simulation is pretty simple. We have a cubic box with particles (spheres) ...
0
votes
1answer
131 views

Parsing a String to see if it contains another String, and then returning a monad if it does

I was writing a function (named listenString) in haskell to see if a string contains one of the strings in a list of strings, and to then return a value (of the type m ()) that corresponded with the ...
-2
votes
1answer
55 views

What's Haskell's way to do this: “fn object target” or “fn target object”? [closed]

For example, ends_width str prefix or ends_width prefix str? I think one is better for partial, other is better for infix. What's the preferred style in a FP perspective?
1
vote
1answer
92 views

Recursive Determinant

The following code I devised to compute a determinant: module MatrixOps where determinant :: (Num a, Fractional a) => [[a]] -> a determinant [[x]] = x determinant mat = sum [s*x*(determinant ...
2
votes
1answer
78 views

Haskell MultiWayIf extension: When is it considered useful syntactic sugar?

The new MultiWayIf extension (available with GHC 7.6) allows guard syntax in an if: {-# LANGUAGE MultiWayIf #-} fn :: Int -> String fn x y = if | x == 1 -> "a" | y < 2 ...
3
votes
2answers
264 views

Optimizing unboxed array operations in Haskell

Consider this simplified code which successively permutes array elements: import Data.Word import Data.Bits import Data.Array.Unboxed import Data.Array.Base import Data.Array.ST test3 :: UArray Int ...
2
votes
2answers
343 views

Haskell markov text generator

I'm new to Haskell, and here is my first not-totally-trivial program. It's the first program I tend to write in any language -- a Markov text generator. I'm wondering what I can change to make it more ...
4
votes
3answers
341 views

I'm wondering if I'm doing this whole Haskell thing right

There may not be a "right" way to do it, but I've come to perceive Haskell as the kind of language, where literacy of the proposed programming paradigm is crucial to writing proficient code in the ...
4
votes
3answers
274 views

simple in-memory db

Pretty new to haskell here, I've implemented a very simple in-memory "database" just as an exercise, thought I'd post it here and see if there's anything obvious I should be doing that fits more of ...
3
votes
2answers
473 views

Palindrome test in Haskell

I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the functional way of doing things. I built this short module to test if a given string ...
0
votes
0answers
120 views

Could someone profile the space and time complexity of this Haskell snippet?

I'm new to programming and even more new to Haskell, below is a little tid-bit I wrote that operates on a bunch of lists. I am wondering if someone would be kind enough to walk through the function ...
0
votes
0answers
76 views

Haskell network connection graceful handler

Just trying to work out some simple graceful connection handling code in Haskell to get my head around some of the IO/Networking/Threading stuff, some tips where I'm doing things poorly would be ...
3
votes
2answers
407 views

C# state monad implementation

I want to know whether this thing I wrote in C# is a correct implementation of the state monad. I've used it in code and it does what I expect it to do, but I'm still not quite sure if I'm doing this ...
4
votes
2answers
85 views

Is there a way to simple Haskell class instance?

I define a Pixel data with different size like this. data Pixel = RGB8 Word8 Word8 Word8 | RGBA8 Word8 Word8 Word8 Word8 | RGB16 Word16 Word16 Word16 | RGBA16 Word16 ...
3
votes
1answer
326 views

Crtitique my Haskell function 'capitalize'

I am a Haskell beginner. I wrote the following function that takes a string and returns a new string with each word capitalized: first letter uppercase, following letters lower-cased. It works, but I ...