haskell

Haskell: faster summation of primes

Disclaimer: I'm working on Euler Problem 9. I'm adding up some pretty large numbers, all the primes from 1 to 2 000 000. Summing those primes takes forever. I'm using the haskell built in function 'sum'. as in: sum listOfPrimes Are there any other faster options? --My prime generator was the slow link in my code. ...

Concurrent DB connection pool in Haskell

I am a Java programmer who learns Haskell. I work on a small web-app that uses Happstack and talks to a database via HDBC. I've written select and exec functions and I use them like this: module Main where import Control.Exception (throw) import Database.HDBC import Database.HDBC.Sqlite3 -- just for this example, I use MySQL in produ...

Plot data reconstruction reading pixel colors from image files

Hi, How can I open and read colors of specific pixels of an image file in Haskell? Which packages, functions do you recommend? You can have a look at the quoted plot and the reconstructed data below for an idea on what I would like to automate. I had my way with this particular figure using Gimp and marking the points on lines manually...

Graphs (Nodes and Edges)

I am using HASKELL for graph games. I am willing to get a suitable method for reach ability from a node to a particular node in the graph apart from using bfs or trees etc. As I asked for code in haskell for reach ability from one node to a particular node, it is necessary to tell you that I am totally new to haskell. I have been re...

Need to learn Prolog, Haskell for a C# programmer

I am a C# programmer, and after going through some wonderful discussions regarding functional programming and declarative programming. I feel I am not good at both :P, so, I was thinking of starting learning prolog, and haskell. Please suggest about the feasibility in doing so. And if I learn F#, then learning Haskell makes any sense ? W...

What does the "@" symbol mean in reference to lists in Haskell?

I've come across a piece of Haskell code that looks like this: ps@(p:pt) What does the @ symbol mean in this context? I can't seem to find any info on Google (it's unfortunately hard to search for symbols on Google), and I can't find the function in the Prelude documentation, so I imagine it must be some sort of syntactic sugar instea...

Haskell: any debugShow function?

I want to use Debug.Trace.trace to print something which I know is a Show. Just like I would do in Python etc. One solution is to add "Show a =>" to the signature of the function where I want to put the trace, and to any function calling it, etc. But it would had been much nicer if I could use some debugShow function which calls show i...

Haskell: Can I use a where clause after a block with bind operators (>>=)?

I have a very simple question. I'd like to use a where clause after a bloc of code that uses bind operators but I get a compilation error. Here is a simple example: main = putStrLn "where clause test:" >> return [1..10] >>= \list -> print list' where list' = reverse list -- test1.hs:5:28: Not in scope: `list' I ca...

Values inside monads, nested in data structures?

Suppose that in a Haskell program I have some data whose type is something like: IO [ IO (Int, String, Int) ], or IO [ (Int, String, IO Int) ], or [ (Int, String, IO Int) ] but I have pure functions that should operate on [ (Int, String, Int) ]. It seems that I'd have to clumsily remove the inside values from the IO monad, until I g...

"Could not deduce (MArray (STUArray s) Int (ST s)) from context ()" when applying runST

Hi, I'm in the process of learning haskell and came across this problem: Using Glasgow Haskell Compiler, Version 6.10.4, for Haskell 98, stage 2 booted by GHC version 6.10.1 Common beginning of the file {-# LANGUAGE FlexibleContexts #-} module UPSO where import Control.Monad(forM,forM_) import Control.Monad.ST.Lazy (ST,runST) import...

Haskell Function Cheat Sheet

Is there a descriptive listing of common Haskell functions in prelude and some of the core libraries such as Data.List and Data.Char? I am just learning Haskell and I find myself frequently performing time-inefficient searches for functions that I know exist but for which I have forgotten the name. Such searches tend to distract my f...

How do I test if a floating point number is an integer in haskell?

If I have a floating point number in Haskell how do I test if it is a whole number. ...

Where can I find some good documentation about Haskell programming language?

I'm having problems with Haskell documentation that I found. Is not too clear and too simple. Where can I find any better documentation about this language? ...

Pattern matching trick for identical values

I just wondered whether it's possible to match against the same values for multiple times with the pattern matching facilities of functional programming languages (Haskell/F#/Caml). Just think of the following example: plus a a = 2 * a plus a b = a + b The first variant would be called when the function is invoked with two similar va...

Why can Haskell handle very large numbers easily?

Hugs> 94535^445 13763208823213770506960538876615156211048901640052821530697264247739998018468419032448277029434879827074549660094560167350418780006041435009085328874649203806051649321126870390595266721098189242349208444482316125325707186571602341772853777338301048340410490766099124882372196084459950728677984306149354032194958838350428628...

New language for a jr programmer new to the industry?

As a programmer new to the software engineering industry, I'm trying to decide a new language to learn. I currently use Ruby/Javascript/HTML/CSS/SQL at the workplace, but would like to try a compiled language for a change. I am currently torn between learning a functional language like Haskell, or an imperative language like Java. All ...

Defining multiple-type container classes in haskell, trouble binding variables.

Hello, I'm having trouble with classes in haskell. Basically, I have an algorithm (a weird sort of graph-traversal algorithm) that takes as input, among other things, a container to store the already-seen nodes (I'm keen on avoiding monads, so let's move on. :)). The thing is, the function takes the container as a parameter, and calls j...

Implementing the last function

I am trying to teach myself Haskell. One thing I have tried to do is to write an alternative function to return the last element of a list by recursing through the list until the tail is the empty set and then returning the head. I have... mylast [] = [] mylast (x:[]) = x mylast (x:xs) = mylast xs ...but I get an error when I try any ...

Simple library to do UTF-8 in Haskell (since Streams no longer compile)

I just want to read (and maybe write) UTF-8 data. haskell.org still advertises System.Streams which does not compile with recent ghc: % runhaskell Setup.lhs configure Configuring Streams-0.2.1... runhaskell Setup.lhs build Preprocessing library Streams-0.2.1... Building Streams-0.2.1... [10 of 45] Compiling System.FD ( System/FD....

The meaning of ' in Haskell function name?

What is quote ' used for? I have read about curried functions and read two ways of defining the add function - curried and uncurried. The curried version... myadd' :: Int -> Int -> Int myadd' x y = x + y ...but it works equally well without the quote. So what is the point of the '? ...