Haskell is an 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

6
votes
0answers
77 views

Attempt to port Free Applicative to scala

I'm trying to port Edward Kmett's free package (in particular, Free Applicative) to scala. I was able to get this far. I'm particularly having problem with implementing the ap function for the Ap ...
1
vote
1answer
40 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
46 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
102 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
240 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
275 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
226 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
116 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
98 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
54 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 ...
2
votes
2answers
166 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
65 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
94 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 ...
1
vote
0answers
33 views

TOML Parser with Parsec

i wanted to practice parsec and thought about doing a TOML parser for fun. i am looking for both directions on how to fix the remaining problems, but even more some hints on my style. the one ...
5
votes
1answer
103 views

Is there a better way to walk a directory tree?

I just started to learn Haskell, and i wrote a function that walks the directory tree recursively and pass the content of each directory to a callback function: The content of the directory is a ...
5
votes
1answer
105 views

Excessive use of let a problem in Clojure?

I have this set of functions - it works, but I'm concerned about the use of lets. (defn- create-counts [coll] "Computes how many times did each 'next state' come from a 'previous state'. The ...
5
votes
1answer
195 views

Counting word frequencies in Haskell

I am leaning Haskell and decided to do the following lab assignment from CS240h: Functional Systems in Haskell. I welcome any advice on more idiomatic coding style and performance tips. Notes: I ...
1
vote
0answers
78 views

Data model with validation in haskell couple convoluted functions

So I'm curious about a few things that I did here design wise, as well as one space I'm sure I can be given improvements from real haskellers. The part I really think can be done better that I'm ...
1
vote
1answer
36 views

Ltree inverse crossing function using high order functions

I was solving some Haskell exercises as a way to refresh some of the language concepts. I encounter the following exercise: data LTree a = Leaf a | Fork (LTree a) (LTree a) crossing :: LTree a ...
3
votes
1answer
160 views

Wrote javascript version of error monad / monadplus, did I obey monad laws correctly?

Just looking for some critiques hopefully from haskellers of how I might be breaking monad laws or just monadding all wrong. My or is something like the mplus for either and usable as a catch for ...
2
votes
2answers
133 views

Reducing boilerplate of binary layout handling in Haskell

Here is the code: https://github.com/EarlGray/haskell-snippets/blob/master/ext2hs/Ext2.hs My problem is that it is quite painful to make large Haskell "records" and deserialize a binary layout with ...
0
votes
1answer
59 views

Errors with binary search in Haskell

I just learned about Maybe in Haskell, so I decided to try to use it with a binary search. Here's the function: binarySearch :: (Ord a, Int b) => [a] -> a -> b -> b -> Maybe b ...
3
votes
1answer
232 views

Refactoring a Telnet parser

I'm writing a Telnet parser in Haskell that can run within any monad that implements some event-handling functions. When it finishes processing a block of input - whether because it read it all or ...
1
vote
0answers
47 views

This is a try at implementing integers in Idris. Any advice or comments are most welcome.

-- tries to implement integers using fold and a generalized notion of 'reduction' instead of -- utilizing recursion explicitly in all operations./ -- maximum (reasonable) code reuse, information ...
1
vote
1answer
116 views

Haskell with too much case statements

This is function, that works correctly, but it seems to be too ugly. panel argument is never used for anything but pushing into refreshGamePanel, and it seems to be too much case statements. How can I ...
1
vote
0answers
100 views

A stack-based language interpreter in Haskell

Here is a little interpreter I wrote for a simple stack-based language. It is my first attempt at a complete Haskell program, beyond glorified calculator use. I'd like very much to get an expert's ...
2
votes
1answer
75 views

Which of these two paren-matching functions is better?

I am currently trying to learn Haskell (after taking a Scala course on Coursera); but while I can write functions that do what I want, I worry that I am not learning to write idomatic/clean/performant ...
3
votes
3answers
168 views

How can I improve this Haskell code?

This code solves the problem of FizzBuzz. Is it possible in any way to improve it? main = main' 1 where main' n = do (putStrLn . choose) (show n, "Fizz", "Buzz", "FizzBuzz", n) if n < 100 ...
3
votes
1answer
92 views

Haskell tips/why doesnt this scale linearly?

My friend wrote a program which compares random arrangements of die faces to find the one with the most evenly distributed faces - especially when the faces are not a mere sequence. I translated his ...
4
votes
1answer
134 views

