haskell

Haskell audio output on OS X?

I'd like to be able to output audio from Haskell. I'm currently using GHC 6.10 on OS X (Snow Leopard). I've tried building the jack library (using JackOSX) and the PortAudio library, but neither of them seemed effective. Is there a relatively simple way to do live audio output from a Haskell program on a Mac? Edit: Clarity ...

Guarded Equations in Haskell

Can somebody provide me with an easy to understand explanation of a guarded equation as it is used in Haskell and also its mathematical sense? ...

Haskell pattern matching - what is it?

What is pattern matching in Haskell and how is it related to guarded equations? I've tried looking for a simple explanation, but I haven't found one. EDIT: Someone tagged as homework. I don't go to school anymore, I'm just learning Haskell and I'm trying to understand this concept. Pure out of interest. ...

Haskell confusion with ContT, callCC, when ...

Continuing quest to make sense of ContT and friends. Please consider the (absurd but illustrative) code below: v :: IO (Either String [String]) v = return $ Left "Error message" doit :: IO (Either String ()) doit = (flip runContT return) $ callCC $ \k -> do x <- liftIO $ v x2 <- either (k . Left) return x when True $ k (Lef...

Accessing named fields in a Haskell function

Hi I've defined a Tree data type in Haskell and an associated 'size' method which calculates the number of elements in the tree. This worked before, however I have updated the Tree data type to use named fields as in the following definition: data Tree a = Empty | Leaf {value::a} | Node {left :: (Tree a), value :: a, right :: (Tree a...

Haskell mutable map/tree

I am looking for a mutable (balanced) tree/map/hash table in Haskell or a way how to simulate it inside a function. I.e. when I call the same function several times, the structure is preserved. So far I have tried Data.HashTable (which is OK, but somewhat slow) and tried Data.Array.Judy but I was unable to make it work with GHC 6.10.4. A...

How can I use parMap with a monadic function?

I have a monadic function getRate: getRate :: String -> IO Double I'd like to map this function over a list of String's. Normally, I would just do: mapM getRate ["foo", "bar"] but since each call to getRate makes network calls, I'd like to parallelize the map so that each rate is fetched in a separate thread (or at least spread ou...

What is a common idiom for converting between Integral types?

I want to convert between various integral types (for example, Word32 and Word8). What is the idiomatic way to do that in haskell? Word8 -> Word32 conversion can always succeed. Word32 -> Word8 conversion might result in an overflow and I'll deal with that (either for testing explicitly or getting an indication from whatever the conver...

F# vs Haskell vs Lisp - which language to learn?

I've heard a lot about functional programming languages and I'm willing to learn one. I guess it will be mostly for fun, however, I hope it will improve my programming skills. I have mostly C#/.NET background, so my first choice is to learn F# (because of .NET and familiarity with Visual Studio). On the on other hand, I wonder if F# has...

Composing monad actions with folds

Let's take a function of type (Monad m) => a -> m a. For example: ghci> let f x = Just (x+1) I'd like to be able to apply it any number of times. The first thing I tried was ghci> let times n f = foldr (>=>) return $ replicate n f The problem is that it won't work for large n: ghci> 3 `times` f $ 1 Just 4 ghci> 1000000 `times` f $...

Scala equivalent to Haskell Monads

I had some experience in Haskell and currently learning Scala. Am wondering whether there is something equivalent to Monads in Scala?? ...

How do I use Data.Concurrent.mergeio?

I see two functions mergeio and nmergeio in Data.Concurrent, but I can't find any examples of how they work. Has anyone worked with these before? My hope is that I can use these to get a function like "parMapM". ...

GTK Expander without fixed sizes.

Hi. I am having some trouble using the GTK Expander widget. I have several expanders in a vertical box. When collapsing an expander, I want the expanders below to "shuffle" up to meet the bottom of the collapsed expander's bar. However, using VBox appears to reserve a fixed amount of vertical space for each widget, which does not change ...

Problems trying out happstack-tutorial

I've been reading about Happstack and decided to give it a shot. I'm running xubuntu 9.10 and got to this page in the tutorial which told me to do cabal install in the tutorial folder. When I did this, I got the following errors: $ cabal install Resolving dependencies... cabal: cannot configure Crypto-4.2.1. It requires QuickCheck >=2 F...

Need a tutorial for using GHC to parse and typecheck Haskell

I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my...

Iterate over list in haskell?

I'm writing an audio program in Haskell using Portaudio. I have a function that generates a list of samples I'd like to play, and I'm trying to play them using the following snippet inside main: curSamps <- return (chunk 1 (sineWave 440 44100)) forever $ do Right numSampsAvail <- getStreamWriteAvailable paStream Right NoError <- wri...

How do VBOs/FBOs/DisplayLists work in Haskell's OpenGl bindings?

Haskell is about computation by calculation of values. DisplayLists / FBOs / VBOs are very very stateful by nature. I.e. "give me a display list / buffer object". How do these bindings work in Haskell? [I do understand monads; so a technical explaination, as opposed to a fluffy one, is preferred]. Thanks! ...

Why doesn't my Haskell function accept negative numbers?

I am fairly new to Haskell but do get most of the basics. However there is one thing that I just cannot figure out. Consider my example below: example :: Int -> Int example (n+1) = ..... The (n+1) part of this example somehow prevents the input of negative numbers but I cannot understand how. For example.. If the input were (-5) I wou...

Learning Haskell: How to implement my own version of init function

As part of learning Haskell, I am trying to implement my own version of various functions associated with Lists. Right now I am stuck on the init function. init function in Haskell returns all the elements in a List other than the last element. Here is what I have done so far. init' :: [Int] -> [Int] init' [] = error "This function ca...

Is there a way to do more "dynamic" data constructors in Haskell?

Is there some Haskell extension that enables the creation of more complex data constructors then GADT? Suppose I wanted to create a data structure that is an ordered list, and have a data constructor similar to (:) that work with lists, with type signature: data MyOrdList a where (>>>) :: (Ord a) -> a -> MyOrdList a -> MyOrdList a ...