Re: [Haskell-cafe] Re: haskell blas bindings: does iomatrix gemv transposing of matrix a?
aeyakovenko: > is there anyway the modifyWith functions could work on uboxed types? If they're inlined, the modify functions on boxed types may well end up unboxed. What's the particular problem you're having? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] Haskell Weekly News: Issue 86 - September 20, 2008
On Tue, 23 Sep 2008 10:34:25 +0200, Wolfgang Jeltsch <[EMAIL PROTECTED]> wrote: >Okay, I was reading the wrong list (haskell instead of haskell-cafe) so the >announcement is there in my mail folder. But why doesn’t Mailman contain the >message properly in its archive? According to http://www.haskell.org//pipermail/haskell-cafe/2008-September/047664.html , >Skipped content of type multipart/mixed Apparently either Mailman has been configured to skip content of type multipart/mixed (which the announcement in question was interpreted as being, apparently because of the attachments), or there is a bug in Mailman. Apparently, either Mailman should be re-configured not to skip content of type multipart/mixed, or this bug (if it is a bug) should be fixed. -- Benjamin L. Russell ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: haskell blas bindings: does iomatrix gemv transposing of matrix a?
>> is there anyway the modifyWith functions could work on uboxed types? > > If they're inlined, the modify functions on boxed types may well end up > unboxed. > > What's the particular problem you're having? well, after inspecting a little further its not so bad actually. i was comparing module Main where import qualified Data.Vector.Dense.IO as Vector import Control.Monad e = exp 1.0 sigmoid xx = 1.0 / (1 + (e ** (1.0 * xx))) type Vec = Vector.IOVector Int Double main = do let size = 10 ff::Vec <- Vector.newListVector size $ repeat 0.5 replicateM_ 1000 $ Vector.modifyWith (sigmoid) ff putStrLn $ "done" to this: #include "math.h" #include "stdlib.h" #include "stdio.h" double sigmoid(double xx) { return 1.0 / (1.0 + (pow(M_E, (1.0 * xx; } int main() { int size = 10; int times = 1000; int ii,jj; double* array = malloc(sizeof(double)*size); for(jj = 0; jj < size; ++jj) { array[jj] = 0.5; } for(ii = 0; ii < times; ++ii) { for(jj = 0; jj < size; ++jj) { array[jj] = sigmoid(array[jj]); } } printf("done\n"); } the haskell version does ok, or 0m37.937s vs 0m23.492s in C. I am compiling with these options: -O2 -fexcess-precision -funbox-strict-fields -fglasgow-exts -fbang-patterns -prof -auto-all, and O2 for gcc. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: haskell blas bindings: does iomatrix gemv transposing of matrix a?
On Wed, 24 Sep 2008, Anatoly Yakovenko wrote: is there anyway the modifyWith functions could work on uboxed types? If they're inlined, the modify functions on boxed types may well end up unboxed. What's the particular problem you're having? well, after inspecting a little further its not so bad actually. i was comparing module Main where import qualified Data.Vector.Dense.IO as Vector import Control.Monad e = exp 1.0 sigmoid xx = 1.0 / (1 + (e ** (1.0 * xx))) I think 'exp' is generally more efficient and less ambiguous than 'e **'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] the way to fail
Whenever `fail` comes up, there are usually remarks to the effect that it doesn't really belong in the definition of `Monad`. Where does `fail` belong? Could it go in `Arrow`? -- _jsn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Injecting Haskell into C
I have a C function whose behaviour is customized by user-supplied function (think of libc qsort). Typically these user-supplied functions are written in C, but I'd like to use FFI to write them in Haskell. Precisely, I'd like to write high-order function which will generate these functions (e.g. mkCompare :: ... -> (Ptr a -> Ptr a -> Int) for feeding the result to qsort). As I understand, there are two ways to do that. Either Haskell code is called from C, or C code is called for Haskell. So my questions are: 1. Are they both possible? 2. If yes, which is better performance-wise? (C function is performance-critical). If generated function is called many times, how big an overhead is going to be? -- Roman I. Cheplyaka :: http://ro-che.info/ kzm: My program contains a bug. How ungrateful, after all I've done for it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] the way to fail
Am Mittwoch, 24. September 2008 11:36 schrieb Jason Dusek: > Whenever `fail` comes up, there are usually remarks to the > effect that it doesn't really belong in the definition of > `Monad`. Where does `fail` belong? Could it go in `Arrow`? > > -- > _jsn In my opinion, fail s should be somehow equivalent to mzero for any string s. So it should go into MonadPlus. Or we should split MonadPlus into MonadZero (with mzero) and a reduced MonadPlus (with mplus) and then fail should obviously go into MonadZero. Best wishes, Wolfgang ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Injecting Haskell into C
Hello Roman, Wednesday, September 24, 2008, 2:04:38 PM, you wrote: > As I understand, there are two ways to do that. Either Haskell code is > called from C, or C code is called for Haskell. So my questions are: > 1. Are they both possible? yes. "foreign export" exports Haskell functions to C world, foreign import does opposite > 2. If yes, which is better performance-wise? (C function is >performance-critical). If generated function is called many times, >how big an overhead is going to be? foreign import *unsafe* -fvia-C together with -O2 may improve speed of C function calls -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] ICFP programming contest results
On Wed, Sep 24, 2008 at 1:06 AM, Malcolm Wallace <[EMAIL PROTECTED]> wrote: > The ICFP programming contest results presentation: > http://video.google.com/videoplay?docid=-4697764813432201693 > > Feel free to pass on this link to any other appropriate forum. Yikes. Haskell did pretty terribly! Anyone have an idea why, given our success in previous contests? David (speaking as someone who was traveling that weekend and didn't have time to compete) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Line noise
> qsort [] = [] > qsort (x:xs) = qsort (filter (x <) xs) ++ [x] ++ qsort (filter (x >=) xs) Note that you can help the reader by making the precedence a bit more obvious: qsort [] = [] qsort (x:xs) = qsort (filter (x <) xs) ++ [x] ++ qsort (filter (x >=) xs) I find that my students can understand this much better than the 1½ liner. Regarding the mapM_ example: > mapM_ (\(n,v) -> putStrLn $ "[" ++ show n ++ "] = " ++ show v) (zip [0..] vs) > > To somebody familiar with Haskell, that is as clear as day. I guess I'm not familiar with Haskell, because I find the paren-counting to be difficult to do in my head (and god knows that I'm familiar with parenthese). Also, I tend to shy away from ($) and (.) and to only use them when I have a list of functions to compose/apply and want to avoid growing the depth of my AST with the length of the list. So I'd probably write the mapM_ example as: mapM_ (\(n,v) -> putStrLn ("[" ++ show n ++ "] = " ++ show v)) (zip [0..] vs) which I find a lot easier to read. Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ICFP programming contest results
daveroundy: > On Wed, Sep 24, 2008 at 1:06 AM, Malcolm Wallace > <[EMAIL PROTECTED]> wrote: > > The ICFP programming contest results presentation: > > http://video.google.com/videoplay?docid=-4697764813432201693 > > > > Feel free to pass on this link to any other appropriate forum. > > Yikes. Haskell did pretty terribly! Anyone have an idea why, given > our success in previous contests? > > David (speaking as someone who was traveling that weekend and didn't > have time to compete) I would say we did OK, Top 10: Java, C++, Java, Haskell, Haskell, C , C++ , C , C++, C++ So now given the size of the competition, the results are starting to look more like places like topcoder or spoj, where the top entries are primarily C and C++, but with a disproportionate represenation of Haskell and OCaml at the top end. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Line noise
> I believe this was voiced as an SML issue more than an OCaml issue, though > honestly I don't know enough of the differences to distinguish them. Before > I mentioned that function/prefix application always binds tighter than > operator/infix application, he was using many redundant parentheses, thanks > to defensive programming against whichever dialect was at fault. It was apparently a programmer issue rather than a language issue: SML's precedence rules are pretty much identical to Haskell's in this regard. Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ICFP programming contest results
Is the report available yet? Regards On Wed, Sep 24, 2008 at 13:06, Don Stewart <[EMAIL PROTECTED]> wrote: > daveroundy: > > On Wed, Sep 24, 2008 at 1:06 AM, Malcolm Wallace > > <[EMAIL PROTECTED]> wrote: > > > The ICFP programming contest results presentation: > > > http://video.google.com/videoplay?docid=-4697764813432201693 > > > > > > Feel free to pass on this link to any other appropriate forum. > > > > Yikes. Haskell did pretty terribly! Anyone have an idea why, given > > our success in previous contests? > > > > David (speaking as someone who was traveling that weekend and didn't > > have time to compete) > > I would say we did OK, > > Top 10: >Java, C++, Java, Haskell, Haskell, C , C++ , C , C++, C++ > > So now given the size of the competition, the results are starting to > look more like places like topcoder or spoj, where the top entries are > primarily C and C++, but with a disproportionate represenation of > Haskell and OCaml at the top end. > > -- Don > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ICFP programming contest results
I've posted a summary of the results on my blog at http://ryani.livejournal.com/18287.html -- ryan 2008/9/24 Rafael Gustavo da Cunha Pereira Pinto <[EMAIL PROTECTED]>: > Is the report available yet? > > Regards > > On Wed, Sep 24, 2008 at 13:06, Don Stewart <[EMAIL PROTECTED]> wrote: >> >> daveroundy: >> > On Wed, Sep 24, 2008 at 1:06 AM, Malcolm Wallace >> > <[EMAIL PROTECTED]> wrote: >> > > The ICFP programming contest results presentation: >> > > http://video.google.com/videoplay?docid=-4697764813432201693 >> > > >> > > Feel free to pass on this link to any other appropriate forum. >> > >> > Yikes. Haskell did pretty terribly! Anyone have an idea why, given >> > our success in previous contests? >> > >> > David (speaking as someone who was traveling that weekend and didn't >> > have time to compete) >> >> I would say we did OK, >> >> Top 10: >>Java, C++, Java, Haskell, Haskell, C , C++ , C , C++, C++ >> >> So now given the size of the competition, the results are starting to >> look more like places like topcoder or spoj, where the top entries are >> primarily C and C++, but with a disproportionate represenation of >> Haskell and OCaml at the top end. >> >> -- Don >> ___ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > -- > Rafael Gustavo da Cunha Pereira Pinto > Electronic Engineer, MSc. > > ___ > 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
[Haskell-cafe] Re: Climbing up the shootout...
Manlio Perillo wrote: Don Stewart ha scritto: [...] Ok. So I'll just say: high level, efficient code is an overriding theme of many individuals working on Haskell. Things are better and better each year. We do not stand still. Any roadmap for improve support in intensive IO multiplexing? Or, at least, some papers about how this is implemented in GHC? Af far as I understand, select is used in two separate places. How much effort it takes to implement a pluggable "reactor" (select, poll, epoll, kqueue, /dev/poll, and so)? We'd certainly support any efforts to add support for a more modern I/O multiplexing or asynchronous I/O back-end to the IO library. It's not too difficult, because the interface between the low-level I/O supplier and the rest of the IO library is rather small - just a few functions that read and write blocks of data in a blocking or non-blocking way. The blocking variants currently communicate with the I/O manager thread which does select() on behalf of the clients. Before doing this, though, I'd urge you to check that your application really does have scaling issues with the current system. If it doesn't, then great, and if it does then you have a good benchmark to evaluate the replacement. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: [Haskell-cafe] Climbing up the shootout...
On Sep 22, 2008, at 20:16 , Bulat Ziganshin wrote: Ok. So I'll just say: high level, efficient code is an overriding theme of many individuals working on Haskell. Things are better and better each year. We do not stand still. yes. when we say that things are greatly improving each year, this means that they was bad previously ;) You're reaching --- trying to use the past to assert the present --- to try to support your incorrect thesis. People who insist something can't be done should stay out of the way of those who are doing it :) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[6]: [Haskell-cafe] Climbing up the shootout...
On Sep 22, 2008, at 18:53 , Donnie Jones wrote: I'm fairly new to Haskell and the Haskell community, but I can say from my experience of hacking on GHC, the GHC team of developers are very interested in performance improvements, e.g. this thread is about performance! So Bulat, why don't you hack on GHC yourself and help improve the compiler? Or suggest detailed improvements since you seem capable of citing specific examples? Because he's convinced himself it's pointless because Haskell will never be able to run faster than C (note how he keeps trying to run dons out of the discussion because he has proof to the contrary). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[8]: [Haskell-cafe] Climbing up the shootout...
Hello Brandon, Wednesday, September 24, 2008, 9:36:56 PM, you wrote: > Because he's convinced himself it's pointless because Haskell will > never be able to run faster than C taking into account that C compilers are very close to maximum speed possible, and this required many years of developemnt by many people, it's not as easy as you believe ;) > (note how he keeps trying to run > dons out of the discussion because he has proof to the contrary). Don os free to present such examples. unfortunately all examples i've seen was due to use of slow C code which easily can be made faster. in particular, shootout can't be considered as representative benchmark -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Line noise
Mads Lindstrøm <[EMAIL PROTECTED]> wrote: > qsort (x:xs) = ... > > what would you propose to call the elements? (car:cdar:cddar:cdddr) no discussion. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Line noise
"donn cave" <[EMAIL PROTECTED]> wrote: > Quoth Andrew Coppin <[EMAIL PROTECTED]>: > ... > | As one experienced C++ programmer put it, "there is no clear flow > from | left to right or right to left". Personally I found that a > little ironic | comming from the language that gave us > | > | while (*x++ = *y++) { } > | > | which is every bit as non-linear! ;-) > > Well, to be precise, C++ got that from C. What C++ adds to it: > >fy(a.fx(b), c) (in Haskell, fy (fx a b) c) > fy( a->fx( a, b ), c )? Typeclasses are something to advertise, and C++ didn't at all enrich C with OO. It polluted it with an extremely badly designed macro system. That is, I'd rather dig through ten layers of wizardly monad- transforming abstraction than even consider to look at a thousand lines of console buffer displaying the last ten percent of a type error involving more < and > than you need in a lifetime. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Am I doing it right?
Hi Haskellers, So as another step in my education, I wanted to ask if the following code at least feels 'morally' correct as a find/replace function, replacing each occurrence of the sub-list before with after in the list. unfoldr felt like the most natural higher order function to capture the recursion, but I imagine there are still slicker ways to have done this because I am creating an intermediate list-of-lists. However, doing it this way seems at least moderately speedy given that I was able to read in, find/replace, and write out a 120 MB file in 30 seconds on a fairly dinky linux box. replace :: (Eq a) => [a] -> [a] -> [a] -> [a] replace before after = concat . unfoldr aux where aux [] = Nothing aux str | take l str == before = Just (after,drop l str) | otherwise = Just (take 1 str,drop 1 str) l = length before Thanks, Creighton ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[8]: [Haskell-cafe] Climbing up the shootout...
On Sep 24, 2008, at 13:44 , Bulat Ziganshin wrote: (note how he keeps trying to run dons out of the discussion because he has proof to the contrary). Don os free to present such examples. unfortunately all examples i've seen was due to use of slow C code which easily can be made faster. in particular, shootout can't be considered as representative benchmark "I reserve the right to disallow any actual evidence for any reason I can come up with, including amorphous and vacuous ones" (you can almost always write something faster, but with how much effort?) Thanks, I get enough of that from the government here. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Am I doing it right?
On Wed, Sep 24, 2008 at 1:14 PM, Creighton Hogg <[EMAIL PROTECTED]> wrote: > Hi Haskellers, > So as another step in my education, I wanted to ask if the following > code at least feels 'morally' correct as a find/replace function, > replacing each occurrence of the sub-list before with after in the > list. unfoldr felt like the most natural higher order function to > capture the recursion, but I imagine there are still slicker ways to > have done this because I am creating an intermediate list-of-lists. > However, doing it this way seems at least moderately speedy given that > I was able to read in, find/replace, and write out a 120 MB file in 30 > seconds on a fairly dinky linux box. > > replace :: (Eq a) => [a] -> [a] -> [a] -> [a] > replace before after = concat . unfoldr aux > where aux [] = Nothing > aux str | take l str == before = Just (after,drop l str) > | otherwise = Just (take 1 str,drop 1 str) > l = length before Yeah, this code is pretty nice. concat is a foldr, so you have an elegant foldr . unfoldr at the top. IIRC foldr . unfoldr fuses, so you get efficiency that way. "take l str == before" is also known as "before `isPrefixOf` str", just to be slightly more idiomatic. This algorithm is quite inefficient, O(nm). There is probably a more efficient one that still only relies on Eq, I am not certain though.€€ Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[10]: [Haskell-cafe] Climbing up the shootout...
Hello Brandon, Wednesday, September 24, 2008, 11:13:14 PM, you wrote: > can come up with, including amorphous and vacuous ones" (you can > almost always write something faster, but with how much effort?) as i said, eddorts to optimize Haskell code is several times larger while the result is several times slower -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Climbing up the shootout...
Simon Marlow ha scritto: Manlio Perillo wrote: [...] We'd certainly support any efforts to add support for a more modern I/O multiplexing or asynchronous I/O back-end to the IO library. It's not too difficult, because the interface between the low-level I/O supplier and the rest of the IO library is rather small - just a few functions that read and write blocks of data in a blocking or non-blocking way. The blocking variants currently communicate with the I/O manager thread which does select() on behalf of the clients. There is some documentation that summarize the current status, and how all fits together? There are some benchmarks that tell you the use of a separate I/O manager thread is a good solution? Before doing this, though, I'd urge you to check that your application really does have scaling issues with the current system. If it doesn't, then great, and if it does then you have a good benchmark to evaluate the replacement. Right now I don't have any Haskell applications. The only application that I develope and need to scale are, until now, web applications, and for this I use Nginx + mod_wsgi + wsgix (the last two implemented by myself, http://hg.mperillo.ath.cx/). I'm quite satisfied with the current status, and I don't think I need to change language/frameworks. However I'm looking for a good environment for implementing generic internet servers, or web applications with special needs. As an example one of my "maybe future" tasks is to write a simple BitTorrent tracker + seeder. I have tried to write it as a Nginx module, but it requires a lot of boiler plate code, so I gave up. Twisted (a Python asynchronous framework) is a confortable environment, but I feel concurrent Haskell is superior. It surely will work using just select, but since I have experience (including indirect experience) with both Twisted and Nginx, I know that using select is asking for troubles (but the solution used by Haskell is very new for me). It is ok for clients, but not for servers that need to go in internet. Cheers, Simon Thanks Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Doing something constructive. [Was: Climbing up the shootout...]
manlio_perillo: > However I'm looking for a good environment for implementing generic > internet servers, or web applications with special needs. > As an example one of my "maybe future" tasks is to write a simple > BitTorrent tracker + seeder. You could look at conjure, the bitorrent client that uses STM for network multiplexing, http://darcs.haskell.org/~lemmih/conjure/ > Twisted (a Python asynchronous framework) is a confortable environment, > but I feel concurrent Haskell is superior. Should be a lot faster, given there's compiled native code, and no global locks. Actually, the very kind of thing we see on the shootout now :) > It surely will work using just select, but since I have experience > (including indirect experience) with both Twisted and Nginx, I know that > using select is asking for troubles (but the solution used by Haskell is > very new for me). Yes, you'd use probably STM's `orElse` to multiplex IO from different sources, and GHCs lightweight threads for concurrency. We've used solutions like this at Galois to build servers that are both high level and efficient. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] New IO foundations. [Was: Climbing up the shootout...]
simonmarhaskell: > Manlio Perillo wrote: > >Don Stewart ha scritto: > >>[...] > >>Ok. So I'll just say: high level, efficient code is an overriding theme > >>of many individuals working on Haskell. Things are better and better > >>each year. We do not stand still. > >> > > > >Any roadmap for improve support in intensive IO multiplexing? > >Or, at least, some papers about how this is implemented in GHC? > > > >Af far as I understand, select is used in two separate places. > >How much effort it takes to implement a pluggable "reactor" (select, > >poll, epoll, kqueue, /dev/poll, and so)? > > We'd certainly support any efforts to add support for a more modern I/O > multiplexing or asynchronous I/O back-end to the IO library. It's not > too difficult, because the interface between the low-level I/O supplier > and the rest of the IO library is rather small - just a few functions > that read and write blocks of data in a blocking or non-blocking way. > The blocking variants currently communicate with the I/O manager thread > which does select() on behalf of the clients. > Indeed, it has been done at least once elsewhere, http://www.seas.upenn.edu/~lipeng/homepage/unify.html Check the tarball for a custom bytestring and epoll implementation used to scale up to 10M haskell threads, http://www.seas.upenn.edu/%7Elipeng/unify/unify-0.0.1.tar.gz Perhaps something worth resuscitating code for, for more epoll servers. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[10]: [Haskell-cafe] Climbing up the shootout...
On Sep 24, 2008, at 15:20 , Bulat Ziganshin wrote: Wednesday, September 24, 2008, 11:13:14 PM, you wrote: can come up with, including amorphous and vacuous ones" (you can almost always write something faster, but with how much effort?) as i said, eddorts to optimize Haskell code is several times larger while the result is several times slower ...and we're back to "dons demonstrated otherwise, so you have to invent reasons to disqualify him". If all you can do is get in the way of people doing what you claim is impossible, please stop. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Random question
Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error messages. I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty. Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated. Regards Iain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error messages. myTake :: IO [Int] myTake = do n <- rand 1 10 take n [1..10] or myTake = rand 1 10 >>= \n -> take n [1..10] or myTake = rand 1 10 >>= flip take [1..10] I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty. Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated. Monad enlightenment happens after 7'th monad tutorial. Verified by me and a few of my friends. -- vlm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
forgot return, of course: > myTake :: IO [Int] > myTake = do > n <- rand 1 10 > return $ take n [1..10] Lev Walkin wrote: Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error messages. myTake :: IO [Int] myTake = do n <- rand 1 10 take n [1..10] or myTake = rand 1 10 >>= \n -> take n [1..10] or myTake = rand 1 10 >>= flip take [1..10] I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty. Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated. Monad enlightenment happens after 7'th monad tutorial. Verified by me and a few of my friends. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On Wed, Sep 24, 2008 at 2:03 PM, Iain Barnett <[EMAIL PROTECTED]> wrote: > Hi, > > I have a function, that produces a random number between two given numbers > > rand :: Int -> Int -> IO Int > rand low high = getStdRandom (randomR (low,high)) > > > (Naively) I'd like to write something like > > take (rand 1 10 ) [1..10] So once you apply those two Ints, the type of the expression is no longer a function, it's (IO Int), which is an action that produces and Int. So you want to do the action 10 times. For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
And the one liner: (rand 1 10) >>= return . (\v -> take v [1..10]) On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin <[EMAIL PROTECTED]> wrote: > forgot return, of course: > > > myTake :: IO [Int] > > myTake = do > > n <- rand 1 10 > > return $ take n [1..10] > > > Lev Walkin wrote: > >> Iain Barnett wrote: >> >>> Hi, >>> >>> I have a function, that produces a random number between two given >>> numbers >>> >>> rand :: Int -> Int -> IO Int >>> rand low high = getStdRandom (randomR (low,high)) >>> >>> >>> (Naively) I'd like to write something like >>> >>> take (rand 1 10 ) [1..10] >>> >>> and see [1,2,3,4] ... or anything but nasty type-error messages. >>> >> >> myTake :: IO [Int] >> myTake = do >>n <- rand 1 10 >>take n [1..10] >> >> or >> >> myTake = rand 1 10 >>= \n -> take n [1..10] >> >> or >> >> myTake = rand 1 10 >>= flip take [1..10] >> >> I'm reading about 6 tutorials on monads simultaneously but still can't >>> crack this simple task, and won't pain you with all the permutations of code >>> I've already tried. It's a lot, and it ain't pretty. >>> >>> Would anyone be able to break away from C/C++ vs Haskell to help? Just a >>> point in the right direction or a good doc to read, anything that helps will >>> be much appreciated. >>> >> >> >> Monad enlightenment happens after 7'th monad tutorial. Verified by me >> and a few of my friends. >> >> > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] pure Haskell database
Hi. I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. Thanks Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
Your forgetfulness boosted my ego for a few seconds - I wasn't the only one! :) Thanks very much, that's a big help. Iain On 24 Sep 2008, at 10:10 pm, Lev Walkin wrote: forgot return, of course: > myTake :: IO [Int] > myTake = do > n <- rand 1 10 > return $ take n [1..10] Lev Walkin wrote: Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error messages. myTake :: IO [Int] myTake = do n <- rand 1 10 take n [1..10] or myTake = rand 1 10 >>= \n -> take n [1..10] or myTake = rand 1 10 >>= flip take [1..10] I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty. Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated. Monad enlightenment happens after 7'th monad tutorial. Verified by me and a few of my friends. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[12]: [Haskell-cafe] Climbing up the shootout...
Hello Brandon, Thursday, September 25, 2008, 12:43:55 AM, you wrote: >> as i said, eddorts to optimize Haskell code is several times larger >> while the result is several times slower > ...and we're back to "dons demonstrated otherwise, so you have to please show me example that you mean and i will show exact reasons why this Haskell code wasn't compared to the best C code -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Wed, Sep 24, 2008 at 4:17 PM, Manlio Perillo <[EMAIL PROTECTED]>wrote: > I need a simple, concurrent safe, database, written in Haskell. > A database with the interface of Data.Map would be great, since what I need > to to is atomically increment some integer values, and I would like to avoid > to use SQLite. > How about "MVar (Map k Int)"? or even "Map k (MVar Int)"? -- Rich LOI: https://www.google.com/reader/shared/00900594587109808626 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On Wed, 24 Sep 2008, Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) If you only need arbitrary numbers, not really random ones, you should stay away from IO: http://www.haskell.org/haskellwiki/Humor/Erlk%C3%B6nig http://www.haskell.org/haskellwiki/Haskell_programming_tips#Separate_IO_and_data_processing ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[12]: [Haskell-cafe] Climbing up the shootout...
Hello Brandon, Thursday, September 25, 2008, 12:43:55 AM, you wrote: >> as i said, eddorts to optimize Haskell code is several times larger >> while the result is several times slower > ...and we're back to "dons demonstrated otherwise, so you have to > invent reasons to disqualify him". If all you can do is get in the > way of people doing what you claim is impossible, please stop. and btw it's you who doesn't have any technical arguments and try to "disqualify" me instead. if you have something technical to say, you may do it instaed of Don. if you just *believe* that Haskell is cool while not knowing anything about tech details, you can stop this meaningless talk -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[12]: [Haskell-cafe] Climbing up the shootout...
On Wed, Sep 24, 2008 at 11:20 PM, Bulat Ziganshin <[EMAIL PROTECTED]> wrote: > please show me example that you mean and i will show exact reasons > why this Haskell code wasn't compared to the best C code The shootout seems pretty popular, and there's still a lot of C programmers around, so I wonder why the C code on the shootout would be of poor quality. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Injecting Haskell into C
you'll find this example really helpfull -- Forwarded message -- From: Claude Heiland-Allen <[EMAIL PROTECTED]> Date: 2008/6/5 Subject: Re: [Haskell-cafe] example of FFI FunPtr To: "Galchin, Vasili" <[EMAIL PROTECTED]> Cc: haskell Galchin, Vasili wrote: > > Hello, > > I want to model a Haskell function that is a callback from C. I have > only found one example in the unix package's Semaphore.hsc, which apparently > is not used. I want to be able to marshall a Haskell function that is a > first class citizen residing in a Haskell data type and pass to a C function > via FFI. Are there examples of this? Attached is a simple example. The main thing to note is 'foreign import ccall "wrapper"' which gives you a factory for turning Haskell functions into foreign function pointers. More information: http://www.cse.unsw.edu.au/~chak/haskell/ffi/ Claude -- http://claudiusmaximus.goto10.org CallBacker: CallBacker.hs callerback.c callerback.h ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe module Main(main) where import Foreign.C.Types(CDouble) import Foreign.Ptr(FunPtr, freeHaskellFunPtr) foreign import ccall "wrapper" wrap :: (CDouble -> CDouble) -> IO (FunPtr (CDouble -> CDouble)) foreign import ccall "callerback.h twice" twice :: FunPtr (CDouble -> CDouble) -> CDouble -> IO CDouble square :: CDouble -> CDouble square x = x * x main :: IO () main = do squareW <- wrap square let x = 4 y <- twice squareW x z <- twice squareW y print y print z freeHaskellFunPtr squareW #include "callerback.h" double twice(d2d f, double x) { return f(f(x)); } #ifndef CALLERBACK_H #define CALLERBACK_H typedef double (d2d)(double); double twice(d2d f, double x); #endif CallBacker: CallBacker.hs callerback.c callerback.h ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. On 24 Sep 2008, at 10:13 pm, John Van Enk wrote: And the one liner: (rand 1 10) >>= return . (\v -> take v [1..10]) my last attempt before emailing was (rand 1 10 ) >>= (\x -> take x [1..10]) So close! :) I can see now, with all the examples, why the return is needed, but not why the composition operator is. Something for me to look into. Thanks for the input. On 24 Sep 2008, at 10:25 pm, Henning Thielemann wrote: If you only need arbitrary numbers, not really random ones, you should stay away from IO: http://www.haskell.org/haskellwiki/Humor/Erlk%C3%B6nig http://www.haskell.org/haskellwiki/ Haskell_programming_tips#Separate_IO_and_data_processing You're right, arbritary will be fine. It's relatively easy to get random numbers in other languages so I just started there, but while researching I had seen a few people lament the tying up of IO with rands, but I couldn't understand some of the other solutions presented. Thanks for the links, I'll give them a read. On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin <[EMAIL PROTECTED]> wrote: forgot return, of course: > myTake :: IO [Int] > myTake = do > n <- rand 1 10 > return $ take n [1..10] Lev Walkin wrote: Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int -> Int -> IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error messages. myTake :: IO [Int] myTake = do n <- rand 1 10 take n [1..10] or myTake = rand 1 10 >>= \n -> take n [1..10] or myTake = rand 1 10 >>= flip take [1..10] I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty. Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated. Monad enlightenment happens after 7'th monad tutorial. Verified by me and a few of my friends. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[14]: [Haskell-cafe] Climbing up the shootout...
Hello david48, Thursday, September 25, 2008, 1:38:55 AM, you wrote: >> please show me example that you mean and i will show exact reasons >> why this Haskell code wasn't compared to the best C code > The shootout seems pretty popular, and there's still a lot of C > programmers around, so I wonder why the C code on the shootout would > be of poor quality. 1. speed of most shootout examples heavily depends on availability and quality of libraries bundled with the compiler. shootout authors doesn't allow to use 3rd-party libs nor rewrite this functionality from scratch. for example C lays down in multithreading tests because C compilers doesn't include green thread libs 2. unlike Don, C authors can't modify libs bundled to their compilers to reach out maximum speed on these benchmarks. for example, using of readInt instead of generic read allowed to make program tens times faster and even outperform a bit C version that uses standard library functions -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On Wed, 24 Sep 2008, Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. ... and then replicateM ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[14]: [Haskell-cafe] Climbing up the shootout...
I'm going to have to agree with David... even if you ignore the multi-threaded projects, why couldn't the C programs just implement very specific version of the third party library inside their code? Is there anything stopping them? On Wed, Sep 24, 2008 at 5:50 PM, Bulat Ziganshin <[EMAIL PROTECTED]>wrote: > Hello david48, > > Thursday, September 25, 2008, 1:38:55 AM, you wrote: > >> please show me example that you mean and i will show exact reasons > >> why this Haskell code wasn't compared to the best C code > > > The shootout seems pretty popular, and there's still a lot of C > > programmers around, so I wonder why the C code on the shootout would > > be of poor quality. > > 1. speed of most shootout examples heavily depends on availability and > quality of libraries bundled with the compiler. shootout authors > doesn't allow to use 3rd-party libs nor rewrite this functionality > from scratch. for example C lays down in multithreading tests because > C compilers doesn't include green thread libs > > 2. unlike Don, C authors can't modify libs bundled to their compilers > to reach out maximum speed on these benchmarks. for example, using > of readInt instead of generic read allowed to make program tens times > faster and even outperform a bit C version that uses standard library > functions > > > -- > Best regards, > Bulatmailto:[EMAIL PROTECTED] > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Climbing up the shootout...
Hallo, John Van Enk wrote: > I'm going to have to agree with David... even if you ignore the > multi-threaded projects, why couldn't the C programs just implement very > specific version of the third party library inside their code? Is there > anything stopping them? > Maybe they don't care *that* much? Cheers, -alex http://www.ventonegro.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Wed, Sep 24, 2008 at 11:17:01PM +0200, Manlio Perillo wrote: > Hi. > > I need a simple, concurrent safe, database, written in Haskell. > A database with the interface of Data.Map would be great, since what I need > to to is atomically increment some integer values, and I would like to avoid > to use SQLite. I've tried writing at least part of that. But it's still higly experimental and uses template haskell. It looks like this: from that some datastructures are defined which look like tables used in traditional RDBMS such as SQLite.. However if you don't want to use many "tables" you may be a lot faster writing down what you need yourself. My lib automacially generates code for inserting / deleting tuples into multi indexes such as (Map Int (Map Int PrimIdx)). $(let cds = defaultTable { tblName = "cds" , columns = [ ("cdId", conT ''Int) , ("title", conT ''Int) ] , primary = PrimaryUniq [ "cdId" ] [| 0 |] , indexes = [ Index "title" [] ] , tblStates = [ ( "nextCdId", [t| Int |], [| 0 |] ) ] } tracks = let a="a" -- updateNumRows n = [| \n -> cdUpdateByPK (\r -> r { num_tracks = (num_tracks r) + $(n) } ) |] in defaultTable { tblName = "tracks" , columns = [ ("trackId", conT ''Int ) , ("name", conT ''String) , ("cd", conT ''Int) -- foreign key ] , primary = PrimaryUniq [ "cd", "trackId" ] [| 0 |] , indexes = [ Index "cd" [ IndexUnique "trackId" ] ] --the id is uniq foreach cd -- checks = [ foreignConstraint "cd" "cds" "id" ] -- triggers = [ InsertUpdate (Just ["cd"]) [| cdUpdateByPK ( updateNum_tracks (+1) ) . pk |] -- DeleteUpdate (Just ["cd"]) [| cdUpdateByPK ( updateNum_tracks (-1) ) . pk |] -- ] } db = defaultDB { dbName = "my" , tables = [ cds, tracks] , statistics = True } in createDB db) If you're interested drop me a mail. Marc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[16]: [Haskell-cafe] Climbing up the shootout...
Hello John, Thursday, September 25, 2008, 1:55:18 AM, you wrote: ask benchmark authors or just examine code before making any conclusions. for example, in sumfile behcnmark, C entries use fgets+atoi or C++ streams to read input numbers so C works 2x slower than Clean and 4x slower than low-level Haskell code (which wasn't accepted for the same reasons). so we have "fight of invalids" where Haskell invalid was made much faster (on this test) by adding special function to ghc libs > I'm going to have to agree with David... even if you ignore the > multi-threaded projects, why couldn't the C programs just implement > very specific version of the third party library inside their code? Is there > anything stopping them? > > On Wed, Sep 24, 2008 at 5:50 PM, Bulat Ziganshin > <[EMAIL PROTECTED]> wrote: > Hello david48, > > Thursday, September 25, 2008, 1:38:55 AM, you wrote: >>> please show me example that you mean and i will show exact reasons >>> why this Haskell code wasn't compared to the best C code > >> The shootout seems pretty popular, and there's still a lot of C >> programmers around, so I wonder why the C code on the shootout would >> be of poor quality. > > > 1. speed of most shootout examples heavily depends on availability and > quality of libraries bundled with the compiler. shootout authors > doesn't allow to use 3rd-party libs nor rewrite this functionality > from scratch. for example C lays down in multithreading tests because > C compilers doesn't include green thread libs > > 2. unlike Don, C authors can't modify libs bundled to their compilers > to reach out maximum speed on these benchmarks. for example, using > of readInt instead of generic read allowed to make program tens times > faster and even outperform a bit C version that uses standard library > functions > > > -- > Best regards, > Bulat mailto:[EMAIL PROTECTED] > > ___ > > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On Wed, 2008-09-24 at 22:44 +0100, Iain Barnett wrote: > On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: > > For one approach, check > > out 'replicate' to make copies of something, and then 'sequence' to > > run them and return a list. > Thanks, I haven't found anything that explains 'sequence' well yet, > but I'll keep looking. sequence is one of your more general-purpose loop functions in Haskell. Frequently, the number of passes in a loop and the job of each pass are fixed before-hand. Standard lazy-evaluation constructs like iterate, replicate, and map make it easy to produce a list of the passes you want to use. (This is the data-structure-as-control-construct pattern). sequence then supplies the last step: it takes a list (in the principle examples, a list of passes through some loop) and returns a loop that goes through and executes all the passes. In sequence, ironically enough. > On 24 Sep 2008, at 10:13 pm, John Van Enk wrote: > > And the one liner: > > (rand 1 10) >>= return . (\v -> take v [1..10]) > my last attempt before emailing was > (rand 1 10 ) >>= (\x -> take x [1..10]) > So close! :) > I can see now, with all the examples, why the return is needed, but > not why the composition operator is. Something for me to look into. Btw: the composition operator isn't needed. You can inline it into your example and get (rand 1 10) >>= (\ v -> return ((\ v -> take v [1..10]) v)) (which is equivalent to the clearer (rand 1 10) >>= (\ v -> return (take v [1..10])) by a step closely related to inlining (beta-contraction, to be specific)). I don't know why composition was used in this case. Using the version (\ v -> take v [1..10]) <$> (rand 1 10) and using the definition f <$> a = a >>= return . f gives rise to it. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Injecting Haskell into C
> As I understand, there are two ways to do that. Either Haskell code is > called from C, or C code is called for Haskell. So my questions are: > 1. Are they both possible? Yep. > 2. If yes, which is better performance-wise? (C function is > performance-critical). If generated function is called many times, > how big an overhead is going to be? I'm also interested in an answer to this, since I have a program that does both, quite a bit. Of course the real answer is to try to profile it, but I'm also interested in the theory of what's going on in both directions (I'm using safe imports of course, since there are callbacks). I have a bit of a performance problem with the C->haskell part, but that may also be all the marshalling the haskell side has to do (both via the with / alloca approach, and malloc in haskell and free() in C), and I'd like to know a bit more before I go wild trying to cache data in C that comes from haskell. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Am I doing it right?
"Creighton Hogg" <[EMAIL PROTECTED]> wrote: > So as another step in my education, I wanted to ask if the following > code at least feels 'morally' correct as a find/replace function, > replacing each occurrence of the sub-list before with after in the > list. > Besides not using head, tail and isPrefixOf I would write it the same, except that I'd write it like this: -->8 import Data.ByteString.Lazy.Char8 as B import Prelude as P cut = let f _ s [] = [s] f n s (x:xs) = let (h,t) = B.splitAt (x - n) s in h:f x t xs in f 0 replace before@(b:_) after this = let before' = B.pack before after' = B.pack after f s | B.tail before' `B.isPrefixOf` B.tail s = B.append after' $ B.drop (B.length before') s | otherwise = s in B.concat $ P.map f $ cut this $ B.elemIndices b this main = B.interact $ replace "th" "s" -->8 As we all love benchmarks so dearly, here are the times: ./replace < /usr/share/dict/words > /dev/null 1.29s user 0.02s system 87% cpu 1.498 total ./replace < /usr/share/dict/words > /dev/null 0.25s user 0.02s system 84% cpu 0.313 total -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Am I doing it right?
Achim Schneider <[EMAIL PROTECTED]> wrote: > "Creighton Hogg" <[EMAIL PROTECTED]> wrote: > > > So as another step in my education, I wanted to ask if the following > > code at least feels 'morally' correct as a find/replace function, > > replacing each occurrence of the sub-list before with after in the > > list. > > > Besides not using head, tail and isPrefixOf I would write it the same, > except that I'd write it like this: > Coming to think of it, I really don't like those temporary Int64's, memchr or not. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
On 2008 Sep 24, at 17:44, Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. sequence turns a list of monadic values into a monadic list of values, i.e. [m a] becomes m [a]. In IO, this is [IO a] -> IO [a]. This lets you do something like replicate an I/O action, then turn the list of I/ O actions into a single I/O action on a list. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Am I doing it right?
Am Donnerstag, 25. September 2008 00:39 schrieb Achim Schneider: > "Creighton Hogg" <[EMAIL PROTECTED]> wrote: > > So as another step in my education, I wanted to ask if the following > > code at least feels 'morally' correct as a find/replace function, > > replacing each occurrence of the sub-list before with after in the > > list. > > Besides not using head, tail and isPrefixOf I would write it the same, > except that I'd write it like this: > > -->8 > > import Data.ByteString.Lazy.Char8 as B > import Prelude as P > > cut = > let f _ s [] = [s] > f n s (x:xs) = > let (h,t) = B.splitAt (x - n) s > in h:f x t xs > in f 0 > > > replace before@(b:_) after this = > let > before' = B.pack before > after' = B.pack after > f s | B.tail before' `B.isPrefixOf` B.tail s = > B.append after' $ B.drop (B.length before') s > > | otherwise = s > > in B.concat $ P.map f $ cut this $ B.elemIndices b this > > main = > B.interact $ replace "th" "s" > > -->8 > > As we all love benchmarks so dearly, here are the times: > > ./replace < /usr/share/dict/words > /dev/null 1.29s user 0.02s system > 87% cpu 1.498 total > > ./replace < /usr/share/dict/words > /dev/null 0.25s user 0.02s system > 84% cpu 0.313 total If you love benchmarks, how about: [EMAIL PROTECTED]:~/Documents/haskell/move> time ./replaceAS < /usr/share/dict/ger-eng.txt > /dev/null real0m1.227s user0m1.130s sys 0m0.100s [EMAIL PROTECTED]:~/Documents/haskell/move> time ./replaceKMP < /usr/share/dict/ger-eng.txt > /dev/null real0m0.179s user0m0.130s sys 0m0.050s where the latter is - module Main (main) where import qualified Data.ByteString.Lazy.Char8 as B import qualified Data.ByteString.Search.KnuthMorrisPratt as KMP replace before after this = let pat = B.pack before rep = B.pack after lp = B.length pat ixs = KMP.matchLL pat this offs = zipWith (-) ixs (0:map (+ lp) ixs) wrk bs [] = [bs] wrk bs (o:os) = let (h,t) = B.splitAt o bs rm = B.drop lp t in h:rep:wrk rm os in B.concat $ wrk this offs main = B.interact $ replace "th" "s" --- just to stay close to your code and because I didn't want to think about a really fast search&replace implementation. Note that longer patterns give a better advantage to the stringsearch package, searching for "this" (replacing with "that") gives [EMAIL PROTECTED]:~/Documents/haskell/move> time ./replaceAS < /usr/share/dict/ger-eng.txt > /dev/null real0m1.222s user0m1.130s sys 0m0.080s [EMAIL PROTECTED]:~/Documents/haskell/move> time ./replaceKMP < /usr/share/dict/ger-eng.txt > /dev/null real0m0.124s user0m0.080s sys 0m0.040s [EMAIL PROTECTED]:~/Documents/haskell/move> time ./replaceBM < /usr/share/dict/ger-eng.txt > /dev/null real0m0.093s user0m0.060s sys 0m0.030s The fast searching function on ByteStrings has already been written for you :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] [Streams] Couldn't match expected type ?`Distribution.Verbosity.Verbosity'
I cannot compile Streams 0.1: % darcs pull Pulling from "http://software.pupeno.com/Streams-0.1";... No remote changes to pull in! % make runhaskell Setup.lhs configure Setup.lhs:11:53: Couldn't match expected type `Distribution.Verbosity.Verbosity' against inferred type `IO FilePath' In the first argument of `readPackageDescription', namely `pkg_descr_file' In a 'do' expression: pkg_descr <- readPackageDescription pkg_descr_file In the expression: do pkg_descr_file <- defaultPackageDesc pkg_descr <- readPackageDescription pkg_descr_file let isWindows = "mingw" `isPrefixOf` System.Info.os config = ... defaultMainNoRead config make: *** [.setup-config] Error 1 % ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Streams] Couldn't match expected type ?`Distribution.Verbosity.Verbosity'
On 2008 Sep 24, at 20:14, Stephane Bortzmeyer wrote: % ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 You probably have 6.8.2's Cabal (in the 1.2 series), while the package requires 1.4 (and 1.2 isn't smart enough to check versions). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Streams] Couldn't match expected type ?`Distribution.Verbosity.Verbosity'
On Wed, Sep 24, 2008 at 08:24:09PM -0400, Brandon S. Allbery KF8NH <[EMAIL PROTECTED]> wrote a message of 13 lines which said: > You probably have 6.8.2's Cabal (in the 1.2 series), while the package > requires 1.4 (and 1.2 isn't smart enough to check versions). How can you check that it requires 1.4 ? The Cabal file says: -- Tested-with: hugs 2003, hugs March2005, ghc 6.4.2, ghc 6.6 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Streams] Couldn't match expected type ?`Distribution.Verbosity.Verbosity'
On 2008 Sep 24, at 20:30, Stephane Bortzmeyer wrote: On Wed, Sep 24, 2008 at 08:24:09PM -0400, Brandon S. Allbery KF8NH <[EMAIL PROTECTED]> wrote a message of 13 lines which said: You probably have 6.8.2's Cabal (in the 1.2 series), while the package requires 1.4 (and 1.2 isn't smart enough to check versions). How can you check that it requires 1.4 ? The Cabal file says: -- Tested-with: hugs 2003, hugs March2005, ghc 6.4.2, ghc 6.6 Hm, that implies otherwise; if it were 1.4 then it would have a cabal- version: field. I think I have to defer to someone else. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Distributing Haskell binaries as OSX App Bundles
I wrote a command-line program recently for a friend in haskell. However, he's far away and not particularly computer literate. I sent him the raw binaries, but they came up with errors about not being able to find libgmp stuff. So then I thought I should probably be able to somehow distribute all the stuff together in a .app bundle. However, the only experience I have of doing this sort of stuff before is via xcode. What's the best way to go about this? It just occurred to me now that maybe cmake is the way to go? Any advice that might save me some time would be really appreciated. Cheers, Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell board game
Hello, I'm interested in doing a simple board game on haskell. For that I want to be able to draw stuff like the possible player movements and I want to be able to display very simple animations. I want to know what graphical interface library you suggest to me. I have almost no prior experience with graphical interfaces of any kind, so I rather start with something easy and straightforward. I have no need for great performance or anything like that. I'd like if it runs on windows with much trouble, that is, it'll be easy to package it for windows without requiring the user to install anything besides my game. My first thought was to use GTK's gtkTable, but I'm unsure how easy it is to make it work on windows. Beside that, I'm not sure it would be the easiest API for me to use. []'s Rafael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell board game
> I'm interested in doing a simple board game on haskell. For that I want > to be able to draw stuff like the possible player movements and I want > to be able to display very simple animations. I want to know what > graphical interface library you suggest to me. There's (at least) two comprehensive APIs for drawing pictures from haskell. If you need 3D, then OpenGL is your best choice. For 2D you can still use OpenGL, but you may prefer the cairo bindings, which provide an easy to use postscript-style vector drawing model. Tim http://www.haskell.org/haskellwiki/Opengl http://haskell.org/gtk2hs/archives/category/cairo/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell board game
check out http://www.haskell.org/soe/ On Wed, Sep 24, 2008 at 7:23 PM, Tim Docker <[EMAIL PROTECTED]> wrote: >> I'm interested in doing a simple board game on haskell. For that I want >> to be able to draw stuff like the possible player movements and I want >> to be able to display very simple animations. I want to know what >> graphical interface library you suggest to me. > > There's (at least) two comprehensive APIs for drawing pictures from > haskell. If you need 3D, then OpenGL is your best choice. For 2D you can > still use OpenGL, but you may prefer the cairo bindings, which provide an > easy to use postscript-style vector drawing model. > > Tim > > http://www.haskell.org/haskellwiki/Opengl > http://haskell.org/gtk2hs/archives/category/cairo/ > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Daryoush Weblog: http://perlustration.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] need help making sense of the type ...
I am having hard time making sense of the types in the following example from the Applicative Programming paper: http://www.cs.nott.ac.uk/~ctm/IdiomLite.pdf ap :: Monad m ⇒ m (a → b ) → m a → m b ap mf mx = do f ← mf x ← mx return (f x ) Using this function we could rewrite sequence as: sequence :: [ IO a ] → IO [ a ] sequence [ ] = return [ ] sequence (c : cs ) =* return (:) 'ap' c *'ap' sequence cs I am specifically confused over the type of "m" in: return (:) 'ap' c "c" is obviously an instance of IO a monad. "return (:)" on the other hand (at least as I would expect it) is an instance of " ->" monad. a) are the above statements correct? b) if so, does it make sense for the "ap" function to have two different instances of the "m"? thanks for you help daryoush ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] need help making sense of the type ...
On 2008 Sep 24, at 22:51, Daryoush Mehrtash wrote: I am having hard time making sense of the types in the following example from the Applicative Programming paper: http://www.cs.nott.ac.uk/~ctm/IdiomLite.pdf ap :: Monad m ⇒ m (a → b ) → m a → m b ap mf mx = do f ← mf x ← mx return (f x ) Using this function we could rewrite sequence as: sequence :: [ IO a ] → IO [ a ] sequence [ ] = return [ ] sequence (c : cs ) = return (:) 'ap' c 'ap' sequence cs I am specifically confused over the type of "m" in: return (:) 'ap' c "c" is obviously an instance of IO a monad. "return (:)" on the other hand (at least as I would expect it) is an instance of " ->" monad. Note that he first argument to ap is a function wrapped by a monad. "return (:)" wraps the function/operator (:) in an arbitrary monad (but then the type signature of sequence makes the monad IO). (:) :: a -> [a] -> [a] return (:) :: IO (a -> ([a] -> [a])) -- b is ([a] -> [a]) ap (return (:)) :: IO a -> IO ([a] -> [a]) -- (IO a) is (m a) and (IO ([a] -> [a])) is (m b) return (:) `ap` c :: IO ([a] -> [a]) -- c is (IO a) per type signature return (:) `ap` c `ap` :: IO [a] -> IO [a] -- f in ap is the preceding IO ([a] -> [a]) return (:) `ap` c `ap` sequence cs :: IO [a] -- (sequence cs) is (IO [a]) per type signature -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Red-Blue Stack
Hey guys, This is probably more of a question about functional programming than it is about Haskell, but hopefully you can help me out. I'm new to thinking about things in a functional way so I'm not sure what the best way to do some things are. I'm in a data structures course right now, and the assignments for the course are done in Java. I figured it'd be fun to try and implement them in Haskell as well. The part of the assignment I'm working on is to implement a RedBlueStack, a stack where you can push items in as either Red or Blue. You can pop Red and Blue items individually, but the stack has to keep track of the overall order of items. i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, Blue] All push and pop operations on the stack have to be done in O(1) time. It was easy to do in Java since you can just keep track of everything with a few pointers, but it took a while to get the Haskell version working. Maybe I'm just not used to the functional way of doing things. I originally had this: data RBSItem a = Red a | Blue a data RedBlueStack a = RBS { red :: [RBSItem a], blue:: [RBSItem a], overall :: [RBSItem a] } But there was no way to keep popping in O(1) time because I would have to walk through the overall list when removing items. I eventually came up with: data ShowColour = PlusRed | MinusRed | PlusBlue | MinusBlue data RedBlueStack a = RBS { red :: [a], blue :: [a], order :: [ShowColour] } popRed :: RedBlueStack a -> RedBlueStack a popRed (RBS (r:rs) b o) = RBS rs b (MinusRed : o) popRed rbs@(RBS [] _ _) = rbs -- As an aside here, would it be better to put "popRed = id" for the catch-all in popRed instead of what I have? -- I don't know proper Haskell coding style yet. remUseless :: [ShowColour] -> [ShowColour] remUseless order@(x:xs) | x == MinusRed = remShowColour PlusRed xs | x == MinusBlue = remShowColour PlusBlue xs | otherwise = order where remShowColour r (c:cs) | c == r= cs | otherwise = c : remShowColour r cs remShowColour _ [] = error "Incorrect Stack Order" So instead of walking through the overall list, I just have to add a MinusRed or MinusBlue to the order list. This makes the pop and push functions operate in O(1) time, but it seems a bit excessive, because whenever the overall order of the stack is needed (e.g. printing the stack) I need to clean up the order list. I was just wondering whether this is the best way to implement something like this, keeping track of changes made instead of making the changes. If anyone has any ideas for other ways of implementing this I'd love to see them. I didn't take into account that Haskell is lazy. Will that have any effect on the running time? Probably not for a simple program like this, but for larger ones and more complex data structures and algorithms, I'm guessing it would? Thanks, Matt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Doing something constructive. [Was: Climbing up the shootout...]
On Wed, Sep 24, 2008 at 12:31 PM, Don Stewart <[EMAIL PROTECTED]> wrote: >> Twisted (a Python asynchronous framework) is a confortable environment, >> but I feel concurrent Haskell is superior. > > Should be a lot faster, given there's compiled native code, and no > global locks. The concurrent Haskell programming model is vastly nicer. Twisted is entirely event-driven, so it's nearly as far from a comfortable environment as you might hope to stretch. I can't speak to their respective performance strengths. However, I've done quite a bit of concurrent networking with lightweight coroutines in Python (greenlet), and its performance is nothing to write home about. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] if - then - else layout
consider this partial program: if n>5 then putStrLn "big" else putStrLn "small" this works fine in hugs, but in ghc I must change it to: if n>5 then putStrLn "big" else putStrLn "small" -- View this message in context: http://www.nabble.com/if---then---else-layout-tp19663006p19663006.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Red-Blue Stack
Try writing data RBStack = RBS [RBSItem] [RBSItem] where the first list are all the same colour and the start of the second list is a different colour. The rest should follow naturally and you will get amortised O(1) push and pop (you occasionally have to juggle the lists). By the way, for this kind of question you'll get help much faster if you ask on #haskell. Jamie On Thu, Sep 25, 2008 at 5:11 AM, Matthew Eastman <[EMAIL PROTECTED]> wrote: > Hey guys, > > This is probably more of a question about functional programming than it is > about Haskell, but hopefully you can help me out. I'm new to thinking about > things in a functional way so I'm not sure what the best way to do some > things are. > > I'm in a data structures course right now, and the assignments for the > course are done in Java. I figured it'd be fun to try and implement them in > Haskell as well. > > The part of the assignment I'm working on is to implement a RedBlueStack, a > stack where you can push items in as either Red or Blue. You can pop Red and > Blue items individually, but the stack has to keep track of the overall > order of items. > > i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, Blue] > > All push and pop operations on the stack have to be done in O(1) time. > > It was easy to do in Java since you can just keep track of everything with a > few pointers, but it took a while to get the Haskell version working. Maybe > I'm just not used to the functional way of doing things. > > I originally had this: > > data RBSItem a = Red a | Blue a > > data RedBlueStack a = RBS { >red :: [RBSItem a], >blue:: [RBSItem a], >overall :: [RBSItem a] > } > > But there was no way to keep popping in O(1) time because I would have to > walk through the overall list when removing items. > > I eventually came up with: > > data ShowColour = PlusRed | MinusRed | PlusBlue | MinusBlue > > data RedBlueStack a = RBS { >red :: [a], >blue :: [a], >order :: [ShowColour] > } > > popRed :: RedBlueStack a -> RedBlueStack a > popRed (RBS (r:rs) b o) = RBS rs b (MinusRed : o) > popRed rbs@(RBS [] _ _) = rbs > > -- As an aside here, would it be better to put "popRed = id" for the > catch-all in popRed instead of what I have? > -- I don't know proper Haskell coding style yet. > > remUseless :: [ShowColour] -> [ShowColour] > remUseless order@(x:xs) >| x == MinusRed = remShowColour PlusRed xs >| x == MinusBlue = remShowColour PlusBlue xs >| otherwise = order >where >remShowColour r (c:cs) >| c == r= cs >| otherwise = c : remShowColour r cs >remShowColour _ [] = error "Incorrect Stack Order" > > So instead of walking through the overall list, I just have to add a > MinusRed or MinusBlue to the order list. This makes the pop and push > functions operate in O(1) time, but it seems a bit excessive, because > whenever the overall order of the stack is needed (e.g. printing the stack) > I need to clean up the order list. > > I was just wondering whether this is the best way to implement something > like this, keeping track of changes made instead of making the changes. If > anyone has any ideas for other ways of implementing this I'd love to see > them. > > I didn't take into account that Haskell is lazy. Will that have any effect > on the running time? Probably not for a simple program like this, but for > larger ones and more complex data structures and algorithms, I'm guessing it > would? > > Thanks, > Matt > ___ > 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
Re: [Haskell-cafe] if - then - else layout
On 2008 Sep 25, at 0:47, leledumbo wrote: consider this partial program: if n>5 then putStrLn "big" else putStrLn "small" this works fine in hugs, but in ghc I must change it to: if n>5 then putStrLn "big" else putStrLn "small" Actually, this also works: if n > 5 then putStrLn "big" else putStrLn "small" Except in a "do", the "else" must be indented beyond the start of the "if". I think Hugs is violating the Haskell98 layout rules. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] if - then - else layout
I think you mean "in a do". There is a proposal to fix this in Haskell' cheers, Fraser On Sep 25, 2008, at 6:59, "Brandon S. Allbery KF8NH" <[EMAIL PROTECTED] > wrote: On 2008 Sep 25, at 0:47, leledumbo wrote: consider this partial program: if n>5 then putStrLn "big" else putStrLn "small" this works fine in hugs, but in ghc I must change it to: if n>5 then putStrLn "big" else putStrLn "small" Actually, this also works: if n > 5 then putStrLn "big" else putStrLn "small" Except in a "do", the "else" must be indented beyond the start of the "if". I think Hugs is violating the Haskell98 layout rules. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon university KF8NH ___ 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
[Haskell-cafe] Google Android
Hello, Do there currently (or in the works) exist FFI bindings for Google's Android API? Kind regards, Vasili ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] if - then - else layout
I think it'd be nice if we just replaced the if with a question mark :) -- _jsn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe