[Haskell-cafe] ANN: stm-chans 1.2.0
-- stm-chans 1.2.0 The stm-chans package offers a collection of channel types, similar to Control.Concurrent.STM.TChan but with additional features. -- Changes (since 1.0.0) * (Version 1.1.0) Added tryWriteTBChan. * (Version 1.1.0) Added tryWriteTBMChan. * Some major performance improvements in TBChan and TBMChan, thanks to Thomas DuBuisson. In particular, these improvements reduce contention between readers and writers, improving throughput by up to 2--3 times when producers and consumers are running in separate OS threads. The cost for non-parallel programs is trivial (1% worst-case running time, per Criterion). * Added estimateFreeSlotsTBChan, freeSlotsTBChan, estimateFreeSlotsTBMChan, and freeSlotsTBMChan. These functions return either the exact number or a lower-bound on the number of free slots available before the channels will block/retry. * Some other minor optimizations and code improvements. -- Long description In particular stm-chans offers these types: * Control.Concurrent.STM.TBChan: Bounded FIFO channels. When the channel is full, writers will block/retry. This ensures that the writers do not get too far ahead of the readers, which helps to make sure that memory and cpu resources are used responsibly. * Control.Concurrent.STM.TMChan: Closeable FIFO channels. This is like TChan (Maybe a) but with a monotonicity guarantee that once Nothing is returned all future reads will be Nothing as well. * Control.Concurrent.STM.TBMChan: Bounded Closeable FIFO channels. This combines the capabilities of TBChan and TMChan. In addition, the stm-chans package offers a (partial) compatibility layer for some recent API improvements to the stm package (see ticket #5104 [1]). These new functions include: * tryReadTChan :: TChan a - STM (Maybe a) A version of readTChan which does not retry. Instead it returns Nothing if no value is available. * peekTChan :: TChan a - STM a Get the next value from the TChan without removing it, retrying if the channel is empty. * tryPeekTChan :: TChan a - STM (Maybe a) A version of peekTChan which does not retry. Instead it returns Nothing if no value is available. [1] http://hackage.haskell.org/trac/ghc/ticket/5104 -- Links Homepage: http://code.haskell.org/~wren/ Hackage: http://hackage.haskell.org/package/stm-chans Darcs: http://community.haskell.org/~wren/stm-chans Haddock (Darcs version): http://community.haskell.org/~wren/stm-chans/dist/doc/html/stm-chans -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] trying to cabal install lambdabot, failure on 'random' package
/usr/bin/ghc --make -package-name show-0.4.1.1 -hide-all-packages -fbuilding-cabal-package -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id QuickCheck-2.4.0.1-5898cfb0116fc1d6ecef04b3f053c323 -package-id base-4.3.1.0-167743fc0dd86f7f2a24843a933b9dce -package-id random-1.0.0.3-749b78c54a8a1b32dbb45d98a91b -package-id smallcheck-0.4-008eb21a2943dfdde26401dbc145c45b -package-id syb-0.3-8db7bc4339a1cb8a6f2a46c40447ef0b -O -Wall -XHaskell98 ShowQ ShowFun SimpleReflect command line: cannot satisfy -package-id random-1.0.0.3-749b78c54a8a1b32dbb45d98a91b: random-1.0.0.3-749b78c54a8a1b32dbb45d98a91b is shadowed by package random-1.0.0.3-57524486875e0c4c260dd22788921013 (use -v for more information) World file is already up to date. cabal: Error: some packages failed to install: lambdabot-4.2.3.2 depends on show-0.4.1.1 which failed to install. lambdabot-utils-4.2.1 failed during the building phase. The exception was: ExitFailure 1 readline-1.0.1.0 failed during the configure step. The exception was: ExitFailure 1 show-0.4.1.1 failed during the building phase. The exception was: ExitFailure 1 I have ghc 7.0.,3 and cabal $ cabal --version cabal-install version 0.10.2 using version 1.10.1.0 of the Cabal library From the recent Haskell Platform for OS X. Ideas? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
Andrew Coppin wrote: OK, so strictly this is unrelated to Haskell as such. However, there's enough people doing webby stuff with Haskell that some of you must have wanted to run your code on a real, Internet-accessible web server. So does anybody have any suggestions on which companies offer the most favourable tools / pricing? I currently have a website, but it supports only CGI *scripts* (i.e., Perl or PHP). It does not support arbitrary CGI *binaries*, which is what I'd want for Haskell. In fact, I don't have control over the web server at all; I just put content on there. I'm happily using http://nearlyfreespeech.net and they offer Haskell as .cgi language (though I make no use of that). http://example72.nfshost.com/versions.php They only charge as much as you use; so far, I haven't spend more than $10 total on website hosting. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] trying to cabal install lambdabot, failure on 'random' package
show is the failing package A look on Hackage suggests that show had problems with its cabal file at versions 0.4 0.4.1 and was fixed at 0.4.1.1. Can you try installing show individually at 0.4.1.1 the try installing the rest of lambdabot. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
Linode. Can't recommend them highly enough. G On Fri, May 6, 2011 at 8:07 PM, Andrew Coppin andrewcop...@btinternet.com wrote: OK, so strictly this is unrelated to Haskell as such. However, there's enough people doing webby stuff with Haskell that some of you must have wanted to run your code on a real, Internet-accessible web server. So does anybody have any suggestions on which companies offer the most favourable tools / pricing? I currently have a website, but it supports only CGI *scripts* (i.e., Perl or PHP). It does not support arbitrary CGI *binaries*, which is what I'd want for Haskell. In fact, I don't have control over the web server at all; I just put content on there. The same provider can offer me a virtual server, but at 3x the price I'm currently paying. I simply cannot afford that kind of money just for silly toy projects. What does everybody else use? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
On 07/05/2011 09:10 AM, Gregory Collins wrote: Linode. Can't recommend them highly enough. If Linode is really the cheapest that the Internet has to offer, I'm going to need to find a job that pays /significantly/ more money... (I'm also not sure whether being billed in USD is possibly a bad idea. Banks have a habit of charging you currency conversion fees for that. Then again, I haven't found many companies that list prices in GBP.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
On 06/05/2011 07:16 PM, JP Moresmau wrote: I use Amazon EC2 Free Tier. You can install Yesod/Warp easily enough and it's fine for small traffic. My understanding is that EC2 is only free for 1 year, after which you pay full price. ($0.02/hour = $15/month if it's running full-time.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
On Sat, May 7, 2011 at 12:38, Andrew Coppin andrewcop...@btinternet.com wrote: On 07/05/2011 09:10 AM, Gregory Collins wrote: Linode. Can't recommend them highly enough. If Linode is really the cheapest that the Internet has to offer, I'm going to need to find a job that pays /significantly/ more money... (I'm also not sure whether being billed in USD is possibly a bad idea. Banks have a habit of charging you currency conversion fees for that. Then again, I haven't found many companies that list prices in GBP.) There's definitely cheaper services. We rent dedicated servers at leaseweb (leaseweb.com, they bill in euros), and they have them starting at €33. They also have virtual servers starting at €9. Their deals, especially with dedicated servers, fluctuate quite a bit, so it can pay off to check back if you can't find something good. Erik ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Manatee-0.2.1 release!
Hi all, Manatee-0.2.1 release! (Detail see: http://goo.gl/MkVw http://goo.gl/PnPbq http://goo.gl/OSpz8) New features in new version: * Show welcome page when you first time use Manatee, make manatee easier to use. * Keymap helper, you just need hit Ctrl+/ or Ctrl+? if you don't know keymap. * Window layout save/restore, you play Manatee and shutdown, all window layout will restore when you next startup. * Tab position save when you switch to other tab-group, and restore tab position when you switch back. * Use new input-framework instead manatee-anything package. * Many detail improve and bug fixed. Enjoy! -- Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
Then again, I haven't found many companies that list prices in GBP.) I use rackhost.co.uk I've had no problems with them at all, and they charge in GBP. A cheaper alternative is CheapVPS, I moved away from them since they're not terribly reliable, but probably good enough for personal websites. Nick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
On 7 May 2011 13:52, Nicolas Wu nicolas...@gmail.com wrote: Then again, I haven't found many companies that list prices in GBP.) I use rackhost.co.uk Oops, I mean rackspace.co.uk, who I believe are the people behind slicehost.com which comes highly recommended. Nick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Server hosting
I'm using tilaa.nl. It starts at ~10€/month and they are quite friendly and competent. -- Cp On Sat, May 7, 2011 at 13:53, Nicolas Wu nicolas...@gmail.com wrote: On 7 May 2011 13:52, Nicolas Wu nicolas...@gmail.com wrote: Then again, I haven't found many companies that list prices in GBP.) I use rackhost.co.uk Oops, I mean rackspace.co.uk, who I believe are the people behind slicehost.com which comes highly recommended. Nick ___ 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] Server hosting
I've had good experiences with prgmr VPSes; I currently have a 1024MB VPS that I'm paying $16 a month for (the month by month rate is $20, but I'm paying for it yearly). You can also grab a 256MB VPS for $8 month by month or $6.40 yearly, if that'd be enough. In the last year I think there was one significant outage that lasted several hours - it was due to a problem of the data center where the servers were located, and they were good about communicating why that happened, and discounted the hosting as a result. I don't think they are going to be as fast (disk access wise) as Linode (based on benchmarks I've seen, not personal experience), but are much cheaper for the same amount of RAM. At least when I was first doing haskell webdev, the amount of ram required for linking apps built with happstack was astounding, such that on my 256MB slicehost VPS, every recompile meant 20 minutes of swapping, and a completely inaccessible server. So while I didn't need the speed of a larger VPS, I did need the RAM. Since then, Linode has bumped up to 512MB ram, so the difference isn't as sharp as it used to be, but I've also had no problems with performance (I don't have any high traffic sites). Anyhow, just my experience having used them for the past year and a half. More info at prgmr.com On May 6, 2011, at 2:07 PM, Andrew Coppin wrote: OK, so strictly this is unrelated to Haskell as such. However, there's enough people doing webby stuff with Haskell that some of you must have wanted to run your code on a real, Internet-accessible web server. So does anybody have any suggestions on which companies offer the most favourable tools / pricing? I currently have a website, but it supports only CGI *scripts* (i.e., Perl or PHP). It does not support arbitrary CGI *binaries*, which is what I'd want for Haskell. In fact, I don't have control over the web server at all; I just put content on there. The same provider can offer me a virtual server, but at 3x the price I'm currently paying. I simply cannot afford that kind of money just for silly toy projects. What does everybody else use? ___ 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] Server hosting
I am considering hetzner online in Germany - http://www.hetzner.de/en/hosting/produkte_rootserver/eq4 Ralph Hodgson @ralphtq On May 7, 2011, at 6:27 AM, Charles-Pierre Astolfi c...@crans.org wrote: I'm using tilaa.nl. It starts at ~10€/month and they are quite friendly and competent. -- Cp On Sat, May 7, 2011 at 13:53, Nicolas Wu nicolas...@gmail.com wrote: On 7 May 2011 13:52, Nicolas Wu nicolas...@gmail.com wrote: Then again, I haven't found many companies that list prices in GBP.) I use rackhost.co.uk Oops, I mean rackspace.co.uk, who I believe are the people behind slicehost.com which comes highly recommended. Nick ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] lambdabot install error
Sönke Hahn wrote: There is a related bug report in ghc's trac: [1]. According to that, you could try to remove the -fvia-C flag to prevent ghc from using the C backend. (I had no luck with that, so I guess there is still another bug lurking.) Just FYI: I tried again and realised, why I had no luck: I disabled '-fvia-C' in a cabal file, but ghc still used the c backend due to an 'OPTIONS_GHC' pragma with 'fvia-C' in the code. Removing that solved it for me. HTH, Sönke [1] http://hackage.haskell.org/trac/ghc/ticket/5050 ___ 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] Server hosting
On Sat, May 7, 2011 at 12:38 PM, Andrew Coppin andrewcop...@btinternet.com wrote: On 07/05/2011 09:10 AM, Gregory Collins wrote: Linode. Can't recommend them highly enough. If Linode is really the cheapest that the Internet has to offer, I'm going to need to find a job that pays /significantly/ more money... I didn't say they were the cheapest, but IMO for VPS servers they are definitely the best. I've used cheaper providers before; one of them went out of business without warning and the other was sluggishly slow due to oversubscription. You get what you pay for. G -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For Project Euler #1 isn't it more efficient to generate just the numbers you need? Spoiler
Do you mean O(1) complexity? Don't you have to touch at least the multiples of 3 5 making it O(k) where is the number of multiples of 3 and the number of multiples of 5? On Fri, May 6, 2011 at 10:10 PM, Lyndon Maydwell maydw...@gmail.com wrote: If you're looking for efficiency, I believe you can actually do #1 in constant time: On Sat, May 7, 2011 at 7:31 AM, cas...@istar.ca wrote: -- Instead of this -- sumMultiples3or5 s = sum [x | x - [3..s-1], x `mod` 3 == 0 || x `mod` 5 == 0] -- Isn't this faster sumMultiples3or5 s = sum ([x | x - [3,6..s-1]] `merge` [x | x - [5,10..s-1]]) merge xs [] = xs merge [] ys = ys merge txs@(x:xs) tys@(y:ys) | x y = x : xs `merge` tys | x y = y : txs `merge` ys | otherwise = x : xs `merge` ys ___ 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 -- -- Regards, KC ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For Project Euler #1 isn't it more efficient to generate just the numbers you need? Spoiler
One doesn't have to touch them to compute their sum. 2011/5/7 KC kc1...@gmail.com: Do you mean O(1) complexity? Don't you have to touch at least the multiples of 3 5 making it O(k) where is the number of multiples of 3 and the number of multiples of 5? On Fri, May 6, 2011 at 10:10 PM, Lyndon Maydwell maydw...@gmail.com wrote: If you're looking for efficiency, I believe you can actually do #1 in constant time: On Sat, May 7, 2011 at 7:31 AM, cas...@istar.ca wrote: -- Instead of this -- sumMultiples3or5 s = sum [x | x - [3..s-1], x `mod` 3 == 0 || x `mod` 5 == 0] -- Isn't this faster sumMultiples3or5 s = sum ([x | x - [3,6..s-1]] `merge` [x | x - [5,10..s-1]]) merge xs [] = xs merge [] ys = ys merge txs@(x:xs) tys@(y:ys) | x y = x : xs `merge` tys | x y = y : txs `merge` ys | otherwise = x : xs `merge` ys ___ 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 -- -- Regards, KC ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Principal Engineer, Mirantis Inc. http://www.mirantis.com/ Editor, http://fprog.ru/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Those damned parentheses
Hi. I am kind of tired of all of the parentheses I have to put in places and I'm trying to figure out what is the correct way to write code such that I can leave out parentheses. For example, I have the following: data Message = ... --leaving this out because it's not important data Plane = Plane { id :: Int, position:: (Int,Int,Int), direction :: Int, path:: [Int], messagebuf :: Chan Message } main = do c - newChan :: Chan Message p - Plane 0 (0,0,0) 0 [] c f p f p = putStrLn $ (show Main.id p) ++ - message received This causes an error The function `show' is applied to two arguments. If I put instead: f p = putStrLn $ (show . Main.id p) ++ - message received I get the error Couldn't match expected type `[Char]' with actual type `a0 - c0'. The only way it seems to work is f p = putStrLn $ (show (Main.id p)) ++ - message received This seems to be the same for many other situations where I try to use function composition of some sort. It's just getting kind of annoying. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Those damned parentheses
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 5/7/11 15:10 , Eitan Goldshtrom wrote: I get the error Couldn't match expected type `[Char]' with actual type `a0 - c0'. The only way it seems to work is f p = putStrLn $ (show (Main.id p)) ++ - message received Interestingly enough, you have the correct answer in there as well: $ f p = putStrLn $ (show $ Main.id p) ++ = message received You may also want to look into Control.Applicative. - -- brandon s. allbery [linux,solaris,freebsd,perl]allber...@gmail.com system administrator [openafs,heimdal,too many hats]kf8nh -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk3FmykACgkQIn7hlCsL25X9cQCeM2leHUslCJWW1GIFKtt5Dw9P gFoAn1DbWu9QO89062Dx6hMIPRNq6siU =P2Zz -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Those damned parentheses
On Sat, May 7, 2011 at 2:10 PM, Eitan Goldshtrom thesource...@gmail.com wrote: Hi. I am kind of tired of all of the parentheses I have to put in places and I'm trying to figure out what is the correct way to write code such that I can leave out parentheses. For example, I have the following: data Message = ... --leaving this out because it's not important data Plane = Plane { id :: Int, position :: (Int,Int,Int), direction :: Int, path :: [Int], messagebuf :: Chan Message } main = do c - newChan :: Chan Message p - Plane 0 (0,0,0) 0 [] c f p f p = putStrLn $ (show Main.id p) ++ - message received One thing to keep in mind is that function application binds tightest, and function application goes from left to right, so: a b c d is parsed as: ((a b) c) d I'm not really sure what you're doing, but I would probably write it as: f p = putStrLn $ show (Main.id p) ++ - message received Because function application binds tightest, I don't need parenthesis around the (show ...) part. The other rule to note is the the ($) function binds the weakest of them all, so you can do a lot to the left of it and to the right of it without parentheses. This causes an error The function `show' is applied to two arguments. If I put instead: f p = putStrLn $ (show . Main.id p) ++ - message received I get the error Couldn't match expected type `[Char]' with actual type `a0 - c0'. The only way it seems to work is f p = putStrLn $ (show (Main.id p)) ++ - message received This seems to be the same for many other situations where I try to use function composition of some sort. It's just getting kind of annoying. -Eitan ___ 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] Those damned parentheses
I know about the $ symbol, that's why it's in there in the respective places. I see that I can use it to fix my problem, but I was trying to figure out function composition really. I guess that's just not the place for it. I'll check out Control.Applicative. Also thanks for the clarification on function application. I know functions are by default infixl 9, but I hadn't really thought that through all the way. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] For Project Euler #1 isn't it more efficient to generate just the numbers you need? Spoiler
Got it. You mean use the formula for summing an arithmetic progression twice and take account of duplicates. Sheer genius! On Sat, May 7, 2011 at 11:56 AM, Eugene Kirpichov ekirpic...@gmail.com wrote: One doesn't have to touch them to compute their sum. 2011/5/7 KC kc1...@gmail.com: Do you mean O(1) complexity? Don't you have to touch at least the multiples of 3 5 making it O(k) where is the number of multiples of 3 and the number of multiples of 5? On Fri, May 6, 2011 at 10:10 PM, Lyndon Maydwell maydw...@gmail.com wrote: If you're looking for efficiency, I believe you can actually do #1 in constant time: On Sat, May 7, 2011 at 7:31 AM, cas...@istar.ca wrote: -- Instead of this -- sumMultiples3or5 s = sum [x | x - [3..s-1], x `mod` 3 == 0 || x `mod` 5 == 0] -- Isn't this faster sumMultiples3or5 s = sum ([x | x - [3,6..s-1]] `merge` [x | x - [5,10..s-1]]) merge xs [] = xs merge [] ys = ys merge txs@(x:xs) tys@(y:ys) | x y = x : xs `merge` tys | x y = y : txs `merge` ys | otherwise = x : xs `merge` ys ___ 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 -- -- Regards, KC ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Principal Engineer, Mirantis Inc. http://www.mirantis.com/ Editor, http://fprog.ru/ -- -- Regards, KC ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
Sorry for third post but I wonder why the many instances are restricted by Monad. Both Functor and Applicative can by constructed without Monad: instance (Functor m) = Functor (CtlArg t m) where fmap f (CtlArg arg g c) = CtlArg arg (fmap f . g) c instance (Functor m) = Functor (Iter t m) where {-# INLINE fmap #-} fmap f (Iter g) = Iter (fmap f . g instance (Functor m) = Functor (IterR t m) where fmap f (IterF i) = IterF (fmap f i) fmap f (IterM i) = IterM (fmap (fmap f) i) fmap f (IterC c) = IterC (fmap f c) fmap f (Done a c) = Done (f a) c fmap f (Fail i m mc) = Fail i (fmap f m) mc instance (Functor m) = Applicative (Iter t m) where {-# INLINE pure #-} pure x = Iter $ Done x {-# INLINE (*) #-} Iter a * bi@(Iter b) = Iter $ \c - fix (\f ir - case ir of IterF cont - cont * bi IterM m - IterM $ fmap f m IterC (CtlArg a cn ch) - IterC (CtlArg a (\r - cn r * bi) ch) Done v ch - fmap v (b ch) Fail f _ ch - Fail f Nothing ch) a c Since every monad is applicative (or rather should be) it doesn't loose generality. Join is also defined by using only functor: joinI :: (Functor m) = Iter t m (Iter t m a) - Iter t m a joinI (Iter i) = Iter $ \c - fix (\f x - case x of IterF cont - IterF (joinI cont) IterM m - IterM $ fmap f m IterC (CtlArg a cn ch) - IterC (CtlArg a (\r - joinI (cn r)) ch) Done v ch - runIter v ch Fail f _ ch - Fail f Nothing ch) (i c) Regards PS. I haven't tested the code or benchmarked it - but it seems it is possible. signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
At Sat, 07 May 2011 21:50:13 +0100, Maciej Marcin Piechotka wrote: Sorry for third post but I wonder why the many instances are restricted by Monad. It would be great if Functor were a superclass of Monad. However, since it isn't, and since I can't think of anything particularly useful to do with Iters over Functors that aren't also Monads, I'd rather just pass one dictionary around than two. So my convention throughout the library is that m has to be a Monad but doesn't have to be a Functor. In general, I try to place as few requirements in the contexts of functions as possible. However, I also want to be able to call most functions from most other ones. If some of the useful low-level functions end up requiring Functor, then most functions in the library are going to end up requiring (Functor m, Monad m) = instead of (Monad m) =, which will actually end up increasing the amount of stuff in contexts. (Of course, (Iter t m) itself is an Applicative Functor, even when m is just a Monad. So that I make use of in the parsing module.) David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Those damned parentheses
As another suggestion, you may try HLint [1]. It usually tells you if you put unnecessary parenthesis. Among other nice suggestions. [1] http://community.haskell.org/~ndm/hlint/ (or cabal-install hlint) Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Those damned parentheses
On 5/7/11 4:29 PM, Eitan Goldshtrom wrote: I know about the $ symbol, that's why it's in there in the respective places. I see that I can use it to fix my problem, but I was trying to figure out function composition really. I guess that's just not the place for it. I'll check out Control.Applicative. Also thanks for the clarification on function application. I know functions are by default infixl 9, but I hadn't really thought that through all the way. The secret to parentheses in Haskell is that juxtaposition binds most strongly. That's it. Other languages (e.g., Perl, ML) have much more complicated rules which often lead new Haskellers astray; ignore them! Thus, f p = putStrLn $ show (Main.id p) ++ - message received Because you are applying Main.id to p, and you are applying show to (Main.id p). Of course, this is identical to: f p = putStrLn (show (Main.id p) ++ - message received) Since ($) is defined by: f $ x = f x with very low precedence. Alternatively, these are also identical to: f p = putStrLn $ (show . Main.id) p ++ - message received f p = putStrLn $ ((show . Main.id) p) ++ - message received f p = putStrLn $ (show . Main.id $ p) ++ - message received f p = putStrLn ((show . Main.id $ p) ++ - message received) etc. Note that the definition of (.) is: f . g = \x - f (g x) or, if you prefer, (f . g) x = f (g x) -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
On 5/7/11 5:15 PM, dm-list-haskell-c...@scs.stanford.edu wrote: In general, I try to place as few requirements in the contexts of functions as possible. One counterargument to this philosophy is that there are many cases where fmap can be defined more efficiently than the liftM derived from return and (=). Similarly, the applicative operators (*) and (*) often admit more efficient implementations than the default. So, when dealing with monads that have those more efficient definitions, you're restricting performance unnecessarily by forcing them to use the generic monadic definitions. There's nothing wrong with having multiple constraints in the context. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type-class conditional behavior
Dear all, I'd like to write a function maybeShow :: a - Maybe String, which runs show if its argument is of class Show. The context and motivation for this are as follows. I have a GADT type which encapsulates abstract-value computation (or constants or error codes), a snippet of which is below. data AV t where AVLeft :: AV a - AV (Either a b) This is used to implement an arrow transformer, and due to Arrows mapping all Haskell functions, I cannot put some kind of qualification on the constructor, like AVLeft :: Show a = Of course any replies are welcome, but I do need something implemented and stable. If there are GHC-compatible hacks, even an unsafeShow :: a - String, that'd be great. I'd also prefer not to branch on all types which could possibly be maybeShow's argument. (Concretely, if I have newtype AVFunctor a b c = AVF (a (AV b) (AV c)), then the Arrow class declaration forces all types, c.f. variable b, to be potential variables of type AV), class (Category a) = Arrow a where arr :: (b - c) - a b c Thanks very much, Nicholas — https://ntung.com — CS major @ UC Berkeley p.s. I posted this question on StackOverflow if you care to get brownie points there, http://goo.gl/PrmYW p.s. 2 -- if there is a general dump var function in ghci, which does more than :info, I'd love to know :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe