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
0answers
27 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
103 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. ...
2
votes
1answer
51 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
68 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
99 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
38 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
87 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
95 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
186 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
78 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 ...
-1
votes
1answer
41 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?
7
votes
0answers
185 views
Attempt to port Free Applicative to scala [closed]
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
59 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
56 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
157 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
272 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
294 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
244 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
150 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
103 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
60 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
220 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
73 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
111 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
34 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 ...
6
votes
1answer
148 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 ...
6
votes
1answer
123 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
232 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
86 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
37 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
175 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
134 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
79 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
249 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
51 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
117 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
105 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
76 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
171 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
94 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
145 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 ...
6
votes
1answer
119 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
124 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
262 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
117 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
216 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
192 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
120 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
104 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 ...
8
votes
4answers
891 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 ...