haskell

Haskell XMLRPC server executing dynamically generated functions

I have a Haskell RPCXML (HaXR) server process, run with GHC, that needs to execute any function that it's passed. These functions will all be defined at runtime so the compiled server won't know about them. Is there a way to load a function definition at runtime? A method that avoids disk IO is preferable. Thanks. ...

Am I using sound equational reasoning about a definition of filter in terms of foldr?

well, this is the definition of the filter function using foldr: myFilter p xs = foldr step [] xs where step x ys | p x = x : ys | otherwise = ys so for example let's say i have this function: myFilter odd [1,2,3,4] so it will be: foldr step [] [1,2,3,4] and this will be step 1 (foldr step [] [2,...

Using MonadError with Parsec

I'm trying to use MonadError together with Parsec. I've come up with the following code snippet: f5 = do char 'a' throwError "SomeError" f6 = f5 `catchError` (\e -> unexpected $ "Got the error: " ++ e) ret = runErrorT (runParserT f6 () "stdin" "a") However, ret is Left "SomeError", it seems the catchError doesn't have any ef...

In Haskell, is there a built-in function that creates a list of one element?

Looking for a built-in function that will do the following: mklist x = [x] The benefit is that I can use it in a composition to create a list of one element. Understand that (replicate 1) is available but is there a more direct function? Would be useful in situations like this: ["Alice", "Bob", "Charlie"] >>= mklist . ("Hello " ++) ...

What do the parentheses signify in (x:xs) when pattern matching?

when you split a list using x:xs syntax why is it wrapped in a parentheses? what is the significance of the parentheses? why not [x:xs] or just x:xs? ...

Creating polymorphic recursive types in Haskell

Hi I'm trying to create a Tree type in Haskell. I've used this simple data constructor for storing a tree in which each node can either be empty, be a leaf containing an integer, or be a node containing an integer with branches to two other leaves/nodes. Here's what I've got: module Tree ( Tree(Empty, Leaf, Node) ) where data Tree = E...

Understanding Haskell profiler output - what is ==_a3JO

I am writing some optimization application in Haskell and I just ran it through profiler. I can see many functions and a strange symbol "==_a3JO" (sometimes different numbers and leters). What does it stand for? Sample output: maxDistanceRaw Igc 360 471912 5.2 5.7 19.8...

Are these two combinators already available in Haskell?

I need binary combinators of the type (a -> Bool) -> (a -> Bool) -> a -> Bool or maybe [a -> Bool] -> a -> Bool (though this would just be the foldr1 of the first, and I usually only need to combine two boolean functions.) Are these built-in? If not, the implementation is simple: both f g x = f x && g x either f g x = f x || g...

Functional language implementations of Production Grade data stores

There are many datastores written in Erlang, for example Riak, Dynomite, CouchDb, Scalaris, have I missed any? I know that Java and C/C++ have also been used to write datastores (Cassandra, Hypertable, etc), but have any Datastores been written in any other functional languages such as F#, Scala, Haskell, Clojure, etc? The reason I am a...

Problem with nesting in Text.XHtml library with Haskell

Hi I have the following code to generate a blank html page with a series of divs with id's and classes in Haskell using the Text.XHtml.Strict library: module Main where import Text.XHtml.Strict import Text.Printf page :: Html page = pHeader +++ pTop +++ pBody +++ pFooter pHeader :: Html pHeader = header << thetitle << "Page title" ...

Haskell speculative parallel execution

I am thinking about exploiting parallelism for one problem I am trying to solve. The problem is roughly this: given input (sequence of points) find a best output (biggest triangle composed from these points, longest line etc.). There are 3 different 'shapes' to be found in the sequence of points, however I am interested only in the one w...

Is Vim's Haskell syntax highlighting broken?

It seems to me that Vim's syntax highlighting for Haskell is broken, or very buggy. Multiline comments in Haskell (beginning with {- and ending with -}) are arbitrarily greened-out and un-greened-out. Sometimes dragging the mouse over the commented code causes it to reverse color. Has anyone else been experiencing this problem? ...

Haskell's liftIO's litter functions of type ErrorT String IO ()

I have a function that returns type ErrorT String IO (). While the function works, liftIO's litter every line that does IO. It makes for a mess. Is there any way to get around this and still have the ability to abort on error? ...

Haskell caching results of a function

I have a function that takes a parameter and produces a result. Unfortunately, it takes quite long for the function to produce the result. The function is being called quite often with the same input, that's why it would be convenient if I could cache the results. Something like let cachedFunction = createCache slowFunction in (cachedFu...

Counting elements in a tree in Haskell

Hi Basically I've made a polymorphic tree data type and I need a way of counting the number of elements in a given tree. Here's the declaration for my Tree data type: data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving (Eq, Ord, Show) So I can define a tree of Ints like this: t :: Tree Int t = Node (Leaf 5) 7 (Node (Lea...

The Genuine Sieve of Eratosthenes -- algorithm used to generate prime numbers.

Today I read a paper: O'Neill, Melissa E., "The Genuine Sieve of Eratosthenes", Journal of Functional Programming, Published online by Cambridge University Press 09 Oct 2008 doi:10.1017/S0956796808007004. It described an algorithm of generating prime number by using Priority Queue : sieve [] = [] sieve (x:xs) = x : sieve...

Inserting a value into an ordered tree in Haskell

Hi Basically I have defined a Tree data type which is defined as follows: data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving (Eq, Ord, Show) Now I have to create a function to insert a value into an ordered tree (it doesn't have to sort the tree, just add the value). This is what I've come up with so far: insert :: a -...

O(1) circular buffer in haskell?

I'm working on a small concept project in Haskell which requires a circular buffer. I've managed to create a buffer using arrays which has O(1) rotation, but of course requires O(N) for insertion/deletion. I've found an implementation using lists which appears to take O(1) for insertion and deletion, but since it maintains a left and rig...

STUArray with polymorphic type

I want to implement an algorithm using the ST monad and STUArrays, and I want it to be able to work with both Float and Double data. I'll demonstrate on a simpler example problem: calculating a memoized scanl (+) 0 (I know it can be solved without STUArray, just using as example). {-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-} ...

Crazy haskell indentation

This the entire program: import Data.Char (digitToInt) myInt :: String -> Int myInt [] = error "bad input: empty string" myInt (x:xs) | x == '-' = -1 * myInt xs | otherwise = foldl convert 0 (x:xs) where convert acc x | x `elem` ['0'..'9'] = 10 * acc + digitToInt x | otherwise = error ("bad input: not a...