Hangman: Is this small Haskell game clean and idiomatic Haskell code?

I hope this question isn't too general. I've been learning Haskell, and a while ago I created this Hangman game. I've been working on using a library for terminal output, so no more hardcoded escape ...
5
votes
1answer
117 views

I'm learning Haskell and would love for someone to critique my first attempt at writing something

import System.IO import System.Random import Control.Monad import Control.Arrow data Throw = Rock | Paper | Scissors deriving (Show, Read, Enum, Bounded) instance Random Throw where ...
3
votes
2answers
119 views

BrickBreaker Spinoff in Haskell

I have an implementation of a BrickBreaker-like game where instead of pieces being just removed from the ceiling, each impact results in a new ball being released, gradually building up to a pretty ...
3
votes
2answers
244 views

Google Code Jam - Alien Language

I've successfully solved the Alien Languages problem for Google Code Jam in Haskell: http://code.google.com/codejam/contest/90101/dashboard#s=p0 The algorithm is trivial - turn the patterns into ...
2
votes
2answers
116 views

Is this permutation applicative/monad implementation clear?

Below is a module that executes a sequence of actions in any possible order. LANGUAGE_DataKinds and LANGUAGE_DefaultSignatures are predefined cpp symbols. I am particularly concerned about the use ...
4
votes
1answer
198 views

Is this idiomatic Haskell?

I've been studying hard and asking a lot of questions - I finally came a cross an exercise in LYAH that looked like it was easy enough but a perfect candidate for practicing. The below program has a ...
2
votes
2answers
164 views

Calling a Haskell MD5 hashing function from C, and returning the result back to C land

I'm starting to learn how to meld the worlds of C and Haskell. Looking for any feedback on this first function. The function takes in a pointer to an array of unsigned chars and returns a pointer to ...
4
votes
2answers
114 views

Ordinary Data Processing Task in Haskell: Vague Misgivings

This is an ordinary data processing task: read a list of dates and amounts (for example, deposits and withdrawals from a bank account) and report the date on which the lowest balance was recorded and ...
3
votes
1answer
98 views

Help make nested folds look less terse

My Haskell set/map/list folds often become terse and difficult to read. I'm looking for tips on how to make my functional code easier to follow. I'm working around a bug/feature in a plotting ...
6
votes
4answers
483 views

How to use Haskell as a scripting language for every day task?

In book Real World Haskell the author writes in the first line of every file that uses, for example the following: file: ch05/PrettyJSON. The chapter slash and the name of a module. I wanted to create ...
10
votes
4answers
1k views

How to shorten this terrible code?

I am trying to read a line ending in \r\n from a Handle. This is an HTTP header. I’m fairly new to functional programming, so I tend to use a lot of case expressions and stuff. This makes the code ...
4
votes
3answers
230 views

Haskell: Nearest Neighbour classification algorithm

The following code is from a university assignment of mine to write a classification algorithm (using nearest neighbour) to classify whether or not a given feature set (each feature is the frequency ...
4
votes
2answers
156 views

Project Euler #9 in haskell

I am trying to teach myself haskell by means of project Euler i sovled problem #9 by means of this code which is on the brute force side I was wondering if there is a more elegant/haskell/efficient ...
3
votes
1answer
74 views

mapM for both keys and values of Data.Map

I'm writing a monadic parser instance that transforms Data.Map.Map's: instance (Ord a, FromEDN a, FromEDN b) => FromEDN (M.Map a b) where parseEDNv (E.Map m) = mapMmap parseEDNv parseEDN m ...
6
votes
2answers
244 views

Review my small Haskell program please

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
139 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. type TransitionTable = [(Int, Transitions String Int)] type ...
2
votes
1answer
103 views

Initating in haskell, am I following a good way?

I'm a bit concerned about fucntion usage. There are so many diferent 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
203 views

Haskell Poker Hand Kata

Similar to, but distinct from this. 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: import Data.String ...
2
votes
1answer
203 views

Optimize some Haskell code

I tried to solve the Unfriendly Number problem on InterviewStreet. Statement: There is one friendly number, K, and N unfriendly numbers. We want to find how many numbers are there which exactly ...
1
vote
0answers
67 views

Imroving GADT 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 from the type it can be concluded ...
3
votes
1answer
157 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 ...

1 2 3