1
vote
1answer
37 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 ...
3
votes
2answers
112 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
97 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 ...
4
votes
2answers
64 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 ...
1
vote
0answers
46 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 ...
3
votes
1answer
97 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 ...
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
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 ...
6
votes
2answers
139 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
1answer
307 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 this short note describing bitcask's ...
6
votes
4answers
293 views

Can I make this code more Haskelly?

I am very new to functional programming. I wrote this program where the user can enter an integer and it prints the factorial. If the user enters a negative integer or not an integer at all, it'll ...
5
votes
4answers
531 views

Improving my solution to Project Euler problem #1?

I'm trying to compare my own implementation with another solution of ProjectEuler problem #1, which uses a list comprehension: module Progression1 (sumProgressions) where import Prelude ...
5
votes
1answer
105 views

Chaining method calls and “bubbling” the results

I need a way to build up a sort of stack of places to search for an item. What I would like to do is to have each layer searched for an item, and if it is found at that level, then it should be ...
4
votes
2answers
360 views

Enclosing Circle Problem implementation in Haskell

I implemented the algorithm by Pr. Chrystal described here in Haskell so could someone please tell me: Do i have implemented this algorithm correctly? Initial calling of findPoints takes the first and ...
2
votes
2answers
266 views

Can my solution to TopCoder's BestApproximationDiv2 problem be any better?

Link to problem statement on TopCoder import Data.Char import Data.List import Data.Maybe showResult :: (Int, Int, Int) -> String showResult (a, b, x) = show a ++ "/" ++ show b ++ " has " ...
3
votes
1answer
163 views

Most elegant approach to writing list renumbering function

I'm writing a function with the following signature: (Ord a) => [a] -> [Int] It's semantics is to find an order-preserving mapping from list of objects to list of Ints. The version of mine: ...
9
votes
1answer
366 views

Converting simple markup to HTML

This is going to be rather long and generic, so apologies in advance. I've been reading a lot about Haskell lately, but I've never really programmed anything with it beyond simple experiments in ...