haskell

Help Understanding Arrows in Haskell

I've been trying to get a grip on arrows, since they're the basis of most FRP implementations. I think I understand the basic idea - they're related to monads but store static information at each bind operator so you can walk through a chain of arrows and look at the static information without having to evaluate the whole arrow. But I ...

Help Haskell functors sink in.

Learn You a Haskell has an example about functors. I can read LYAH, and text, and figure out what is supposed to happen -- but I don't know enough to write something like this. I'm finding this problem often in Haskell. instance Functor (Either a) where fmap f (Right x) = Right (f x) fmap f (Left x) = Left x However, I'm ...

Implementing the Haskell-MaybeMonad in F# - how can we get this lazy?

Hi, we are trying to build the Haskell-MaybeMonad sample from http://www.haskell.org/all_about_monads/html/maybemonad.html in F#. The idea is to search for a mailaddress in two dictionaries. If one of the both lookups returns a result we look into the third one. let bindM x k = match x with | Some value -> k value | None ...

Mapping over IO in Haskell

Is there a traditional way to map over a function that uses IO? Specifically, I'd like to map over a function that returns a random value of some kind. Using a normal map will result in an output of type ([IO b]), but to unpack the values in the list from IO, I need a something of type (IO [b]). So I wrote... mapIO :: (a -> IO b) -> [a]...

Java Message Service and Haskell

Hi, I was wondering if there is any way to receive JMS messages from some provider like ActiveMQ or WebMQ in a Haskell program. I've seen that there is a Haskell client for ActiveMQ but it seems to be unmaintained. Has anybody experience with this or any kind of advise? ...

[Haskell] Error "No instance for (Num [t])" in Collatz function

I am new to Haskell, and programming in general. I am trying to define a function which generates the sequence of Collatz numbers from n. I have: collatz n = (collatz' n) : 1 where collatz' n = (takeWhile (>1) (collatz'' n)) where collatz'' n = n : collatz'' (collatz''' n) where collatz''' 1 = 1 ...

how to write the identity function in haskell

I have a function with type like this: functionX :: [String] -> ([Integer] -> [Integer]) It is kind of like a mapping function that maps a specific String to a function with type as so. Because I need to handle the call functionX [], which I think this call should return something called identity function, or whatever, how can I write...

Can I do something like this in haskell?? Help

Okay, this time I'll make it clear, the job of function1 is to check a string if it comes up with the '?' thing, he will put the rest of the string in a list. if not, it will store everything in a stack, how can I do this function2 :: [String] -> [([Char], [Integer]->[Integer])] function1 :: [String] -> [Integer] -> ([Integer], String)...

Constraining the returntype to a Context

Here are my attempts so far: module Main where data FooT = One | Two deriving (Show, Read) {- That is what I want foo :: (Show a, Read a) => a foo = One -} --class Footable (Show a, Read a) => a where class Footable a where --foo2 :: (Show a, Read a) => a foo2 :: a instance Footable FooT where foo2 = One -- test = print foo2 ...

GHC's RTS options for garbage collection

I have a Haskell program which processes a text file and builds a Map (with several million elements). The whole thing can run for 2-3 minutes. I found that tweaking the -H and -A options makes a big difference in running time. There is documentation about this functionality of the RTS, but it's a hard read for me since I don't know the...

Haskell: Functions that sometimes return a function

Hoe do you write a function that can either return a value or another function? For example: Function Foo (x) If X = 0 Return "Done" Else Return a Function that calls Foo(x-1) ...

Proper way to import things already defined in the Prelude in Haskell

I'm trying to define a Foldable instance in Haskell and I have some problem with import. So first try : module MyList where import Data.Foldable data MyList a = MyList [a] instance Foldable (MyList) where foldr f b (MyList as) = foldr f b as Result (normal but annoying) Ambiguous occurrence `foldr' So, I guess I ha...

Why should I want to learn haskell?

Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard people saying things like "Every programmer should know Haskell", "You aren't a programmer if you don't know haskell" and so on. However, I'm not exactly sure if I should bother trying to get a brief understanding of that language or not...

Haskell map/zip Vs. list comprehension

Which of the following are you most likely to write? r = zip xs $ map sqrt xs or r = [(x, sqrt x) | x <- xs] Sample code on the Internet seems to indicate that the former is more abundant and the preferred way. ...

wxhaskell asynchronous updates

I am using WxHaskell to graphically show the state of a program that advertises state updates using TCP (which I decode using Data.Binary). When an update is received, I want to update the display. So I want the GUI to update its display asynchronously. I know that processExecAsync runs a command line process asynchronously, but I don'...

Haskell sorting of an unorderable list using a proxy order

Suppose I have x :: [(n, a)] where n is a number and a is an unorderable item (is not of class Ord). I want to sort this list by n. I cannot do sort x because a is not orderable. I can replace a by indices and then assemble the new list using !! but this seems like a poor solution. Alternatives? ...

Haskell and Conditional Data Structures

Is it possible to write something like: data SomeData = SomeValue | (Integral a) => SomeConstructor a And how exactly would one write this? ...

Haskell rigid type?

Possible Duplicate: Return specific type within Haskell This code: class Alpha a where half :: Real f => a -> f instance Alpha Double where half a = a/2.0 produces this error: rigid.hs:6:13: Couldn't match expected type `f' against inferred type `Double' `f' is a rigid type variable bound by th...

[Haskell] Space Leak

I am solving some problems of Project Euler in Haskell. I wrote a program for a riddle in it and it did not work as i expected. When I looked in the task manager when running the program I saw that i was using >1 gigabyte of RAM on ghc. A friend of me wrote a program with the same meaning in Java and succeeded in 7 seconds. import Data....

Haskell: What does it mean to have a typeclass of `Num [a]` vs a typeclass of `(Num a) => [a]`

Apparently, my type signature was off. I've since found out why. Now, I'm interested in knowing more about the GHCI inferred signature on my typo. I was trying to get this code to work: elemNum :: (Eq a, Num b) => a -> [a] -> b elemNum e l = f e l where f _ [] = [] -- this was my typo, supposed to read 0 f e (x:xs) ...