[Haskell-cafe] What magic has the new parallel io manager done to improve performance?
I'm curious about the design and trade offs in IO manager, I can point out two changes that should boost performance: 1. Run an IO manager thread on each capability. 2. Use ONESHOT flag to save a system call. I wonder is there anything else? It must be interesting. -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What magic has the new IO manager done to improve performance ?
I' m curious about the design and trade offs behind the new IO manager. I see two changes from the code: 1. Run IO manager thread on each capability. 2. Use ONESHOT flag to save a system call. Is there other interesting things to know? Is it possible to use epoll's ET mode to save even more system calls? -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What magic has the new parallel io manager done to improve performance?
Sorry for the duplicate post, please ignore this one. On Sunday, February 17, 2013, yi huang wrote: I'm curious about the design and trade offs in IO manager, I can point out two changes that should boost performance: 1. Run an IO manager thread on each capability. 2. Use ONESHOT flag to save a system call. I wonder is there anything else? It must be interesting. -- http://yi-programmer.com/ -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to implement instance of MonadBaseControl IO
On Sat, Aug 25, 2012 at 3:25 AM, Erik Hesselink hessel...@gmail.com wrote: I'm not sure if you already have something working, but we have several in our codebase, all following a similar pattern. For example: newtype GeoServer a = GeoServer { unGeoServer :: ReaderT GeoServerState (ServerPartT IO) a } instance MonadBaseControl IO GeoServer where newtype StM GeoServer a = StMGeoServer { unStMGeoServer :: StM (ReaderT GeoServerState (ServerPartT IO)) a } liftBaseWith f = GeoServer (liftBaseWith (\run - f (liftM StMGeoServer . run . unGeoServer))) restoreM = GeoServer . restoreM . unStMGeoServer Thank you all, i've adapted Chris's code which is similar to yours, and it works now. Erik On Wed, Aug 22, 2012 at 9:16 AM, yi huang yi.codepla...@gmail.com wrote: I have a `newtype Yun a = Yun { unYun :: ReaderT YunEnv (ResourceT IO) a }` , and i need to define an instance of `MonadBaseControl IO` for it. Newtype instance deriving don't work here. I guess the answer is simple, i just can't figure it out, hope anybody can lightening me. Best regards. Yihuang. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to implement instance of MonadBaseControl IO
I have a `newtype Yun a = Yun { unYun :: ReaderT YunEnv (ResourceT IO) a }` , and i need to define an instance of `MonadBaseControl IO` for it. Newtype instance deriving don't work here. I guess the answer is simple, i just can't figure it out, hope anybody can lightening me. Best regards. Yihuang. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cloud Haskell real usage example
On Wed, Aug 22, 2012 at 8:30 AM, Felipe Almeida Lessa felipe.le...@gmail.com wrote: On Tue, Aug 21, 2012 at 9:01 PM, Thiago Negri evoh...@gmail.com wrote: My view of Cloud Haskell usage would be something similar to this: a master node sending work to slaves; slave instances getting up or down based on demand. So, the master node should be slave-failure-proof and also find new slaves somehow. Am I misunderstanding the big picture of Cloud Haskell or doing anything wrong in the following code? (Disclaimer: I can't speak for Cloud Haskell's developers.) AFAIK this is CH's goal. However, they're not quite there yet. Their network implementation is still a lot naive as you're seeing =). I believe this behavior is due to the usage of channel, you just need to implement some kind of timeout function. Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Conduits: Is Source a valid instance of Monad?
On Wed, Apr 4, 2012 at 4:48 AM, Paul Liu nine...@gmail.com wrote: Is there any follow up on this? I was wondering what is the best way to sequence a number of sources together. Anybody gave a further thought on this? I believe sequence sources together can already be done by `Monoid` instance. Regards, Paul Liu On Tue, Dec 27, 2011 at 3:45 PM, Aristid Breitkreuz arist...@googlemail.com wrote: Hi all, As you may have noticed, Michael Snoyman has been working on an alternative approach to I/O, called conduits. You can find it here: https://github.com/snoyberg/conduit When looking at the Source type (explained here: http://www.yesodweb.com/blog/2011/12/conduits), I noticed that they seem to behave like lists, and naturally wondered if I could write a Monad instance for them. But first, let's have a brief look at the definition of Source: data SourceResult a = Open a | Closed data PreparedSource m a = PreparedSource { sourcePull :: ResourceT m (SourceResult a) , sourceClose :: ResourceT m () } newtype Source m a = Source { prepareSource :: ResourceT m (PreparedSource m a) } ResourceT deals with resource acquisition and releasing (making sure that all resources are released), and provides a an abstraction over IORef/STRef. For our purposes here, ResourceT is probably close enough to IO. So now the question again is, can we write a Monad instance for this? I have been able to write join (concatenate) and return (a source with a single non-repeated) element. https://gist.github.com/1525471 I _think_ it behaves properly like a Monad, but I'm not quite sure, and neither was Michael. Greg Weber then suggested bringing the question to this forum. What made the question difficult for me is that this would be a stateful Monad transformer, so I'm not quite sure how to test the Monad laws properly. There's a second part to this question: If Source turns out not to be a Monad, is it possibly a ZipList-like Applicative? And either way, which is more useful: The list-like or the ziplist-like instances (of Applicative/Monad)? Thank you, Aristid ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Regards, Paul Liu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://yi-programmer.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Conduit experiment: Is this correct?
2012/2/3 Michael Snoyman mich...@snoyman.com 2012/2/3 Ertugrul Söylemez e...@ertes.de: Hello there, I'm trying to build a server for testing the conduit and network-conduit packages. As a contrived example the goal is to pick the first three lines from the client and send them back without the line feeds. After that, I'd like to switch to a simple echo server. This is the code: module Main where import Data.Conduit import Data.Conduit.Binary as Cb import Data.Conduit.List as Cl import Data.Conduit.Network handleClient :: Application handleClient src snk = src $$ do (Cb.lines =$= Cl.isolate 3) =$ snk snk main :: IO () main = runTCPServer (ServerSettings 4000 Nothing) handleClient I'm not sure whether it is correct to use the 'snk' sink multiple times, and intuitively I'd say that this is wrong. What would be the proper way to do this? Greets, Ertugrul In this particular case, it will work due to the implementation of snk. In general, however, you're correct: you should not use the same sink twice. Since Sink works in a CPS fashion, by which i mean every step it return a new push close pair, i think it can be used multiple time. I haven't thought about it much yet, but my initial recommendation would be to create a new Conduit using SequencedSink, which takes the three lines and then switches over to a passthrough conduit. The result looks like this: module Main where import Data.Conduit import Data.Conduit.Binary as Cb import Data.Conduit.List as Cl import Data.Conduit.Network handleClient :: Application handleClient src snk = src $$ myConduit =$ snk main :: IO () main = runTCPServer (ServerSettings 4000 Nothing) handleClient myConduit = sequenceSink 3 go where go 0 = return $ StartConduit $ Cl.map id go count = do mx - Cb.lines =$ Cl.head case mx of Nothing - return Stop Just x - return $ Emit (count - 1) [x] Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to print out intermediate results in a recursive function?
You can use trace from Debug.Trace, change the code like this: mergesort l = case trace l l of [] - ... [x] - ... (x:xs) - ... On Sun, Feb 5, 2012 at 2:23 AM, Qi Qi qiqi...@gmail.com wrote: Hello, I have a question;how can I print out the intermediate number lists in a mergesort recursive function like the following one. merge [] ys = ys merge xs [] = xs merge (x:xs) (y:ys) = if x = y then x : merge xs (y:ys) else y : merge (x:xs) ys mergesort [] = [] mergesort [x] = [x] mergesort xs = let (as, bs) = splitAt (length xs `quot` 2) xs in merge (mergesort as) (mergesort bs) main = do print $ mergesort [5,4,3,2,1] In the main function, it only prints out the final number list. But I'd like to print out the number lists in every recursive level. How can I do that? Thanks. -- Qi Qi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comparison Haskell, Java, C and LISP
If i understand correctly, what we called generics is what so called reflection. It allow you to introspect type structure. http://haskell.org/ghc/docs/latest/html/libraries/ghc-prim-0.2.0.0/GHC-Generics.html#g:4 On Wed, Oct 19, 2011 at 12:03 AM, yrazes yra...@gmail.com wrote: Hi, Maybe you remember my case. I was trying to compare some aspects of these languages. Well... I found that I can compare reflection, support for generics, simplicity and safe code. I just want to ask if you have more information for reflection in Haskell. I read that there is no enough for dynamics to support complete reflection. I hope someone can help me this time :) Julita ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] [ANNOUNCE] Haskdogs-0.1
Cabal compains about Unknown build tool hasktags. It seems not necessary to set Build-tools: hasktags in cabal file? On Wed, Sep 14, 2011 at 4:39 AM, Sergey Mironov ier...@gmail.com wrote: Hi! I am pleased to announce haskdogs - project-level ctag file generator. haskdogs is a small shellscript-like tool which creates tag file for entire haskell project directory. It takes into account first-level dependencies by recursively scanning imports and adding matching packages to the final tag list. As a result, programmer can use his/her text editor supporting tags (vim, for example) to jump directly to definition of any standard or foreign function he/she uses. Note, that haskdogs calls some Unix shell commands like test or mkdir so this tool will likely fail to work on pure Windows platforms. To use it, do 0) cabal install hasktags haskdogs mkdir -p ~/.cabal/var/haskdogs 1) cabal unpack TrickyProject-4.2 cd TrickyProject-4.2 2) haskdogs 3) enjoy the tagfile with references to every function http://hackage.haskell.org/package/haskdogs-0.1 Sergey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
On Tue, Jul 26, 2011 at 12:19 PM, yi huang yi.codepla...@gmail.com wrote: Actually, i'm wondering how to do exception handling and resource cleanup in iteratee, e.g. your `writer` iteratee, i found it difficult, because iteratee is designed to let enumerator manage resources. I've found the answer for myself, `catchError` and `tryIO` is for this. here is an example code: http://hpaste.org/49530#a49565 On Sat, Jul 23, 2011 at 2:41 AM, Eric Rasmussen ericrasmus...@gmail.comwrote: Hi everyone, A friend of mine recently asked if I knew of a utility to split a large file (4gb in his case) into arbitrarily-sized files on Windows. Although there are a number of file-splitting utilities, the catch was it couldn't break in the middle of a line. When the standard why don't you use Linux? response proved unhelpful, I took this as an opportunity to write my first program using the enumerator package. If anyone has time, I'm really interested in knowing if there's a better way to take the incoming stream and output it directly to a file. The basic steps I'm taking are: 1) Data.Enumerator.Binary.take -- grabs the user-specified number of bytes, then (because it returns a lazy ByteString) I use Data.ByteString.Lazy.hPut to output the chunk 2) Data.Enumerator.Binary.head -- after using take for the big chunk, it inspects and outputs individual characters and stops after it outputs the next newline character 3) I close the handle that steps 12 used to output the data and then repeat 12 with the next handle (an infinite lazy list of filepaths like part1.csv, part2.csv, and so on) The full code is pasted here: http://hpaste.org/49366, and while I'd like to get any other feedback on how to make it better, I want to note that I'm not planning to release this as a utility so I wouldn't want anyone to spend extra time performing a full code review. Thanks! Eric ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] file splitter with enumerator package
Actually, i'm wondering how to do exception handling and resource cleanup in iteratee, e.g. your `writer` iteratee, i found it difficult, because iteratee is designed to let enumerator manage resources. On Sat, Jul 23, 2011 at 2:41 AM, Eric Rasmussen ericrasmus...@gmail.comwrote: Hi everyone, A friend of mine recently asked if I knew of a utility to split a large file (4gb in his case) into arbitrarily-sized files on Windows. Although there are a number of file-splitting utilities, the catch was it couldn't break in the middle of a line. When the standard why don't you use Linux? response proved unhelpful, I took this as an opportunity to write my first program using the enumerator package. If anyone has time, I'm really interested in knowing if there's a better way to take the incoming stream and output it directly to a file. The basic steps I'm taking are: 1) Data.Enumerator.Binary.take -- grabs the user-specified number of bytes, then (because it returns a lazy ByteString) I use Data.ByteString.Lazy.hPut to output the chunk 2) Data.Enumerator.Binary.head -- after using take for the big chunk, it inspects and outputs individual characters and stops after it outputs the next newline character 3) I close the handle that steps 12 used to output the data and then repeat 12 with the next handle (an infinite lazy list of filepaths like part1.csv, part2.csv, and so on) The full code is pasted here: http://hpaste.org/49366, and while I'd like to get any other feedback on how to make it better, I want to note that I'm not planning to release this as a utility so I wouldn't want anyone to spend extra time performing a full code review. Thanks! Eric ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pointer equality
2011/7/20 Eugene Kirpichov ekirpic...@gmail.com reallyUnsafePointerEq#, and it really is as unsafe as it sounds :) Why is it so unsafe? i can't find any documentation on it. I think always compare pointer first is a good optimization. 20.07.2011, в 7:51, Nikhil A. Patil patil.nik...@gmail.com написал(а): Hi, Is there any way of getting the following code to immediately return True without performing the element-by-element comparison? Essentially this boils down to checking whether pointers are equal before comparing the contents. main = print $ f == f where f = [1..10^9] Thanks!! nikhil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to determine minimal dependency of package
I'm writing my first haskell package, how do i determine the minimal dependency of it, for example, it use Data.Data, how do i know which version of base package first introduce Data.Data module, i can't find the answer with google. -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] compare iteratee with python's yield
I just read several tutorials on iteratee, i find that iteratee is similar to python's generator, both allow streamlined data processing. For example, i can implement enumFile and printChunks in python like this: EOF = None def enum_file(bufsize, filename): with open(filename) as input: while True: data = input.read(bufsize) if not data: break yield data yield EOF def print_chunks(print_empty, generator): for chunk in generator: if chunk==EOF: print 'EOF' return if len(chunk)==0 and not print_empty: continue print chunk print_chunks(True, enum_file(2, data)) But i find iteratee far more complicated than python's generator, is that because iteratee can do something python's generator can't, or i simply need to be more familar with functional programming style. -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Is there Functor instance of Enumerator'
Say i want to compose Enumerator ByteString m b and Iteratee Builder m b, so I try to transform the enum to Enumerator Builder m b, providing function ByteString - Builder. It's like implement a Functor instance for Enumerator. But i failed, there are no way to make type system happy. Am I right that there is no Functor instance of Enumerator? -- http://www.yi-programmer.com/blog/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe