haskell

What is being passed in?

In the code: oneChar :: Char -> Doc oneChar c = case lookup c simpleEscapes of Just r -> text r Nothing | mustEscape c -> hexEscape c | otherwise -> char c where mustEscape c = c < ' ' || c == '\x7f' || c > '\xff' simpleEscapes :: [(Char, String)] simpleEscapes = zipWith ch "\b\n...

Create a temporary directory in Haskell

What is the proper way to safely create a temporary directory in Haskell? System.IO offers ways to create temporary files, but I can't find anything that does the same for directories, neither there nor in System.Directory, System.Posix.Directory, nor System.Posix.Temp. Is there a function I'm overlooking, or do I need to write one mys...

Haskell Tuple Size Limit

Why I can't construct large tuples in Haskell? Why there's a tuple size limit? Prelude> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) <interactive>:1:0: No instance for (Show (t, t1, t2, ... t23)) arising...

Haskell math performance

I'm in the middle of porting David Blei's original C implementation of Latent Dirichlet Allocation to Haskell, and I'm trying to decide whether to leave some of the low-level stuff in C. The following function is one example—it's an approximation of the second derivative of lgamma: double trigamma(double x) { double p; int i; ...

Haskell lazy I/O and closing files

I've written a small Haskell program to print the MD5 checksums of all files in the current directory (searched recursively). Basically a Haskell version of md5deep. All is fine and dandy except if the current directory has a very large number of files, in which case I get an error like: <program>: <currentFile>: openBinaryFile: resourc...

Can I ensure that Haskell performs atomic IO?

I have two threads in haskell that perform IO. (They print only). Something like the following: thread1 :: IO () thread1 = putStrLn "One" thread2 :: IO () thread2 = putStrLn "Two" I am currently getting results like the following: OnTwoe OTnweo How can I ensure that each thread completes its IO atomically? ...

Haskell's TypeClasses and Go's Interfaces

What are the similarities and the differences between Haskell's TypeClasses and Go's Interfaces? What are the relative merits / demerits of the two approaches? ...

EE Major : Should I learn Ruby on Rails or Haskell?

Hi,I've just completed my freshman year in college and am majoring in EE (with a lot of interest in CS as well) . I know some Python,C/C++ and Java and also a little bit of Actionscript . I am planning to learn either Haskell or Ruby on Rails. Haskell because it is a functional programming language, and I've been really impressed by this...

Haskell: read input character from console immediately, not after newline.

I've tried this: main = do hSetBuffering stdin NoBuffering c <- getChar but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user presses it. I am using ghc v6.12.1 on Windows 7. EDIT: workaround for me was moving from GHC to WinHugs, which supports this correctly...

Haskell FlatMap

I am a beginner interested in Haskell, and I have been trying to implement the flatmap (>>=) on my own to better understand it. Currently I have flatmap :: (t -> a) -> [t] -> [a] flatmap _ [] = [] flatmap f (x:xs) = f x : flatmap f xs which implements the "map" part but not the "flat". Most of the modifications I make result i...

Problem with incomplete input when using Attoparsec

I am converting some functioning Haskell code that uses Parsec to instead use Attoparsec in the hope of getting better performance. I have made the changes and everything compiles but my parser does not work correctly. I am parsing a file that consists of various record types, one per line. Each of my individual functions for parsing ...

How do I code a tree of objects in Haskell with pointers to parent and children?

I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in Java: public class A { private List<B> m_children = new LinkedList<B>(); private boolean m_valid = true; public void invalidat...

Writing a sample server app - is forkIO unavoidable?

Hello, I haven't done anything networkish in haskell, so I'm giving that a try now. I'm using Oleg's ZFS as a template how to do that. IIRC he wasn't using threads but was using "delimited continuations" instead so I wonder if a heavier load server app could principally also be written without using forkIO threads. Günther ...

How to use the `itemDoubleClicked(QTreeWidgetItem*,int)` signal in qtHaskell

I want to use the itemDoubleClicked(QTreeWidgetItem*,int) signal in a Haskell program I'm writing where I am using qtHaskell for the GUI. To connect a function I have at other places done the following: dummyWidget <- myQWidget connectSlot object signal dummyWidget "customSlot()" $ f Where object is some QWidget and signal is a string...

Why can't GHCi resolve the kind of [[]] ?

Why can't Haskell resolve the kind of [[]] (A list of lists)? Why isn't it simply * -> *, as I can give it a type like Int, and get [[Int]], which is of kind *. ...

List of GHC extensions

I wanted to use {-# LANGUAGE OverloadedStrings #-} but I forgot how it's called. This kind of thing isn't hoogle-able, and also it takes some time finding using google*. Is there somewhere a list of GHC extensions named as they are in the LANGUAGE pragma? * My googling search journey: Google Haskell at wikipedia GHC at wikipedia GHC ...

best way to write a-> ..->[a] recursive functions in haskell

So I keep having this small problem where I have something like func :: a -> b -> [a] -- # or basically any a-> ...-> [a] where ... is any types -> func x y = func' [x] y -- '# as long as they are used to generate a list of [a] from x func' :: [a] -> b -> [a] func' = undefined -- # situation dependant generates a list from ...

Improve my Haskell implementation of Filter

I have recently been teaching myself Haskell, and one of my exercises was to re-implement the filter function. However, of all the exercises I have performed, my answer for this one seems to me the most ugly and long. How could I improve it? Are there any Haskell tricks I don't yet know? myfilter :: (a -> Bool) -> [a] -> [a] myfilter f ...

How difficult is Haskell multi-threading?

I have heard that in Haskell, creating a multi-threaded application is as easy as taking a standard Haskell application and compiling it with the -threaded flag. Other cases, however, have described the use of a par command within the actual source code. What is the state of Haskell multi-threading? How easy is it to introduce into prog...

Right rotate of tree in Haskell: how is it work?

I don't know haskell syntax, but I know some FP concepts (like algebraic data types, pattern matching, higher-order functions ect). Can someone explain please, what does this code mean: data Tree ? = Leaf ? | Fork ? (Tree ?) (Tree ?) rotateR tree = case tree of Fork q (Fork p a b) c -> Fork p a (Fork q b c) As I understand, first ...