Re[2]: [Haskell-cafe] memory issues
Hello Don, Saturday, February 28, 2009, 2:18:37 AM, you wrote: > offset :: !Integer oh yes > And possibly just using {-# UNPACK #-}!Int64 would be ok? i think that it will be even better but main problem is a huge unevaluated thunks. as the last hope, this may be converted to x <- getOffsets y <- getSizes x z <- sort y also, "zipWith (Block) offsets sizes" and getSizes may be combined to make only one pass through data (although it's not highly important since sort anyway will need them all). really good technique would be to use some sort of heap to hold only 10-100 largest page sizes btw, data Block = Block { size::Integer , offset::Integer } deriving (Ord) allows to omit instance Ord Block definition -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] memory issues
Hello Daniel, Saturday, February 28, 2009, 3:10:44 AM, you wrote: >> print may waste a lot of time, locking stdout for every >> line printed > hout <- openFile (args!!1) WriteMode > mapM_ (hPrint hout) $ sort $ blocks content > ? I find hardly any difference, though. no difference. if handle is locked for every output operation - both versions will be equivalent. if not - they also will be equivalent :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] memory issues
Hello Daniel, Saturday, February 28, 2009, 6:20:09 PM, you wrote: > But they would not be equivalent if stdout has to be locked for each output > operation separately, but a file opened with openFile fp WriteMode was > locked then once and remained so until closed. ghc Handles are locked for every operation, not for entire file lifetime. it's done in order to make safe concurrent operations in threads of the same program -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How to work with date?
Hello Jon, Monday, March 2, 2009, 2:22:55 PM, you wrote: > take 10 $ map (addDays (-1)) $ repeat $ utctDay $ zonedTimeToUTC now take 10 $ iterate (addDays (-1)) $ utctDay $ zonedTimeToUTC now -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Assignment of grayCode
Hello Neil, Monday, March 2, 2009, 2:53:04 PM, you wrote: > That seems a reasonable description, but without checking with the > person who set the test, you may never know for sure. I personally > can't see any difference between your second version and the original > question... he probably thinks that if the things are the same forever, then grayCode function sshouldn't return different answers for different params :) starting university courses with imperative programming languages is evil! :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help optimizing memory usage for a program
Hello Manlio, Monday, March 2, 2009, 6:30:51 PM, you wrote: > The process-data-1 program parse the entire dataset using about 1.4 GB > of memory (3x increment). > This is strange. > The memory required is proportional to the number of ratings. > It may be IntMap the culprit, or the garbage collector than does not > release the memory to the operating system (or, worse, does not > deallocate all used temporary memory). ghc has 2 garbage collectors. first is copying, usied by default (because it's faster): when previously allocated memory block overflows, it collects used data by copying them into *new* data block allocated from OS and then use old data block to satisfy further memory requests. let's calculate. if at GC moment your program has allocated 100 mb of memory and only 50 mb was not a garbage, then memory usage will be 150 mb another GC is compacting one - it's about 2x slower, but collects data in-place. moreover, you may set up"growing factor". with a g.f. of 1.5, for example, memory will be collected once heap will become 1.5x larger than real memory usage after last GC. this effectively guarantees that memory overhead will never be over this factor look at GHC manual, RTS switches section. and last - GHC never returns memory to the OS, there should be ticket on this -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] help optimizing memory usage for a program
Hello Manlio, Monday, March 2, 2009, 8:16:10 PM, you wrote: > 1) With default collection algorithm, I have: > 2) With -c option: > So, nothing changed. you should look into +RTS -s stats. those 409 vs 418 mb is just somewhat random values, since GCs in those 2 inviocations are not synchronized. you should run program severaltimes with various sized datasets. and take a look into other RTS options, i think it would be better to fix heap size so that you will have maximum performance for the given amount of memory used. also try to make -A option close to L2 cache size -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] help optimizing memory usage for a program
Hello Manlio, Monday, March 2, 2009, 8:16:10 PM, you wrote: > By the way: I have written the first version of the program to parse > Netflix training data set in D. > I also used ncpu * 1.5 threads, to parse files concurrently. > However execution was *really* slow, due to garbage collection. > I have also tried to disable garbage collection, and to manually run a > garbage cycle from time to time (every 200 file parsed), but the > performance were the same. may be it will be better to use somewhat like MapReduce and split your job into 100-file parts which are processed by ncpu concurrently executed scripts? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] help optimizing memory usage for a program
Hello Kenneth, Monday, March 2, 2009, 11:14:27 PM, you wrote: > I think my approach is turning out better because I'm: > - building up the IntMap using 'empty' and 'insert', instead of > combining 17,770 'singleton' IntMaps >(which probably results better GC behavior) i don't read into details, but may be it will be better to use sort-and-group approach? OTOH, this makes interesting usecase for mapreduce technologies -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] help optimizing memory usage for a program
Hello Austin, Monday, March 2, 2009, 11:51:52 PM, you wrote: >> let's calculate. if at GC moment your program has allocated 100 mb of >> memory and only 50 mb was not a garbage, then memory usage will be 150 >> mb > ? A copying collector allocates a piece of memory (say 10mb) which is > used as the heap, and only one *half* of it ever has data in it. When if you interested, i suggest you to run any memory-eater with +RTS -S switch. it's somewhat hard to decrypt, but finally you will see what i said. let's imagine that you have 10mb heap at moment of GC, and only 7 mb are live. when doing GC, ghc copies live data into new blocks allocated from the OS. so after GC program will occupy 10+7 mb. ghc can't return memory back to the OS, so it uses those 10 mb to fulfill further memory requests. as a result, next GC will occur when 17 mb will be consumed you have described some fixed-pool scheme which is probably simplified description of idea don't taking into account dynamic poll growth -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] interaction between ghci and cudaBLAS library
Hello Don, Tuesday, March 3, 2009, 5:22:46 AM, you wrote: > GHCi doesn't use the threaded runtime though. So given that: Don, afair ghci compiled using threaded runtime since 6.6: Prelude> :m Control.Concurrent Prelude Control.Concurrent> rtsSupportsBoundThreads True -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] possible memory leak in uvector 0.1.0.3
Hello Manlio, Tuesday, March 3, 2009, 1:10:48 PM, you wrote: > It *is* a problem with IntMap. > I have changed the program to not use any array concatenation, and it > still requires a lot of memory. it may be problem with something else. in particular, check that you don't have lazy thunks stored instead of values > Does esist a data structure that is able to store something like 480189 > keys with efficient memory usage? data.hashtable. at least, i can calculate its memory usage - it should be less than 100 bytes per key even with collecting GC. plus memory required for values ...but intmap should be the same. i still think that you have unforced thunks stored in map -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] possible memory leak in uvector 0.1.0.3
Hello Manlio, Tuesday, March 3, 2009, 5:35:33 PM, you wrote: > There are 100,000,000 ratings, so I create 100,000,000 arrays containing > only one element. every array needs ~30 bytes - it's a minimal memory block ghc can alloc for variable-sized objects. multiple this by 3 to account for copying GC behavior -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] possible memory leak in uvector 0.1.0.3
Hello Daniel, Tuesday, March 3, 2009, 5:47:36 PM, you wrote: >>let v = map singleton' $ ratings contents >>let m = foldl1' (unionWith appendU) v >>v `seq` return $! m > The (v `seq` ) is completely useless. > Maybe > (size m) `seq` return m > would help? i suggest return $! length v return $! size m (if size really scans tree instead of using stored value :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Threading and Mullticore Computation
Hello mwinter, Tuesday, March 3, 2009, 8:09:21 PM, you wrote: >anybody give me an idea what I am doing wrong? 1. add -O2 to compile command 2. add +RTS -s to run commands your program execution time may be dominated by GCs -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Threading and Mullticore Computation
Hello mwinter, Tuesday, March 3, 2009, 8:31:12 PM, you wrote: not same :) when you perform two computations at the same time, you have 2x more memory allocated that means that each GC will need more time. and don't forget that GC is single-threaded > In both runs the same computations are done (sequentially resp. > parallel), so the gc should be the same. But still using 2 cores is > much slower than using 1 core (same program - no communication). > On 3 Mar 2009 at 20:21, Bulat Ziganshin wrote: >> Hello mwinter, >> >> Tuesday, March 3, 2009, 8:09:21 PM, you wrote: >> >> >anybody give me an idea what I am doing wrong? >> >> 1. add -O2 to compile command >> 2. add +RTS -s to run commands >> >> your program execution time may be dominated by GCs >> >> >> -- >> Best regards, >> Bulatmailto:bulat.zigans...@gmail.com > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Threading and Mullticore Computation
Hello Andrew, Tuesday, March 3, 2009, 9:21:42 PM, you wrote: > I just tried it with GHC 6.10.1. Two capabilities is still slower. (See > attachments. Compiled with -O2 -threaded.) i don't think so: Total time4.88s ( 5.14s elapsed) Total time7.08s ( 4.69s elapsed) so with 1 thread wall clock time is 5 seconds, with 2 thread wall time is 4.7 seconds cpu time spent increased with 2 threads - this indicates that you either use hyperthreaded/SMT-capable cpu or speed is limited by memory access operations so, my conclusion - this benchmark limited by memory latencies so it cannot be efficiently multithreaded -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Mystified by Cabal
Hello Colin, Saturday, March 7, 2009, 8:30:43 PM, you wrote: > >> Data/Tree/Game/Tree.hs:1:0: Failed to load interface for > >> `Prelude': it is a member of package base-3.0.3.0, which > >> is hidden > build-depends: base >= 4 and which ghc version you are running? :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] serializing large data structures, stack overflow
Hello friggin, Saturday, March 7, 2009, 10:57:04 PM, you wrote: > dec = B.decodeFile "C:/users/saftarn/desktop/bintest.txt" >>= \a -> > return $ (a :: M.Map (Int,Int) Int) just a quick style hack: dec = B.decodeFile "C:/users/saftarn/desktop/bintest.txt" :: IO (M.Map (Int,Int) Int) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Holumbus-MapReduce 0.0.1
Hello Stefan, Sunday, March 8, 2009, 4:47:25 PM, you wrote: > Wedel, Germany, I have developed a library for building distributed > MapReduce systems in Haskell. > Holumbus-Distribution consists of modules and tools for the > implementation of distributed systems in general. > Holumbus-Storage is designed to build a distributed storage system which beautiful!!! i think these are sort of things where haskell will really shine and which now is covered by Erlang, Java and other languages hardly compared to Haskell -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Logo Preferences
Hello Sebastian, Monday, March 9, 2009, 1:08:50 PM, you wrote: i think we should make 2-stage voting, like in F1 after 1st stage we will know which logos are most popular and therefore are real candidates, so we can select among them > On Sun, Mar 8, 2009 at 11:19 PM, Ashley Yakeley wrote: > > Eelco Lempsink wrote: > > The list with options can be found here (for now): > http://community.haskell.org/~eelco/poll.html Notice that some > (very) similar logos are grouped as one option (thanks to Ian > Lynagh) All submissions compete, so that still makes more than a 100 options! > > The voting system we'll use is the Condorcet Internet Voting System > (http://www.cs.cornell.edu/andru/civs.html). > So ranking all 100+ items on the Condorcet ballot is a bit of a > daunting task. However, if we get a rough idea of the favourites, we > can each cut down a bit on the work. > > For instance, suppose 82 and 93 are very popular. You might not > like either of them, but it's worth ranking them on your ballot > (after the ones you do like) if you have a preference between them. > But there's less need to rank the ones no-one likes. > > > > I'm pretty sure this is precisely how the system works. You bring > the ones you care about to the top and rank them, and everything > else shares a rank at the bottom (or you could pick a few of those > that you really dislike and put them even lower than the default > rank). But the point is that you shouldn't need to rank every single > logo, just the ones you care about and then you leave the rest at the default > rank. > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] Logo Preferences
Hello Sebastian, Tuesday, March 10, 2009, 1:08:38 AM, you wrote: > It just seems like duplicated work to me. They're still few enough > that I can scan through them and multi-select the ones I like and > then click "move to top" in a pretty short amount of time (and then refine > the ranking if I care). and if none of them will be among 10 most popular - it is no difference for you which one will be finally selected? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Microsoft PhD Scholarship at Strathclyde
Hello Conor, Tuesday, March 10, 2009, 6:59:58 PM, you wrote: > {- > -- Haskell Types with Numeric Constraints > -} are you have in mind integrating results into production ghc versions? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Don, Tuesday, March 10, 2009, 10:40:30 PM, you wrote: >> I think uvector only works with certain types that can be >> unboxed, while storablevector works with all types that >> instantiate Foreign.Storable.Storable. I don't know about >> vector. From the description of vector, I have the > That's interesting. I'd expect Storable and UA to have the same set of > inhabitants. Is there any difference? if uavector use ghc's built-in unboxed array operations (as Data.Array.Unboxed does) then it's necessarily bounded to types supported by those operations btw, i have extended this set in my own library by making a class which has implementation using those operations but may be extended further. OTOH, nowadays when ForeignArrays becomes as fast as built-in ones, i don't see any reasons for these built-in operations at all -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Don, Tuesday, March 10, 2009, 11:01:31 PM, you wrote: >> if uavector use ghc's built-in unboxed array operations (as >> Data.Array.Unboxed does) then it's necessarily bounded to types >> supported by those operations > And what is Storable limited to? > Ultimately they're all limited to the primops for reading and writing, the full story: ghc up to 6.6 has slow access to ForeignArrays, as you may recall therefore, those primitives was added. ByteArra# plus those primitives was the only way to have unboxed arrays with fast access starting with 6.6, ForeignArray access is no-op, so we can just use obvious Ptr operations (via Storable class) to get unboxed arrays fast access. so, no more need for those special ByteArray# access operations but Array library still old, so any effort based on its spources, got the same restrictions also, ByteArray# may be unpinned, but afaik, this isn't really important - it can be coerced to Ptr for the period of one operation -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Xiao-Yong, Tuesday, March 10, 2009, 11:52:50 PM, you wrote: > So it's me who understand it wrong. If I want some high > performance array with elements of custom data type, I'm > stuck with Array, anyway? ForeignArray will be the best here. just make you type instance of Storable. if you need *movable* arrays, you will have to implement your own array datatype or use ArrayRef library and declare your type as instance of Unboxed -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Don, Wednesday, March 11, 2009, 12:12:07 AM, you wrote: > Right, so my point stands: there's no difference now. If you can write a > Storable instance, you can write a UA et al instance. yes, if there is some class provided for this and not just hard-coded 4 or so base types > And GHC 6.6 was released what, 11 October 2006? So this has been the > case for a long time. unfortunately, Array library unboxed arrays still aren't based on any Unboxable *class* -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Xiao-Yong, Wednesday, March 11, 2009, 12:28:45 AM, you wrote: > It goes beyond my current knowledge, now. How do you define > a custom data type as an instance of UA or Storable? just look at existing instances. basically, for complex data type, you just use instances for its basic types, plus you need to calculate offset of second and following fields (using sizeOf in Storable class) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Don, Wednesday, March 11, 2009, 12:48:35 AM, you wrote: >> unfortunately, Array library unboxed arrays still aren't based on any >> Unboxable *class* > Hmm. Aren't all the array library types based on MArray and IArray? > So I can define my own say, new STUArray element type by writing an instance > of > MArray for it. Like so: yes, you can, just this definition duplicates too much code -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString in patterns
Hello Manlio, Wednesday, March 11, 2009, 1:28:13 AM, you wrote: > Using normal String type I can define a pattern like: > But if I want to use ByteString, what should I do? > This seems impossible, since ByteString data constructor is not available. for numeric types, it works via Num instances. we have now IsString type, may be it provides the same feature? i.e., are you tried? :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generics Versus Parametric Polymorphism
Hello Mark, Wednesday, March 11, 2009, 9:11:42 AM, you wrote: > Just wondering if Generics and Parametric polymorphism are one and the same > in Haskell. haskell Parametric polymorphism is the same type of thing as Java Generics :) haskell Generics provides ability to define procedures polymorphic by *any* data type with just a fixed number of definitions there are at least dozen of various tools/libraries supporting Generics in some way in haskell, so indeed we are interested to have at least one with guaranteed availability google for "scrap your boilerplate" paper for a description of one of the most popular Generics implementation -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Generics Versus Parametric Polymorphism
Hello porges, Wednesday, March 11, 2009, 12:35:18 PM, you wrote: > Most importantly (or awesomely?), every time Haskell infers the > type of a function you've written, you get *the most generic possible* > version, for free :) and using generics, you can get function polymorphic on *any* type just for few pennies more :))) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Against cuteness
Hello Gregg, Wednesday, March 11, 2009, 1:17:41 PM, you wrote: > are not O'Reilly. Of all the billions of images from all the > cultures in the world available to us we can surely find something > that is witty or charming without being cute. it will not be fun :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Sugestion for a Haskell mascot
Hello Wolfgang, Wednesday, March 11, 2009, 1:06:37 PM, you wrote: >> Hehe, I love it. Sloth is a synonym for Lazyness in English too, and >> they're so freaking cute... :) > Same in German: The german “Faultier” means “lazy animal”. russian too, if that matter. i was really amazed by this idea. pure, lazy and fun! :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get program command line arguments in Unicode-aware way (Unix/Linux)?
Hello Dimitry, Thursday, March 12, 2009, 5:42:14 AM, you wrote: depends on your OS. for windows i use this code: myGetArgs = do alloca $ \p_argc -> do p_argv_w <- commandLineToArgvW getCommandLineW p_argc argc <- peek p_argc argv_w <- peekArray (i argc) p_argv_w mapM peekTString argv_w >>== tail foreign import stdcall unsafe "windows.h GetCommandLineW" getCommandLineW :: LPTSTR foreign import stdcall unsafe "windows.h CommandLineToArgvW" commandLineToArgvW :: LPCWSTR -> Ptr CInt -> IO (Ptr LPWSTR) note that it doesn't skip over +RTS sections. btw, i plan to make unicode-aware version of System.Directory module to solve all these problems > I am trying to process command line arguments that may contain Unicode > (cyrillic in this example) characters. > The standard GHC's getArgs seems to pass whatever was obtained from > the underlying C library > without any regard to encoding, e. g the following program (testarg.hs): > module Main where > import System.Environment > main = do > x <- getArgs > mapM (putStrLn . show) x > being invoked (ghc 6.10.1) > runghc testarg -T 'при<в>ет' > prints the following: > "-T" > "\208\191\209\128\208\184<\208\178>\208\181\209\130" > (not correct, all bytes were passed without proper encoding) > Is there any way to get program arguments in GHC Unicode-aware? Or at > least assuming that they are always in UTF-8? > Something like System.IO.UTF8, but for command line arguments? > Thanks. > PS: BTW runhugs testarg -T 'при<в>ет' prints: > "-T" > "\1087\1088\1080<\1074>\1077\1090" > which is correct. -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Sugestion for a Haskell mascot
Hello Jon, Thursday, March 12, 2009, 12:49:35 PM, you wrote: > I think using it as a mascot is a bad idea: "Haskell is so > slow, they even chose a sloth as the mascot". and it will be absolute truth :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Re: Sugestion for a Haskell mascot
Hello Satnam, Thursday, March 12, 2009, 1:08:58 PM, you wrote: > Perhaps this is just an indication of my dark and violent side, but > choosing an animal with a killer instinct might be a better idea. A > creature that would eat something small and furry as a mid afternoon snack why not choose Hitler or Mao? this will clearly indicate our intentions :D -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] bytestring vs. uvector
Hello Don, Friday, March 13, 2009, 8:08:57 PM, you wrote: >> What is the reason why you have decided to use unpinned arrays >> (ByteArray#) instead of pinned arrays (Foreign.Ptr)? > They prevent heap fragmentation (and in general are faster). you probably mean faster alloc/gc operations, everything else should be the same -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to catch error in array index when debugging
Hello Colin, Saturday, March 14, 2009, 11:39:41 AM, you wrote: > I'm getting a runtime failure "Error in array index". This causes ghci > to exit. > Is there a way to get it to break instead, so I can find out which > function is failing? i recall two techniques - one is trivially define your own (!) and print index at least. another is to use ghc profiling with -xc RTS option -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Are there performant mutable Arrays in Haskell?
Hello Matthias, Thursday, March 19, 2009, 2:16:30 PM, you wrote: 1. use ghc -O2 2. use unsafeRead/WriteArrray 3. check that all calculations (step*, li/ri) are strict > Hey There, > I am trying to write a hash-algorithm that in fact is working, but > as you might have guessed the problem is the performance :) At the > moment I am 40 times worse than the same implementation in C. > My problem is, I need mutable arrays which are the heart of that hash. > The algorithm is round-based and within each round I need the value > of certain positions in that array. > At the moment I work with an unboxed ST-Array at the crucial part > --- snip --- > test list = runSTUArray $ do > a_arr <- newListArray (0, 1752) list > let round i = do > ain <- readArray a_arr (i-n) > at0 <- readArray a_arr (i-t0) > at1 <- readArray a_arr (i-t1) > at2 <- readArray a_arr (i-t2) > at3 <- readArray a_arr (i-t3) > at4 <- readArray a_arr (i-t4) > let li = ls $ (i - n) mod 16 > ri = rs $ (i - n) mod 16 > writeArray a_arr i $ (step4 li) >. (step3 ri) >. (step2 at1 at2 at3 at4) >$ (step1 ain at0 i) > mapM_ round [n..(n+t-1)] > return a_arr > --- snap --- > I also played around with peekElemOff and pokeElemOff, but this isn't much > faster. > It took ~30sec with my Haskell-Code while the C-implementation need only > ~1sec. > Is there someone who may have some hints for me, what I can do better, or just > lead me in the right direction? :) > Thanks a lot in advance > -- Matthias > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[2]: [Haskell] ANNOUNCE: jhc 0.6.0 Haskell Compiler
Hello sylvain, Thursday, March 19, 2009, 2:16:06 AM, you wrote: > Something is wrong: how can Haskell be faster than C? 1. you measure efficiency of libs, not compilers 2. don't forget about -O2/-O3 -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Editing Haskell wiki pages
Hello Colin, Friday, March 20, 2009, 9:18:59 AM, you wrote: > How am I supposed to edit a page on the Haskell wiki? > If I click on an "Edit this page" link, then Firefox prompts me to > choose a tool to open an application/x-external-editor. When i just it should be a problem with your config, i just tried with ff 3.0.7/win32 - it edits fine. nothing was specially configured for this behaviour -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Ease of Haskell development on OS X?
Hello Jeff, Friday, March 20, 2009, 10:22:35 PM, you wrote: > As this continues to build, I guess the issue for me, and I'm willing > to help with it, is trying to figure out how to redistribute programs > written with gtk2hs. on Windows, people can just install the gtk2hs > libraries via the installer -- although this does bork a little > because it assumes you have a haskell compiler on the machine. > Ignoring the errors, however, works. i distribute my gtk2hs program for windows and linux. no problems, i just included runtime libraries provided by gtk2hs team. it was with gtk2hs 0.9.12.1 though, may be they don't provided updated archive for newer gtk2hs versions? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Ease of Haskell development on OS X?
Hello Don, Saturday, March 21, 2009, 12:06:48 AM, you wrote: >> i distribute my gtk2hs program for windows and linux. no problems, i >> just included runtime libraries provided by gtk2hs team. it was with >> gtk2hs 0.9.12.1 though, may be they don't provided updated archive for >> newer gtk2hs versions? > Awesome! Do you have a URL? http://freearc.org btw, it have 35.000 downloads ATM -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ACM Task for C++ and Java programmers in Haskell. How to make code faster?
Hello Vasyl, Sunday, March 22, 2009, 8:25:02 PM, you wrote: i believe that i already seen this problem here a few years ago :) what search structure you was used? i think that immutable hash (represented as array of lists) would be useful here > Hi! > Recently I've found interesting ACM research on C++ and Java efficiency. > This task also was been solved on lisp/scheme and is described on > http://www.flownet.com/ron/papers/lisp-java/ > I tried to solve this task on Haskell but stuck with efficiency > problems (approx in 1000 times slower and takes 20 times more memory). > I hope > the approach, I've used is correct and problem with data structures > and implementation. It took more than 81% of time for garbage > collection. I tried to use ByteStrings instead of Strings, but > unfortunately it didn't help. > The entire code I placed on > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2764 > The original instructions are on: > http://www.flownet.com/ron/papers/lisp-java/instructions.html > Dictionary file could be downloaded from: > http://www.flownet.com/ron/papers/lisp-java/dictionary. > Input data: http://www.flownet.com/ron/papers/lisp-java/input.txt > Expected output: > http://www.flownet.com/ron/papers/lisp-java/output.txt > Could someone help me to make this code faster? I'd like to see > solution that will be elegant and fast, without heavy optimizations, > that will make code unreadable. Also, if it possible, prepare the > program to support SMP parallelism. > Very thanks in advance. Hope you'll enjoy this task :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Equations for `foo' have different numbers of arguments
Hello Manlio, Tuesday, March 24, 2009, 5:44:14 PM, you wrote: > divide _ 0 = error "division by 0" > divide = (/) > Equations for `divide' have different numbers of arguments you should write divide a b = a/b -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] The votes are in!
Hello Andrew, Tuesday, March 24, 2009, 6:29:18 PM, you wrote: then it was thoughtcrime and that sort of things even more dangerous for State! > He ONCE used unsafeInterleaveIO, but he never evaluated it, and never tried > it again! > 2009/3/24 Brandon S. Allbery KF8NH > > On 2009 Mar 24, at 8:29, John Van Enk wrote: > Is this the part where all the pundits come out and talk about how > Jeff isn't a citizen, eats babies, and wants to turn Haskell into an > imperative language? > "He uses unsafeInterleaveIO!" > > > > -- > brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com > > system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu > > electrical and computer engineering, carnegie mellon university KF8NH > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] g++ std:map vs GHC IntMap
Hello Manlio, Thursday, March 26, 2009, 6:39:12 PM, you wrote: > The test consists in adding 1000 elements to an empty map. +RTS -c -F1.1 then read about garbage collection -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] g++ std:map vs GHC IntMap
Hello Manlio, Thursday, March 26, 2009, 8:17:03 PM, you wrote: > So, now memory required is about the same as the C++ version, but how > can I optimize memory usage without having to tweak the garbage collector? C++ doesn't use GC so why you compare? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] g++ std:map vs GHC IntMap
Hello Don, Thursday, March 26, 2009, 8:26:18 PM, you wrote: >>> +RTS -c -F1.1 >> It now requires 386 MB of memory, but is 4.7 times slower. >> >> So, now memory required is about the same as the C++ version, but how >> can I optimize memory usage without having to tweak the garbage >> collector? > You'll need similar data structures. can +RTS -A400m be consider as "similar data structure" ? :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A bit of a shock - Memoizing functions
Hello Gü?nther, Friday, March 27, 2009, 11:30:41 PM, you wrote: > Some of the memoizing functions, they actually "remember" stuff > *between* calls? what i've seen in haskell - functions relying on lazy datastructures that ensure computation on first usage so this looks exactly like as memoizing: power 2 n | n>=0 && n<100 = powersOfTwo!n power x y = x^y powersOfTwo = array (0,99) [2^n | n <- [0..99] ] it's almost exact definition from ghc Prelude -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: logfloat 0.12.0.1
Hello wren, Saturday, April 4, 2009, 2:51:39 AM, you wrote: > On GHC 6.10 the use of -fvia-C had to be disabled because it conflicts > with the FFI (version 0.12.0.0 still used it, which is fine on GHC 6.8). > I'm still investigating the use of -fasm and getting proper benchmarking > numbers. Contact me if you notice significant performance degradation. isn't this the same bug as in recent thread "[Haskell-cafe] Possible floating point bug in GHC?" ? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] System.Process.Posix
Hello Cristiano, Sunday, April 5, 2009, 12:05:02 AM, you wrote: > Is it me or the above package is not included in Hoogle? afair, Neil, being windows user, includes only packages available for his own system there was a large thread a few months ago and many peoples voted for excluding any OS-specific packages at all since this decreases portability of code developed by Hoogle users :))) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Questions about slow GC with STArray
Hello FFT, Monday, April 6, 2009, 11:07:33 AM, you wrote: > this problem addressed there? Why is this supposed to be specific to > boxed arrays only: wouldn't GC have to scan the whole mutable array > whether it's boxed or unboxed? you need to scan only boxes: if array just contains plain cpu-level numbers, there is nothing to scan one way to solve this problem is to make one `modified` bit per each 256 elements rather than entire array so GC will have to scan only modified chunks -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Questions about slow GC with STArray
Hello Dan, Monday, April 6, 2009, 12:35:14 PM, you wrote: > the size of the sub-array. The test then fills a 10 million element array. > However, something about the benchmark makes it perform poorly for both small > chunks and large chunks. -sstderr reports that lots of copying occurs for > small chunk sizes, and I haven't bothered to figure out why this is the case. > You can, however, see that marking dirty chunks in this fashion would be > profitable. The un-chunked array takes around a minute here, while with chunks > of 10,000 (which seems to be about the optimal value with the above copying > tradeoff), it takes about 6 seconds, and that's still with 60+% GC time. i don't think that 60% GC time is bad for *this* benchmark. array filling is very trivial operation, after all. important part is 10x GC times reduce, apply these numbers to original benchmark -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Questions about slow GC with STArray
Hello FFT, Monday, April 6, 2009, 12:32:53 PM, you wrote: >> you need to scan only boxes: if array just contains plain cpu-level >> numbers, there is nothing to scan > Are those the only legal contents of STUArray? numbers, chars, vanilla pointers. UArray just mimics C arrays, after all -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] Questions about slow GC with STArray
Hello FFT, Monday, April 6, 2009, 12:56:51 PM, you wrote: >>> Are those the only legal contents of STUArray? >> >> numbers, chars, vanilla pointers. UArray just mimics C arrays, after all >> > I haven't gotten to learning about them in detail yet, but my hope was > that STUArray was like vector in C++, and STArray was like > vector. Both are fairly general. well, that's good comparison for some degree, but the catch is that Haskell doesn't have unboxed types at all. therefore, [ST]UArray is something that you can't implement in pure Haskell, it's just like providing API to some C arrays. they are implemented via special operations in GHC runtime that are limited to support only numbers/chars/pointers. so you can't have UArray of Complex numbers (although you can use two array of Doubles of course) UArray is rather old thing, nowadays you may use StorableArray or one of many newer array/vector libraries. unfortunately, they tend to don't support ST monad, so you will need to write a little wrappers using unsafeIOtoST operation > So if I need a array of complex numbers in Haskell, will I need an > extra level of indirection compared to C? And in addition to that some > serious issues with GC speed if those arrays need to be mutable? [1] http://haskell.org/haskellwiki/Library/ArrayRef [2] http://www.haskell.org/haskellwiki/Storable_Vector recent cafe threads http://www.haskell.org/pipermail/haskell-cafe/2008-July/045229.html http://www.haskell.org/pipermail/haskell-cafe/2009-March/057240.html -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 2:25:12 PM, you wrote: > The problem I'm trying to solve is running system commands in > parallel. "system commands" means execution of external commands or just system calls inside Haskell? > Running a benchmark of issuing 1 million trivial tasks (create, > modify, read and IO ref) the version without any parallelism is really > fast (< 0.1 sec), and the version with parallelism is slow (> 10 sec). > This could be entirely due to space leaks etc when queueing many > tasks. i think it's just because use of MVar/Chan is much slower than IORef activity. once i checked that on 1GHz cpu and got 2 million withMVar-s per second i don't understood exactly what you need, but my first shot is to create N threads executing commands from channel: para xs = do done <- newEmptyMVar chan <- newChan writeList2Chan chan (map Just xs ++ [Nothing]) replicateM_ numCapabilities $ do forkIO $ do forever $ do x <- readChan chan case x of Just cmd -> cmd Nothing -> putMVar done () takeMVar done -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[2]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 6:13:29 PM, you wrote: > Calls to System.Cmd.system, i.e. running external console processes. > It's a make system I'm writing, so virtually all the time is spent in > calls to ghc etc. > To Bulat: I should have been clearer with the spec. The idea is that > multiple calls to paralell_ can execute, and a function executing > inside parallel_ can itself call parallel_. For this reason I need one > top-level thread pool, which requires unsafePerformIO. If I create a > thread pool every time, I end up with more threads than I want. this is smth new to solve i propose to use concept similar to Capability of GHC RTS: we have one Capability provided by thread calling para and N-1 Capabilities provided by your thread pool. all that we need is to reuse current thread Capability as part of pool! para xs = do sem <- newQSem for xs $ \x -> do writeChan chan (x `finally` signalQSem sem) tid <- forkIO (executing commands from chan...) waitQSem sem killThread tid instead of killThread we really should send pseudo-job (like my Nothing value) that will led to self-killing of job that gets this signal this solution still may lead to a bit more or less than N threads executed at the same time. your turn! -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[3]: Parallel combinator, performance advice
Hello Bulat, Tuesday, April 7, 2009, 6:50:14 PM, you wrote: > tid <- forkIO (executing commands from chan...) > waitQSem sem > killThread tid > instead of killThread we really should send pseudo-job (like my > Nothing value) that will led to self-killing of job that gets this > signal > this solution still may lead to a bit more or less than N threads > executed at the same time. your turn! solved! every job should go together with Bool flag `killItself`. last job should have this flag set to True. thread will execute job and kill itself if this flag is True. so we get strong guarantees that there are exactly N threads in the system: para xs = do sem <- newQSem for (init xs) $ \x -> do writeChan chan (x `finally` signalQSem sem, False) writeChan chan (last x `finally` signalQSem sem, True) -- tid <- forkIO $ do let cycle = do (x,flag) <- readChan chan x unless flag cycle cycle -- waitQSem sem btw, this problem looks a great contribution into "Haskell way" book of exercises -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[2]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 6:13:29 PM, you wrote: > Consider a thread pool with 2 threads and the call parallel_ [parallel_ > [b,c],a] > You get the sequence: > enqueue (parallel_ [b,c]) > a > wait on parallel_ [b,c] > While you are executing a, a thread pool starts: > enqueue b > c > wait for b > Now you have all the threads waiting, and no one dealing with the > thread pool. This results in deadlock. i think the only way to solve this problem is to create one more thread each time. let's see: on every call to para you need to alloc one thread to wait for jobs completion. so on each nested call to para you have minus one worker thread. finally you will eat them all! so you need to make fork: one thread should serve jobs and another one wait for completion of this jobs bucket. and with killItself flag you will finish superfluous thread JIT -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[2]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 6:13:29 PM, you wrote: > Calls to System.Cmd.system, i.e. running external console processes. > It's a make system I'm writing, so virtually all the time is spent in > calls to ghc etc. btw, if all that you need is to limit amount of simultaneous System.Cmd.system calls, you may go from opposite side: wrap this call into semaphore: sem = unsafePerformIO$ newQSem numCapabilities mysystem = bracket_ (waitQSem sem) (signalQSem sem) . system and implement para as simple thread population: para = mapM_ forkIO -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[4]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 7:33:25 PM, you wrote: >> How about using unsafeInterleaveIO to get a lazy suspension of the result of >> each action, >> and then using par to spark off each of them? If that works you can reuse >> the existing >> task-parallel system of GHC to do the heavily lifting for you, instead of >> having to write your >> own. > par is likely to spark all the computations, and then switch between > them - which will mean I've got more than N things running in > parallel. par/GHC RTS limits amount of Haskell threads running simultaneously. with a system call marked as safe, Capability will be freed while we execute external program so nothing will be limited except for amount of tasks *starting* (as opposite to running) simultaneously :))) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[4]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 7:33:25 PM, you wrote: > parallel_ (x1:xs) = do > sem <- newQSem $ 1 - length xs > forM_ xs $ \x -> > writeChan queue (x >> signalQSem sem, False) > x1 > addWorker > waitQSem sem > writeChan queue (signalQSem sem, True) > waitQSem sem > Where the second flag being True = kill, as you suggested. I think > I've got the semaphore logic right - anyone want to see if I missed > something? Neil, executing x1 directly in parallel_ is incorrect idea. you should have N worker threads, not N-1 threads plus one job executed in main thread. imagine that you have 1000 jobs and N=4. that you will got here is 3 threads each executed 333 jobs and 1 job executed by main thread so you still need to detach one more worker job and finish it just before we are ready to finish waiting for QSem and continue in main thread which is sole reason why we need killItself flag. in this code snipped this flag is completely useless, btw -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[4]: Parallel combinator, performance advice
Hello Neil, Tuesday, April 7, 2009, 7:47:17 PM, you wrote: >> para = mapM_ forkIO > I might try that tomorrow and see if it makes a difference to the > performance. While the majority of computation is in system calls, > quite a few of the threads open files etc, and having them all run in > parallel would end up with way too many open handles etc. if you have too much threads, you may replace forkIO with one more QSem-enabled call: semIO = unsafePerformIO$ newQSem 100 myForkIO = bracket_ (waitQSem semIO) (signalQSem semIO) . forkIO this limit may be much higher than for System.Cmd.system or you may go further and replace it with thread pool approach. the main problem behind is raw calls to forkIO since these increases amount of threads capable to call System.Cmd.system without any control from us -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[5]: Parallel combinator, performance advice
Hello Bulat, Tuesday, April 7, 2009, 7:50:08 PM, you wrote: >> parallel_ (x1:xs) = do >> sem <- newQSem $ 1 - length xs >> forM_ xs $ \x -> >> writeChan queue (x >> signalQSem sem, False) >> x1 >> addWorker >> waitQSem sem >> writeChan queue (signalQSem sem, True) >> waitQSem sem > Neil, executing x1 directly in parallel_ is incorrect idea. forget this. but it still a bit suboptimal: after everything was finished, we schedule one more empty job and wait while some worker thread will pick up it. it will go into Chan after all jobs scheduled at the time our jobs was executed so that we are doing here is eventually don't do any internal activity while we have all N external programs running instead, my solution packed this flag together with last job so once last job is finished we are immediately returned from parallel_ so other internal activity may go on -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[6]: Parallel combinator, performance advice
Hello Bulat, Tuesday, April 7, 2009, 8:10:43 PM, you wrote: >>> parallel_ (x1:xs) = do >>> sem <- newQSem $ 1 - length xs >>> forM_ xs $ \x -> >>> writeChan queue (x >> signalQSem sem, False) >>> x1 >>> addWorker >>> waitQSem sem >>> writeChan queue (signalQSem sem, True) >>> waitQSem sem >> Neil, executing x1 directly in parallel_ is incorrect idea. > forget this. but it still a bit suboptimal... i think i realized why you use this schema. my solution may lead to N-1 worker threads in the system if last job is too small - after its execution we finish one thread and have just N-1 working threads until parallel_ will be finished but problem i mentioned in previous letter may also take place although it looks like less important. we may solve both problems by allowing worker thread to actively select its death time: it should die only at the moment when *last* job in bucket was finished - this guarantees us exactly N worker threads at any time. so: parallel_ (x1:xs) = do sem <- newQSem $ - length xs jobsLast <- newMVar (length xs) addWorker forM_ (x1:xs) $ \x -> do writeChan queue $ do x signalQSem sem modifyMVar jobsLast $ \jobs -> do return (jobs-1, jobs==0) -- waitQSem sem and modify last 3 lines of addWorker: addWorker :: IO () addWorker = do forkIO $ f `E.catch` \(e :: SomeException) -> throwTo mainThread $ ErrorCall "Control.Concurrent.Parallel: parallel thread died." return () where f :: IO () f = do act <- readChan queue kill <- act unless kill f -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trying to write 'safeFromInteger'
Hello Kannan, Wednesday, April 8, 2009, 1:27:21 AM, you wrote: > if i > (toInteger maxBound) problem here is that GHC doesn't know what maxBound you mean. is it maxBound::Int8? or maxBound::Word128? it has nothing common with the value you return later so you need to use either scoped type variables or usual asTypeOf trick. look recent cafe threads for more info -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[8]: Parallel combinator, performance advice
Hello Neil, Wednesday, April 8, 2009, 2:33:15 PM, you wrote: > Yes, this saves us adding a kill job to the queue, but requires an > extra MVar. I guess which one of these is to be preferred depends on > performance measures. i think that main problem with your last variant is that kill job added to the queue much later than real jobs. imagine the following scenario: 1. para used to add 100 jobs to the queue 2. while these jobs are executing, para in another thread adds another 100 jobs to the queue in my variant, first para exits just when its own jobs are completed. in your variant, exit job is added to the queue only after second batch of 100 jobs so we will wait until all these jobs are executed -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] GHC needs a 64 bit machine to be fast?
Hello Peter, Wednesday, April 8, 2009, 12:58:25 PM, you wrote: No. it seems that i'm only user asking GHC team for 64-bit version > Regarding that, is it possible to generate 64-bit code using GHC on Windows? > On Wed, Apr 8, 2009 at 10:17 AM, FFT wrote: > > On Wed, Apr 8, 2009 at 1:14 AM, Karel Gardas wrote: >> >> Hello, >> >> perhaps you are hit by following issue? >> http://hackage.haskell.org/trac/ghc/ticket/594 > > > The benchmark isn't using the native code generator, it compiles via > C, as I understand. > > What are other people's timings on 32 bit Linux machines? > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Trying to write 'safeFromInteger'
Hello Henning, Wednesday, April 8, 2009, 1:43:31 AM, you wrote: > i is Integer, so asTypeOf is not so easy to apply. I propose to write safeFromInteger i = let mb = maxBound in if i > (toInteger mb) then Nothing else Just (fromInteger i `asTypeOf` mb) or you can do it opposite way: safeFromInteger i = let res = fromInteger i in if i > (toInteger (maxBound `asTypeOf` res)) then Nothing else Just res -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re[10]: Parallel combinator, performance advice
Hello Neil, Wednesday, April 8, 2009, 3:25:51 PM, you wrote: > I've attached a revised implementation. With my benchmark it gives a > stack overflow: it may be in replicate. check with let incRef = atomicModifyIORef r (\a -> (a,a)) > As a side note, it's necessary to add parallelStop, to kill all the > threads - or you get thread blocked exceptions being raised. alternatively, you can catch this exception in addWorker -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging compile times (Template Haskell)
Hello Henning, Thursday, April 9, 2009, 5:01:21 PM, you wrote: i think that this case may be interesting for GHC developers > Hi, > as the author of the encoding package[1] I'm quite annoyed by the > extreeme long time it takes to compile a certain module (JISX0208). This > module uses template haskell to generate both a Map (Map Char > (Word8,Word8)) and an Array (UArray (Word8,Word8) Int) for character > conversion. The file has about 6000 entries and the generated array has > 8649 entries. Generating the syntax for the array and map is very fast > (under a second) but compiling the code seems to take forever. > Is there any way to find out why that is the case? I've tried > pinpointing the problem but couldn't... > [1] > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/encoding -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Best text editor
Hello Alexandr, Tuesday, April 14, 2009, 6:37:38 AM, you wrote: >> Hi I would like to follow the crowd and find out what text editor everyone >> uses for haskell on windows. > * HippoEdit (http://www.hippoedit.com/) i've tried HippoEdit and don't recommend it. it's work in progress so i immediately hit several bugs -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Converting IO [XmlTree] to [XmlTree]
Hello rodrigo.bonifacio, Tuesday, April 14, 2009, 6:54:07 PM, you wrote: > I guess this is a very simple question. How can I convert IO > [XmlTree] to just a list of XmlTree? IO [XmlTree] is an action returning [XmlTree]. so to "convert" it to [XmlTree] you just need to execute it in IO monad: value <- action i suggest you to read http://haskell.org/haskellwiki/IO_inside in order to manage IO monad -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
win64 ghc version Re[4]: [Haskell-cafe] GHC needs a 64 bit machine to be fast?
Hello Peter, Wednesday, April 8, 2009, 2:42:24 PM, you wrote: if you need win64 ghc version - add yourself to CC list of http://hackage.haskell.org/trac/ghc/ticket/1884 > Well, make that 2! :-) > On Wed, Apr 8, 2009 at 11:47 AM, Bulat Ziganshin > wrote: > Hello Peter, > > Wednesday, April 8, 2009, 12:58:25 PM, you wrote: > > No. it seems that i'm only user asking GHC team for 64-bit version > >> Regarding that, is it possible to generate 64-bit code using GHC on Windows? > >> On Wed, Apr 8, 2009 at 10:17 AM, FFT wrote: >> >> On Wed, Apr 8, 2009 at 1:14 AM, Karel Gardas >> wrote: >>> >>> Hello, >>> >>> perhaps you are hit by following issue? >>> http://hackage.haskell.org/trac/ghc/ticket/594 >> >> >> The benchmark isn't using the native code generator, it compiles via >> C, as I understand. >> >> What are other people's timings on 32 bit Linux machines? >> >> ___ >> Haskell-Cafe mailing list >> haskell-c...@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > >> > > > > -- > Best regards, > Bulat mailto:bulat.zigans...@gmail.com > > > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Converting IO [XmlTree] to [XmlTree]
Hello Cristiano, Tuesday, April 14, 2009, 7:24:40 PM, you wrote: > unsafePerformIO is not "evil" by itself, it's there for a purpose and, > as for anything else in the language, it's better to understand when > to use it we just think that author of original question don't yet have good knowledge of IO monad baiscs and it's what he actually want to know. if the question was how to perform IO action in pure code, unsafePerformIO may be a good answer -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC including System.Time but not Data.Time?
Hello John, Tuesday, April 14, 2009, 8:44:12 PM, you wrote: > I understand the goal of removing stuff from GHC, but the practical > implications can be rather annoying. i think that Haskell Platform will eventually replace what GHC was for a years, i.e. out-of-box solution for practical haskell usage. and ghc should be just what its name implies - bare compiler but i agree that stripping one package in minor 6.10.2 version, w/o Haskell Platform really available was an error -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] GHC including System.Time but not Data.Time?
Hello John, Wednesday, April 15, 2009, 5:35:00 PM, you wrote: > I agree. Is there any chance of 6.10.3 reverting the change? both 6.6 and 6.8 had last releases at spring, so i don't expect new 6.10.* at all -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] ANN: Elerea, another FRP library
Hello Peter, Thursday, April 16, 2009, 12:29:41 PM, you wrote: Lennart (and Patai) said about unsafePerformIO, you - about NOINLINE > Well, the documentation says: > Use {-# NOINLINE foo #-} as a pragma on any function foo that calls > unsafePerformIO. If the call is inlined, the I/O may be performed more than > once. > > So you claim this does not prevent GHC to inline it anyway? That > feels like a bug then, both in the documentation and NOINLINE > On Thu, Apr 16, 2009 at 10:18 AM, Lennart Augustsson > wrote: > > There's no guarantee about unsafePerformIO not being inlined, that's > just how ghc treats it. > > 2009/4/16 Patai Gergely : > >>> On the other hand, breaking referential transparency in the >>> external interface is a very bad idea, in my opinion. Actually, >>> this means that the library user would have to turn certain >>> compiler optimizations off to get the intended behavior. >> However, in practice you can compile Elerea with -O2 without ill >> effects. In fact, that's what happens if you install it with cabal. >> >>> Just have a look at the Haddock docs of unsafePerformIO. >> Yes, I did that too, and came up with the following checklist: >> >> - the order of side effects doesn't matter much, since the resulting >> networks are equivalent if we don't rely on the automatic delay feature >> (applicative optimisations can be different, but still with the same net >> effect) >> - unsafePerformIO is apparently never inlined, i.e. each instance is >> executed once, so sharing works as desired >> - let-floating is no problem, because all instances of unsafePerformIO >> rely on surrounding function arguments >> - CSE is no problem either, it even helps if it's performed (and it is >> with optimisations turned on), since it results in smaller equivalent >> networks >> >> I think we can expect it to be fairly well-behaving, because the 'side >> effect' of Elerea primitives is basically the same as that of pure >> values in general: upon evaluation a value is created in the memory and >> we get a reference to it. We only have an extra constraint for the >> compiler: never duplicate these values. Merging identical ones is okay, >> and in fact desirable. The following code demonstrates this if you >> compile it with and without optimisations: >> >> import Control.Applicative >> import Control.Monad >> import FRP.Elerea >> import System.IO.Unsafe >> >> cint a b = unsafePerformIO (putStrLn "!") `seq` >> transfer 0 (\dt x x0 -> x0+x*dt) b >> >> mysig = (latcher 0 (b >@ 0.3) (const (cint a b) <$> cint a b)) + >> (cint a b) + (cint a b) + a >> where a = pure 4 >> b = stateful 0 (+) >> >> main = replicateM 10 (superstep mysig 0.1) >>= print >> >> I'd like to see an example where optimisation does make a difference, >> because I'm still unsure about the consequences of 'unsafeness'. >> >> Gergely >> >> -- >> http://www.fastmail.fm - Or how I learned to stop worrying and >> love email again >> >> ___ >> 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 > > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] RE: [Announce] primes
Hello michael, Friday, April 17, 2009, 6:26:33 PM, you wrote: http://haskell.org/cabal/ > You're right. Since I'm not familiar with Cabal, I didn't use it. Is there a > good tutorial? Docs? > Also, I'm running a 32-bit Linux OS. Does one get a significant speed > increase by > switching to a 64-bit OS? > Thanks for the feedback. > Michael > --- On Fri, 4/17/09, Sebastian Fischer > wrote: > From: Sebastian Fischer > Subject: Re: [Haskell-cafe] RE: [Announce] primes > To: "Haskell Cafe mailing list" > Date: Friday, April 17, 2009, 4:03 AM > Oh, I just remembered, I'm using ghci. I'll bet that's why I'm so slow. > I also did, but after installing the package using cabal. IIRC, > cabal compiles with -O2 by default. But if you downloaded the > tarball and then loaded the module in ghci without installing it, > this is probably the reason for the slow response. > Cheers, > Sebastian > -Inline Attachment Follows- > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Computing a sorted list of products lazily
Hello Jason, Saturday, April 18, 2009, 1:41:18 AM, you wrote: > The algorithm should return the same result as: > sortProduct a b = sort [ x * y | x <- a, y <- b ] i think it's well-known problem. you should write a function merging infinite list of sorted lists. in assumption that lists are ordered by their first element this should be doable -- Function that merge finite lists (kidnapped from Data.List): merge_lists :: (a -> a -> Ordering) -> [[a]] -> [a] merge_lists cmp [] = [] merge_lists cmp [xs] = xs merge_lists cmp xss = merge_lists cmp (merge_pairs cmp xss) merge_pairs :: (a -> a -> Ordering) -> [[a]] -> [[a]] merge_pairs cmp [] = [] merge_pairs cmp [xs] = [xs] merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss merge :: (a -> a -> Ordering) -> [a] -> [a] -> [a] merge cmp xs [] = xs merge cmp [] ys = ys merge cmp (x:xs) (y:ys) = case x `cmp` y of GT -> y : merge cmp (x:xs) ys _ -> x : merge cmpxs (y:ys) this function merges lists in pairs. rewriting it to make incremental merging, using "sorted by first element" property and omitting finite lists support, we get just: -- Merging infinite sorted lists merge_lists :: (Ord a) => [[a]] -> [a] merge_lists ((x:xs):xss) = x : merge xs (merge_lists xss) merge :: (Ord a) => [a] -> [a] -> [a] merge (x:xs) (y:ys) = case x > y of True -> y : merge (x:xs) ys _-> x : mergexs (y:ys) works for me with test script: main = putStr (unlines$ map show$ merge_lists [[x*y | x<-[1..]] | y<-[1..]]) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Hello michael, Saturday, April 18, 2009, 6:56:20 PM, you wrote: > Is there a general function to count list elements. I'm trying this you should add Eq restriction to type declaration since "==" operation belomngs to Eq class and your function may work only with types supporting comparision: count :: (Eq a) => a -> [a] -> Int -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] General function to count list elements?
Hello michael, Saturday, April 18, 2009, 8:27:45 PM, you wrote: so you can use Scheme to derive theorem proofs. useful for exams! :) > I know functions can be compared in Scheme > Welcome to DrScheme, version 4.1 [3m]. > Language: Swindle; memory limit: 128 megabytes. >> (equal? equal? equal?) > #t >> > but apparently not in Haskell > [mich...@localhost ~]$ ghci > GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. Prelude>> (==) (==) (==) > :1:0: > No instance for (Eq (a -> a -> Bool)) > arising from a use of `==' at :1:0-13 > Possible fix: add an instance declaration for (Eq (a -> a -> Bool)) > In the expression: (==) (==) (==) > In the definition of `it': it = (==) (==) (==) Prelude>> > though I'm new at Haskell and may not be posing the question properly. > I would think a language with 1st-class support for functions would > certainly include comparing them. > To compare two functions in C, I would compare their machine addresses. > Michael > --- On Sat, 4/18/09, Eugene Kirpichov wrote: > From: Eugene Kirpichov > Subject: Re: [Haskell-cafe] General function to count list elements? > To: "michael rice" > Cc: haskell-cafe@haskell.org > Date: Saturday, April 18, 2009, 11:39 AM > Could you then provide an example of two functions that *are* equal, > or, even better, a definition of equality for arbitrary functions? > Since Haskell may be compiled into C, this must be a definition that > is implementable in C. > 2009/4/18 michael rice : >> Though I haven't tried it out, it's trying to use my function to count >> functions. >> >> The first argument is the identity function. >> >> The second argument is a list of a different form of the identity function. >> >> Though the two identity functions, given the same input, would produce the >> same output, I doubt they would be equal. >> >> So my guess at an answer would be zero. >> >> Michael >> >> --- On Sat, 4/18/09, Eugene Kirpichov wrote: >> >> From: Eugene Kirpichov >> Subject: Re: [Haskell-cafe] General function to count list elements? >> To: "michael rice" >> Cc: haskell-cafe@haskell.org >> Date: Saturday, April 18, 2009, 11:03 AM >> >> What should >> >> count (\x -> x) (replicate 10 (\y -> if 1==1 then y else undefined)) >> >> return? >> >> 2009/4/18 michael rice : >>> Is there a general function to count list elements. I'm trying this >>> >>> count :: a -> [a] -> Int >>> count x ys = length (filter (== x) ys) >>> >>> with this error upon loading >>> >>> = >>> >>> [mich...@localhost ~]$ ghci count >>> GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help >>> Loading package ghc-prim ... linking ... done. >>> Loading package integer ... linking ... done. >>> Loading package base ... linking ... done. >>> [1 of 1] Compiling Main ( count.hs, interpreted ) >>> >>> count.hs:2:29: >>> Could not deduce (Eq a) from the context () >>> arising from a use of `==' at count.hs:2:29-32 >>> Possible fix: >>> add (Eq a) to the context of the type signature for `count' >>> In the first argument of `filter', namely `(== x)' >>> In the first argument of `length', namely `(filter (== x) ys)' >>> In the expression: length (filter (== x) ys) >>> Failed, modules loaded: none. >>> Prelude> >>> >>> = >>> >>> Not sure what it's trying to tell me other than I need an (Eq a) >>> somewhere. >>> >>> Michael >>> >>> >>> >>> >>> ___ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >>> >> >> >> >> -- >> Eugene Kirpichov >> Web IR developer, market.yandex.ru >> >> -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
Hello R.A., Sunday, April 19, 2009, 11:46:53 PM, you wrote: > Does anybody know if there are any plans to incorporate some of > these extensions into GHC - specifically the existential typing ? it is already here, but you should use "forall" keyword instead odf "exists" -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
Hello Jon, Monday, April 20, 2009, 1:59:07 PM, you wrote: > It's not an implementor's place to make such decisions -- > they can legitimately say "this feature sucks" and tell the > next Haskell committee so. If they care enough about it, > they can lobby or get on that next committee, but the > arguments for n+k patterns /in Haskell98/ were done long > ago. if you really believe in that you said, you can spend your own time adding its support :) i never seen n+k patterns in real code so i understand developers that don't want to waste time just to compliant standard even if their efforts will be never really used -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] CPS and the product function
Hello michael, Monday, April 20, 2009, 6:32:47 PM, you wrote: something like 0*_ = 0 x*y = x *# y or vice versa _*0 = 0 x*y = x *# y where *# is original (*) definition. current ghc definiton just performs cpu-level operation w/o checking for 0 since this is rarely useful and need some time OTOH, boolean operations are expected to short-circuit, so they are defined properly. try and (iterate [True,False]) > Hi Eugene, > Clever solution. > It didn't come right back so I interrupted it. Guess it would do all those > multiplies by zero. > Does anyone know how to define it to avoid that? > Thanks. > Michael > --- On Mon, 4/20/09, Eugene Kirpichov wrote: > From: Eugene Kirpichov > Subject: Re: [Haskell-cafe] CPS and the product function > To: "michael rice" > Cc: haskell-cafe@haskell.org > Date: Monday, April 20, 2009, 9:40 AM > Check that by experiment in ghci or by looking at the source: Prelude*>> product [0..] > Or search "product" at http://holumbus.fh-wedel.de/hayoo/hayoo.html > and click on one of the Source links. > 2009/4/20 michael rice : >> I've been looking at CPS in Haskell and wondering how many multiplications >> the product function performs if it encounters a zero somewhere in the input >> list. Zero? >> >> Does anyone know the definition of the product function? >> >> Michael >> >> >> >> ___ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Re: ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
Hello S., Tuesday, April 21, 2009, 5:42:15 PM, you wrote: > If we had been interested in raising fierce discussions about n+k > patterns or how and where cabal installs things, we could have easily > achieved the same effect with much less effort. you mean that we should shoot up? :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Being impure within a 'pure' function
Hello Jason, Wednesday, April 22, 2009, 1:14:49 PM, you wrote: there is no any need in unsafePerformIO for array computations - ST monad is exactly what one need here > If you want to do raw IO and repackage it as "pure", you can > use `unsafePerformIO` and friends. It is important to use the > `NOINLINE` pragma in that case. > -- > Jason Dusek > |...unsafePerformIO...| > > http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO-Unsafe.html#v%3AunsafePerformIO > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Issues with IO and FFIs
Hello Jon, Wednesday, April 22, 2009, 1:54:58 PM, you wrote: > Does anyone have any comments on the following criticism of some difficulties > with FFI, including IO, in Haskell: > http://groups.google.com/group/comp.lang.functional/msg/6d650c086b2c8a49?hl=en > In particular, is it not always possible to write IO libraries safely in > Haskell? i think that this letter is true on factual part but he exaggerate this problem 1) you can develop any pure-haskell imperative library with safe (no global state) interface and implementation. well, you can do the same with any other language too :) 2) if you are going to hardware level, it usually has von Neumann architecture, i.e. global state. so when providing some service to application, you have to deal with global state at some level. if it doesn't handled at C level (in his example, MVar may be maintained at C side), you need to to this at Haskell level 3) haskell language still doesn't provide features to create global variables, although it was proposed to add syntax he uses: globalLock <- newMVar False -- the same as globalLock = unsafePerformIO (newMVar False) -- but with guarantees of no sharing so we use unsafePerformIO hack instead that's all. if we sometimes deal with global-state C libraries, we may need to use global vars too. anyway, at some level (be it C or Haskell) we need to create safe interface too unsafe von Neumann hardware -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Base version on Hackage?
Hello Magnus, Thursday, April 23, 2009, 8:47:23 PM, you wrote: base is built-in into ghc/hugs/... it never can be on hackage > I'm not sure why building of my recently uploaded version of dataenc > fails to build on Hackage[1]. Where can I find out what version of base > is available on Hackage? > /M > [1]: > http://hackage.haskell.org/packages/archive/dataenc/0.12.1.0/logs/failure/ghc-6.10 -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] compilation to C, not via-C
Hello Sam, Friday, April 24, 2009, 8:36:50 PM, you wrote: > I work in Games middleware, and am very interested in looking at how > Haskell could help us. We basically sell C++ libraries. I would like to > be able to write some areas of our libraries in Haskell, compile the > Haskell to C and incorporate that code into a C++ library. well, you can intercept these files. once i wrote simple 4-line haskell utility (it may be 20 lines of C++ or so) and compiled it down to C. results was 300 lines or so which it's impossible to understand so, if you just need haskell-C++ interaction, you may look into using FFI [1,2]. if you believe that you can compile some java/ruby/haskellwhatever code down to C++ and incorporate it into your function - sorry, they all have too different computing model btw, my own program [3] goes this way - i combine fast C++ and complex Haskell code via FFI/dll to produce fast, feature-rich application [1] http://www.haskell.org/haskellwiki/GHC/Using_the_FFI [2] http://www.haskell.org/haskellwiki/FFI_cook_book [3] http://freearc.org -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] compilation to C, not via-C
Hello Alex, Friday, April 24, 2009, 8:57:40 PM, you wrote: >> so, if you just need haskell-C++ interaction, you may look into using >> FFI [1,2]. if you believe that you can compile some >> java/ruby/haskellwhatever code down to C++ and incorporate it into >> your function - sorry, they all have too different computing model >> > Actually some Scheme compilers have a "c-declare" form that lets > you create C functions, which can be called from C, Haskell, Java, > Ruby etc. and it supports lazy lists? :) all compiled languages has some FFI, the problem is that FFI limited to common subset of all those languages - i.e. primitive types and pointers -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] compilation to C, not via-C
Hello Sam, Friday, April 24, 2009, 9:09:43 PM, you wrote: well, GHC generates .o files. so you may solve some of your questions. if you can absolutely ignore performance, you can use so-called non-registerized compilation what generates ansi-compatible C code most Haskell libs are written for ghc, so for other compilers you will need to write almost self-contained code > I need a list of .c and .h files as an end result of the Haskell > compilation stage. I expect these c files will need to include Haskell > runtime C code to operate, and therefore have some dependencies in order > to compile and link. > Afaict, GHC as it stands does not allow me to do this, even though it > presumably generates C in the process of compiling binary objects. > Actually having C source as an end result is critical as I need control > over exactly how the source is compiled and linked. For example: > - I need to compile to different targets: either a static C lib, exe, > dll or C++ lib. > - I need to support multiple compilers. > - I might want to produce a custom runtime. > In short, I'd like to use Haskell as a code-generator. > I can't see that this would be unachievable, particularly given it's > generating C already. Have I missed something? > Cheers, > Sam > -Original Message- > From: Bulat Ziganshin [mailto:bulat.zigans...@gmail.com] > Sent: 24 April 2009 17:53 > To: Sam Martin > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] compilation to C, not via-C > Hello Sam, > Friday, April 24, 2009, 8:36:50 PM, you wrote: >> I work in Games middleware, and am very interested in looking at how >> Haskell could help us. We basically sell C++ libraries. I would like > to >> be able to write some areas of our libraries in Haskell, compile the >> Haskell to C and incorporate that code into a C++ library. > well, you can intercept these files. once i wrote simple 4-line > haskell utility (it may be 20 lines of C++ or so) and compiled it down > to C. results was 300 lines or so which it's impossible to understand > so, if you just need haskell-C++ interaction, you may look into using > FFI [1,2]. if you believe that you can compile some > java/ruby/haskellwhatever code down to C++ and incorporate it into > your function - sorry, they all have too different computing model > btw, my own program [3] goes this way - i combine fast C++ and complex > Haskell code via FFI/dll to produce fast, feature-rich application > [1] http://www.haskell.org/haskellwiki/GHC/Using_the_FFI > [2] http://www.haskell.org/haskellwiki/FFI_cook_book > [3] http://freearc.org -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] compilation to C, not via-C
Hello Rick, Friday, April 24, 2009, 10:12:42 PM, you wrote: what you think about JHC? it seems that Timber is close to it > You may wish to look at Timber. It is a Haskell descendant designed for > embedded systems. > Its current default output is C which is then compiled. It is a > very young language, but given the current list of use cases, I am > sure that it will never abandon it's C output model, because most > people in embedded disciplines seem to prefer it. It does, like > Haskell, include a runtime, but it is small, and light. Since it is > targetted towards embedded systems the garbage collector is one that > can be interacted with to guarantee response times on the microsecond level. > > http://timber-lang.org/ > I too write software for time critical applications and multiple > platforms (such as the iPhone). I surveyed over a dozen compilers in > multiple languages, and my search ended with Timber. As I mentioned, > it is very young, it has very little standard library to speak of, but it has > strong possibilities. > > On Fri, Apr 24, 2009 at 1:34 PM, Bulat Ziganshin > wrote: > Hello Sam, > > Friday, April 24, 2009, 9:09:43 PM, you wrote: > > well, GHC generates .o files. so you may solve some of your questions. > if you can absolutely ignore performance, you can use so-called > non-registerized compilation what generates ansi-compatible C code > > most Haskell libs are written for ghc, so for other compilers you will > need to write almost self-contained code > >> I need a list of .c and .h files as an end result of the Haskell >> compilation stage. I expect these c files will need to include Haskell >> runtime C code to operate, and therefore have some dependencies in order >> to compile and link. > >> Afaict, GHC as it stands does not allow me to do this, even though it >> presumably generates C in the process of compiling binary objects. > >> Actually having C source as an end result is critical as I need control >> over exactly how the source is compiled and linked. For example: >> - I need to compile to different targets: either a static C lib, exe, >> dll or C++ lib. >> - I need to support multiple compilers. >> - I might want to produce a custom runtime. > >> In short, I'd like to use Haskell as a code-generator. > >> I can't see that this would be unachievable, particularly given it's >> generating C already. Have I missed something? > >> Cheers, >> Sam > >> -Original Message- >> From: Bulat Ziganshin [mailto:bulat.zigans...@gmail.com] >> Sent: 24 April 2009 17:53 >> To: Sam Martin >> Cc: haskell-cafe@haskell.org >> Subject: Re: [Haskell-cafe] compilation to C, not via-C > >> Hello Sam, > >> Friday, April 24, 2009, 8:36:50 PM, you wrote: > >>> I work in Games middleware, and am very interested in looking at how >>> Haskell could help us. We basically sell C++ libraries. I would like >> to >>> be able to write some areas of our libraries in Haskell, compile the >>> Haskell to C and incorporate that code into a C++ library. > >> well, you can intercept these files. once i wrote simple 4-line >> haskell utility (it may be 20 lines of C++ or so) and compiled it down >> to C. results was 300 lines or so which it's impossible to understand > >> so, if you just need haskell-C++ interaction, you may look into using >> FFI [1,2]. if you believe that you can compile some >> java/ruby/haskellwhatever code down to C++ and incorporate it into >> your function - sorry, they all have too different computing model > >> btw, my own program [3] goes this way - i combine fast C++ and complex >> Haskell code via FFI/dll to produce fast, feature-rich application > > >> [1] http://www.haskell.org/haskellwiki/GHC/Using_the_FFI >> [2] http://www.haskell.org/haskellwiki/FFI_cook_book >> [3] http://freearc.org > > > > > > -- > Best regards, > Bulat mailto:bulat.zigans...@gmail.com > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] compilation to C, not via-C
Hello Sam, Saturday, April 25, 2009, 11:40:05 PM, you wrote: btw, are you seen MetaLua? it's pretty piece of software that makes Lua very FPish > > > Hi Ryan, > > Nice to hear from another games industry coder on the Haskell lists :) > > Thanks, this is exactly the kind of detail I was after. I had > heard rumours of the Evil Mangler but hadn't found a concrete > reference to it before. This makes a lot of sense. Given this and > the other helpful comments I tend to agree with Wren that a > different compiler might be a better starting point. I'll follow up > JHC and YHC in more depth and have a nose at Timber and Gambit-C as well. > > I'm pretty much undecided on whether haskell and games are going > to play well at the moment. For me, it's very difficult to call, but > I think it still looks interesting enough to pursue. I note there is > at least a precedent set for functional languages in games by > Naughty Dog's GOAL > (http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp). As it > happens, I tried to stir up the coders on the gd-algorithms mailing > list recently to see how much interest there was in Haskell for > games. There was a fair amount of cyber-tumbleweed :). Please feel free to > chip in :) > > I agree the runtime is definitely where a big chunk of the problem > is - particular garbage collection - but incidentally this is the > bit I'm least worried about. It's all work, but I think there are > ways of managing this predictably and efficiently. The 'clump and > dump' approach the Eaton guys have used (and maybe region marking in > JHC?) was one idea that had sprung to mind already - assuming it's the same > one :). > > The monad->code approach sounds interesting as way of implementing > small DSLs, but it sounds like it wouldn't scale up particular far? > If this is true, I'm not sure how well approach would compete with > existing scripting languages used in games. I'm not especially > excited about using Haskell as a game scripting language. I want to > find something to eat into the vast swath of C++ written for games > that lua/python/unrealscript/homebrew scripting can't touch. Say, > for instance, writing a procedural LOD generator. > > Cheers, > Sam Martin > > ps. As a disclaimer - I'm emailing from my work address, but this > is all just my own stuff and not necessarily representative of the > views of Geomerics! We are definitely not about to ship > Haskell-generated C to anyone ;). I'll reply off-list about Geomerics. > > > -Original Message- > From: Ryan Ingram [mailto:ryani.s...@gmail.com] > Sent: 24 April 2009 18:14 > To: Sam Martin > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] compilation to C, not via-C > > Sam, > > I work on graphics engine/pipeline for Spore at Electronic Arts, and > I've had some similar thoughts as you. But I don't think this is the > right path for games right now. > > The "via C" compiler does generate C code that it puts through GCC. > There is a post-process step after the code is converted to assembly > by GCC (see > http://hackage.haskell.org/trac/ghc/wiki/Commentary/EvilMangler); > a perl script rewrites the calling convention of all the functions to > optimize for the code that GHC generates. From what I understand, > performance is significantly worse without the mangler. So > interoperability of the generated C-from-Haskell code directly with > your C code is tricky at best. > > However, the generated code is only half the story. The other half is > that you need the Haskell runtime to go with your program. This > manages the garbage collector, multithreading-support, etc. As a > middleware developer, I'm sure you're aware that it would be quite > difficult to sell "you need this big runtime with unpredictable memory > requirements" to your potential customers. > > That said, don't lose hope. Lots of Haskell development is being done > for embedded systems, and other things at a similar level as to what > you want. But what these systems generally do is write a custom monad > that *outputs* code. You can look at some of the CUFP2008 talks about > this topic (http://cufp.galois.com/2008/schedule.html); I recommend > "Controlling Hybrid Vehicles with Haskell". There was another talk > about compiling Haskell into Excel spreadsheets for finance, but I > can't seem to locate it right now. > > The basic strategy is to encapsulate all your operations in a monad, > then write "code generation" that converts the results into C code > which you can then compile and ship. Unless you're willing to make > the jump to Haskell as a host language with FFI outcalls to native > code, I think this is the right strategy right now. > > Good luck, and keep us informed how it goes. I expect to hear from > you at CUFP next year :) > > -- ryan > > P.S. I saw some demos of Geomerics products; it looks pretty cool. > What are you g
Re: [Haskell-cafe] Help from C libraries experts
Hello Maurício, Wednesday, April 29, 2009, 11:09:04 PM, you wrote: > My goal is to have a place where one can find reliable and > comprehensive low-level bindings to foreign libraries, so that > writing higher level bindings becomes an easier task. it looks impractical. better will be to provide each binding or group of related bindings as separate library -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Decoupling OpenAL/ALUT packages from OpenGL
Hello Sven, Saturday, May 2, 2009, 9:14:13 PM, you wrote: > must, but the actual packaging is not nice. So the obvious idea is to > introduce 3 new packages which lift out functionality from the OpenGL package: another possible variant: OpenGL-DataTypes package that joins these 3 -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] using haskell for a project
Hello Nicolas, Saturday, May 2, 2009, 9:17:55 PM, you wrote: > But now I don't know how to dynamically add new spells (new spells can be > created in my gameplay). Since I can't assign a new value to the `spells' > variable (Data.Map.insert returns a new map), I just don't know where to > go. well, i've written mid-size program that combines pure haskell, imperative haskell and c++ and that's my vision: in C, you don't have the barrier between pure and imperative worlds and as result you don't got habit to distinguish them. haskell forces you to separate pure and imperative code: pure code is much simpler to write but it cannot call imperative one (i.e. function can't call procedures) so you should understand the difference and carefully make your choice you are *forced* to use imperative code when it responds to some external events - user input, network input, so on. so when your spell list mutates as a result of external events, you should do something imperatively. although it may be as easy as tail-recursively calling itself with purely modified value: mainCycle spells = do x <- userInput case x of AddSpell -> mainCycle (newSpell:spells) further improving this idea, you may develop data structire contating whole state info: data GameState = GameState {spells: [Spell], .} and update appropriate parts of GameState on tail-recursive calls: mainCycle gameState = do x <- userInput case x of AddSpell -> mainCycle (gameState {spells = newSpell:spells gameState}) as you see, this approach allows you to live in imperative world but use only pure computations to update state but once your program will become larger, you may find that this approach needs too much typing. in that case, you can program using IORefs, MVars and other types of C-like global vars. or, you may use them semi-globally - i.e. create this vars in outside procedure and then pass to all interested routines: main = do vspells <- newIORef [] let stateVars = StateVars {spells=vspells, ...} mainCycle stateVars you may even use implicit parameters to hide passing details from program code but i don't have experience of using them -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell vs Clean (speed comparison)
Hello Daniel, Sunday, May 3, 2009, 10:24:52 PM, you wrote: > 32-bit sing core [1]: Lisp, Fortran :) this test measures speed of some programs, not "languages". results are depends mainly on bundled libraries and RTS. by no means it demonstrates speed of compiler-generated code of carefully-written program what is typically considered as "language speed". the reasons are: 1) C++ people (and probably Fortran too) aren't so interested in making fastest possible programs as Haskell community. it becomes popular a few years ago, you can find that Haskell becomes several faster at average since then, which doesn't reflect actual improvements in GHC code generation (10-20%) 2) Most programs there depend on speed of libraries. Moreover, there is limitation that it should be *bundled* libraries, so results greatly depends on what currently included in one compiler or another 3) it's prohibited to write your own fast code if bundled library is too slow (for example, because it's too general) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe