[Haskell-cafe] Haskell Weekly News: Issue 191
Welcome to issue 191 of the HWN, a newsletter covering developments in the Haskell community. This release covers the week of July 10 to 16, 2011. [1] http://haskell.org/ You can find the HTML (and mobile) version of the issue at: http://contemplatecode.blogspot.com/2011/07/haskell-weekly-news-issue-191.html Announcements Brent Yorgey put out a call for articles for the next Monad.Reader, which will be focused on parallelism and concurrency. [2] http://goo.gl/Qh6na Quotes of the Week * PenguinOfDoom: Being enlightened gentlemen, we split all programming languages into two groups, sucks and doesn't-suck and put all of them into the first group. * cmccann: beta reducing the chainsaws can be tricky * kmc: edwardk measures API lifetime in hours * _Ray_: the difference in mathematical/CS knowledge of the average haskeller, and the average PHPer, is likely similar to that of the average PHPer and a banana * quicksilver: [on LYAH] by the time I read it I knew everything it was trying to teach, so I just thought "Yay! Cute caterpillar". * edwardk: shapr is the only person i know of who just decides to drive across the country with a car full of machetes * copumpkin is now known as contrapumpkin. contrapumpkin is now known as yoda. yoda is now known as coyoda. + Eduard_Munteanu: Yonoda + coedwardk: i keep reading coyoda as coyoneda + monochrom: I read it as toyota + Eduard_Munteanu: Mmm, the monad is strong in this one... + monochrom: rumours actually say that it should be toyoda but the japaneses want it easier on americans, so toyota Top Reddit Stories * The Haskell School of Music - new book being written by Paul Hudak Domain: plucky.cs.yale.edu, Score: 66, Comments: 9 On Reddit: [3] http://goo.gl/9Jjrd Original: [4] http://goo.gl/r54xG * Confusion between (.) and ($) operators Domain: self.haskell, Score: 41, Comments: 27 On Reddit: [5] http://goo.gl/eFqRj Original: [6] http://goo.gl/eFqRj * Fitter, happier, more productive UTF-8 decoding Domain: serpentine.com, Score: 35, Comments: 6 On Reddit: [7] http://goo.gl/o2REx Original: [8] http://goo.gl/dKB04 * Static Single Assignment for Functional Programmers Domain: wingolog.org, Score: 30, Comments: On Reddit: [9] http://goo.gl/13sSP Original: [10] http://goo.gl/90MEH * [GSoC] Text/UTF-8: Initial results Domain: jaspervdj.be, Score: 29, Comments: 14 On Reddit: [11] http://goo.gl/nJ4pJ Original: [12] http://goo.gl/uPkBl * Data Driven Programming in haskell - live screencast. What are your tips/suggestions? Domain: entirelysubjective.com, Score: 29, Comments: 17 On Reddit: [13] http://goo.gl/kIiX8 Original: [14] http://goo.gl/28k6p * Ur/Web is hiring: web metaprogramming with class Domain: haskell.org, Score: 28, Comments: 11 On Reddit: [15] http://goo.gl/nWf5S Original: [16] http://goo.gl/l9HhI * Monads in C++. Bartosz Milewski's Programming Cafe Domain: bartoszmilewski.wordpress.com, Score: 23, Comments: 0 On Reddit: [17] http://goo.gl/IJnVa Original: [18] http://goo.gl/Bq4Lq * The Typeable class is changing Domain: haskell.org, Score: 22, Comments: 2 On Reddit: [19] http://goo.gl/x1InO Original: [20] http://goo.gl/E2jVK * Reverse Engineering of Compiled Haskell Domain: self.haskell, Score: 18, Comments: 22 On Reddit: [21] http://goo.gl/GCrfN Original: [22] http://goo.gl/GCrfN Top StackOverflow Questions * Haskell - How to avoid typing the same context over and over again? votes: 18, answers: 3 Read on SO: [23] http://goo.gl/0h1qF * Haskell iteratee: simple worked example of stripping trailing whitespace votes: 14, answers: 1 Read on SO: [24] http://goo.gl/bYujx * Parametrised data type in Scala votes: 12, answers: 2 Read on SO: [25] http://goo.gl/4NyZw * How to organize Haskell modules with instances: stick to data type vs type class? votes: 10, answers: 1 Read on SO: [26] http://goo.gl/Tivoh * On improving Haskell's performance compared to C in fibonacci micro-benchmark votes: 10, answers: 3 Read on SO: [27] http://goo.gl/q5O8Q * Constructing a tuple (or list) from already-existing objects - what is the cost? votes: 9, answers: 2 Read on SO: [28] http://goo.gl/UuKft * Writing A Function Polymorphic In A Type Family votes: 9, answers: 1 Read on SO: [29] http://goo.gl/vPpoH * Haskell Lazy ByteString + read/write progress function votes: 9, answers: 1 Read on SO: [30] http://goo.gl/LfNEN About the Haskell Weekly News To help create new editions of this newsletter, please send stories to dstc...@gmail.com. Until next time, Daniel Santa Cruz References 1. http://haskell.org/ 2. http://permalink.gmane.org/gm
[Haskell-cafe] Network.CGI strangeness
Hi Everybody, I'm having some strange issues with Network.CGI's pathInfo action, or else some other strangeness with pattern matching. My "mainCGI" CGI action is: mainCGI :: CGI CGIResult mainCGI = pathInfo >>= outputSlotTHtml . packagesPage outputSlotTHtml is irrelevant to my problem. packagesPage generates a SlotT IO Html -- Slot semantics are essentially irrelevant to my problem. But packagesPage calls a function called pathCrossRef which is having some problems: packagesPage :: WebPath -> SlotT IO Html packagesPage wp = do infos <- getPackageInfos . pathCrossRef $ wp ... pathCrossRef :: String -> String pathCrossRef "/working/" = "/development/code/haskell/working/" pathCrossRef _ = "/development/code/haskell/packages/" The intention is that when the cgi program is called with "/working/" as an argument, the pathCrossRef should point at "/development/.../working/", and when called with "/packages/" (or anything else) as an argument, pathCrossRef should point to "/development/.../packages/". But it is not working! When I visit http://localhost/working/, I end up using the "packages" cross ref. I have even printed the cgi argument to the Apache log, and the argument is "/working/". If I get rid of the wildcard pattern, I get a "missing pattern" error when I visit http://localhost/working/. Can anybody help? Thanks, Alex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] ANN: boomerang and web-routes-boomerang
Am 21.07.2011 21:19, schrieb Jeremy Shaw: Nope. It is not related. It is also not related to the GSM library: http://www.programmersheaven.com/download/29760/download.aspx or the decompiler: http://boomerang.sourceforge.net/index.php Perhaps picking an original name would have been a wise choice. But it was the only I idea I had :) I am only inclined to change it if there is a strong chance of people wanting to use the boomerang name on hackage to refer to something related to the harmony boomerang project.. Well, I don't know. But as a matter of fact, the Boomerang language is much closer to your library in spirit (and possibly techniques) than any of the other projects you mention. First hit at Google for "Boomerang functional programming" -> http://www.seas.upenn.edu/~harmony/ Also, it does have parsers and pretty printers as one application instance. So there is potential for confusion. Best, Janis. -- Jun.-Prof. Dr. Janis Voigtländer http://www.iai.uni-bonn.de/~jv/ mailto:j...@iai.uni-bonn.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] ANN: boomerang and web-routes-boomerang
Nope. It is not related. It is also not related to the GSM library: http://www.programmersheaven.com/download/29760/download.aspx or the decompiler: http://boomerang.sourceforge.net/index.php Perhaps picking an original name would have been a wise choice. But it was the only I idea I had :) I am only inclined to change it if there is a strong chance of people wanting to use the boomerang name on hackage to refer to something related to the harmony boomerang project.. - jeremy On Thu, Jul 21, 2011 at 1:55 PM, Janis Voigtländer wrote: > Am 21.07.2011 20:45, schrieb Jeremy Shaw: >> >> Hello, >> >> I am pleased to announce the release of two new libraries: boomerang >> and web-routes-boomerang. > > Does this have anything to do with: > > "Boomerang: A bidirectional programming language for ad-hoc data" > http://www.seas.upenn.edu/~harmony/ > > ? > > If not, is it wise to name it thus? > > Wondering, > Janis. > > -- > Jun.-Prof. Dr. Janis Voigtländer > http://www.iai.uni-bonn.de/~jv/ > mailto:j...@iai.uni-bonn.de > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using SAX
I'm new to Haskell and am trying to use the SAX module to parse an XML file. I'm using the following code: module FPHParser where import Data.Text as Text import Data.Maybe import Text.XML.LibXML.SAX as SAX import System.IO f :: IO (Parser IO) f = do let g = do putStrLn ("g called.") return True let h msg = do putStrLn (Text.unpack msg) return False p <- SAX.newParserIO (Just (Text.pack "test.xml")) SAX.setCallback p SAX.reportError h SAX.setCallback p SAX.parsedBeginDocument g SAX.parseComplete p return p and am getting the following error when I parse a file with the following contents: [This is the error] "Extra content at the end of the document" This error seems to be coming from the LibSAX library, which is a C library. But I think that my error is in my code, as the file is valid XML. Any help would be greatly appreciated! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] ANN: boomerang and web-routes-boomerang
Am 21.07.2011 20:45, schrieb Jeremy Shaw: Hello, I am pleased to announce the release of two new libraries: boomerang and web-routes-boomerang. Does this have anything to do with: "Boomerang: A bidirectional programming language for ad-hoc data" http://www.seas.upenn.edu/~harmony/ ? If not, is it wise to name it thus? Wondering, Janis. -- Jun.-Prof. Dr. Janis Voigtländer http://www.iai.uni-bonn.de/~jv/ mailto:j...@iai.uni-bonn.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: boomerang and web-routes-boomerang
Hello, I am pleased to announce the release of two new libraries: boomerang and web-routes-boomerang. boomerang is a library for general purpose, invertible parsing and pretty printing. It provides combinators which allow you to specify a grammar once and automatically extract a parser and pretty-printer from it. This library was refactored, with permission, from the Zwaluw library created by Sjoerd Visscher and Martijn van Steenbergen. hackage: http://hackage.haskell.org/package/boomerang quick intro: http://hackage.haskell.org/packages/archive/boomerang/1.0.0/doc/html/Text-Boomerang.html web-route-boomerang provides glue code for using boomerang with web-routes. web-routes is a framework-independent, type-safe, url routing library. hackage: http://hackage.haskell.org/package/web-routes-boomerang tutorial: http://happstack.com/docs/crashcourse/WebRoutes.html#web-routes-boomerang - jeremy p.s. boomerang is similar in purpose to the inveritble-syntax library: http://hackage.haskell.org/package/invertible-syntax The libraries take different approaches and are both worth considering. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Make Show instance
Hello, Willem Van Lint, Thank you for help, it works. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Make Show instance
Hi, I think your main problem here is that you use Int in the pattern matching. The point is that you are matching your value of type Tree k v to a pattern such as: - EmptyTree - (Node (a, b) left right) Patterns don't contain type information such as Int, but things like value constructors and variables. Note the difference between type constructors and value constructors ( http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html ). So you probably should use something like this: data Tree k v = EmptyTree | Node (k, v) (Tree k v) (Tree k v) instance (Show k, Show v) => Show (Tree k v) where show EmptyTree = "Empty" show (Node (a, b) left right) = show left ++ "(" ++ show a ++ "," ++ show b ++ ")" ++ show right I probably use (++) too much here though. '(Show k, Show v) =>' tells us that the types k and v are of that typeclass so that we can use show on values of this type. I'm a beginner too though so I hope I was clear. 2011/7/21 Александр > Hello, thank you for reply. I know that i can derive this. But i want to > know how can i make it by hand. > > Thank you. > ___ > 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] Make Show instance
The documentation for the Show typeclass has this very example: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t:Show The summary? you need to define either showPrec or show, the latter of which is simpler, it is just a -> String. So: instance Show (Tree Int Int) where show (Tree (Node (k,v)) left right) = ... On Jul 21, 2011, at 10:55 AM, Александр wrote: > Hello, thank you for reply. I know that i can derive this. But i want to > know how can i make it by hand. > > Thank you. > ___ > 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] Make Show instance
Hello, thank you for reply. I know that i can derive this. But i want to know how can i make it by hand. Thank you. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Make Show instance
Hi. On 07/21/2011 04:45 PM, Александр wrote: Hello, I have binary tree, with every leaf tuple - (k,v): data Tree k v = EmptyTree | Node (k, v) (Tree k v) (Tree k v) How can i make Show Instance for (Tree Int Int) ? The easiest way is automatic derivation: data Tree k v = EmptyTree | Node (k, v) (Tree k v) (Tree k v) deriving (Eq, Ord, Show, Read) -- you normally want at least these four. Then the compiler automatically declares the instances for you, given that 'k' and 'v' have them. For k = v = Int, this is the case. I try: instance Show (Tree k v) where show EmptyTree = show "Empty" show (Node (Int, Int) left right) = .. I'm afraid to say that, but 'Int' doesn't make sense at this place. You would want > show (Node (x, y) left right) = ... instead. (That is, use any variables. Variables have to be lowercase.) -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Make Show instance
Hello, I have binary tree, with every leaf tuple - (k,v): data Tree k v = EmptyTree | Node (k, v) (Tree k v) (Tree k v) How can i make Show Instance for (Tree Int Int) ? I try: instance Show (Tree k v) where show EmptyTree = show "Empty" show (Node (Int, Int) left right) = .. But get error: Not in scope: data constructor `Int' I have a function: fillTree :: Int -> Tree Int Int -> Tree Int Int fillTree 100 tree = tree fillTree x tree = let a = treeInsert (x, x) EmptyTree in fillTree (x + 1) a If i execute it: No instance for (Show (Tree Int Int)) arising from a use of `print' How can i make Show instance for my Tree? Thank you. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Helsinki Haskellers?
Hi, Cafe, My wife, a biologist, will attend a conference outside Helsinki in mid-September. I've decided to accompany her on the trip to Finland. Are there any Haskellers in the area who might be interested in an informal meetup? I'd also welcome any suggestions on what to see, do, eat, etc. We'll have 3-4 days after her conference. We especially enjoy nature (hiking, biking, boating), music (folk/ethnic, jazz, classical), and dance (performance and participatory). And I love Haskell, of course. As my inquiry is only weakly Haskell-related, I suggest that replies be sent to me rather than the list. Thanks. Dean (from North Carolina) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
On Thu, Jul 21, 2011 at 8:31 AM, Ivan Lazar Miljenovic wrote: > Well, for fmap vs liftM, you have that liftM is automatically defined > for you rather than needing to make the Functor instance, so if you're > quickly defining a Monad for internal use then you can just use liftM, > etc. without needing to also make Functor and Applicative instances > (note that AFAIK, return and pure are the same thing, in that return > isn't automatically defined like liftM is). Note that even if we had "class Applicative m => Monad m where ...", we could say data X a = ... instance Functor X where fmap = liftM instance Applicative X where pure = return (<*>) = ap instance Monad X where return = ... x >>= f = ... So you just need five more lines of boilerplate to define both Functor and Applicative. Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pointer equality
On 07/21/2011 02:15 PM, Alexey Khudyakov wrote: Any examples for hangups of 'smartEq' are greatly appreciated, I couldn't produce any so far. Following sequences will hang smartEq. They are both infinite and aperiodic. smartEq (fromList primes) (fromList primes) smartEq (fromList pidigits) (fromList pidigits) Err, yeah, of course. I would expect expressions of type ListExp to be finite as they represent written text. fromList therefore expects to receive only finite lists. Defining 'primes' using my method seems to be a bit of a challenge due to its recursive definition. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pointer equality
> Any examples for hangups of 'smartEq' are greatly appreciated, I couldn't > produce any so far. > Following sequences will hang smartEq. They are both infinite and aperiodic. smartEq (fromList primes) (fromList primes) smartEq (fromList pidigits) (fromList pidigits) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Please help me spot where space leak occur.
On Thu, Jul 21, 2011 at 1:22 AM, Olexander Kozlov wrote: > Greetings Haskell community, > I stuck with a space leak problem in simple task. I have a function > described with a list of pairs: > type Fn a b = [(a, b)] > mapping values from a to b. And I have a composition operation which accepts > two functions and returns > theirs composition: > compose :: Eq b => Fn a b -> Fn b c -> Fn a c > Finding composition of 1,000,000 functions takes about 240M with the > following implementation: > type Fn a b = [(a, b)] > lkup :: Eq a => a -> Fn a b -> b > lkup x ((a, b) : abs) = if x /= a then lkup x abs else b > compose :: Eq b => Fn a b -> Fn b c -> Fn a c > compose ((a, b) : abs) bcs = (a, lkup b bcs) : compose abs bcs > compose [] _ = [] > fldl :: (a -> b -> a) -> a -> [b] -> a > fldl f z (x:xs) = fldl f (f z x) xs > fldl _ z [] = z > fna = [(1, 2), (2, 3), (3, 1)] > fni = [(1, 1), (2, 2), (3, 3)] > test = fldl compose fni (replicate 100 fna) > main = print test > I build with: > ghc --make -prof -auto-all -caf-all -fforce-recomp -rtsopts Test.hs > Profile results: > Test.exe +RTS -K50M -p -RTS > total time = 0.34 secs (17 ticks @ 20 ms) > total alloc = 240,003,820 bytes (excludes profiling overheads) > COST CENTRE MODULE %time %alloc > compose Main 58.8 80.0 > lkup Main 35.3 0.0 > test Main 5.9 11.7 > fldl Main 0.0 8.3 > After reading 'High-Performance Haskell' by Johan Tibell I tried to made my > compose function strict: > compose :: Eq b => Fn a b -> Fn b c -> Fn a c > compose ((a, b) : abs) bcs = let c = lkup b bcs in c `seq` (a, c) : compose > abs bcs > compose [] _ = [] > and memory consuption reduced down to 180M. Good achievement but still too > much! > Profile results: > Test.exe +RTS -K50M -p -RTS > total time = 0.24 secs (12 ticks @ 20 ms) > total alloc = 180,003,820 bytes (excludes profiling overheads) > COST CENTRE MODULE %time %alloc > compose Main 83.3 73.3 > lkup Main 8.3 0.0 > fldl Main 8.3 11.1 > test Main 0.0 15.6 > I tried to make fldl strict as well: > fldl :: (a -> b -> a) -> a -> [b] -> a > fldl f z (x:xs) = let z' = f z x in z' `seq` fldl f z' xs > fldl _ z [] = z > and end up with 160M of total allocations. > Profile results: > Test.exe +RTS -K32M -p -RTS > total time = 0.30 secs (15 ticks @ 20 ms) > total alloc = 160,003,820 bytes (excludes profiling overheads) > COST CENTRE MODULE %time %alloc > compose Main 46.7 82.5 > lkup Main 40.0 0.0 > test Main 6.7 17.5 > fldl Main 6.7 0.0 > Please help me spot where space leak occur, I see no other places for space > leaks. I'll appreciate any help. The space leak is because your fldl is not as strict as is needed. This version of the program needs about 1 meg on my computer: {-# LANGUAGE BangPatterns #-} type Fn a b = [(a, b)] lkup :: Eq a => a -> Fn a b -> b lkup x ((a, b) : abs) = if x /= a then lkup x abs else b compose :: Eq b => Fn a b -> Fn b c -> Fn a c compose ((a, b) : abs) bcs = (a, lkup b bcs) : compose abs bcs compose [] _ = [] -- fldl :: (a -> b -> a) -> a -> [b] -> a fldl f z (x:xs) = let z'@[(!z1,!z2),(!z3,!z4),(!z5,!z6)] = f z x in z' `seq` fldl f z' xs fldl _ z [] = z fna = [(1, 2), (2, 3), (3, 1)] fni = [(1, 1), (2, 2), (3, 3)] test = fldl compose fni (replicate 100 fna) main = print test $ Test +RTS -K50M -p -s -RTS [(1,2),(2,3),(3,1)] 351,125,156 bytes allocated in the heap 108,576 bytes copied during GC 26,888 bytes maximum residency (1 sample(s)) 18,168 bytes maximum slop 1 MB total memory in use (0 MB lost due to fragmentation) Generation 0: 669 collections, 0 parallel, 0.00s, 0.00s elapsed Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed INIT time0.00s ( 0.01s elapsed) MUT time0.50s ( 0.50s elapsed) GCtime0.00s ( 0.00s elapsed) RPtime0.00s ( 0.00s elapsed) PROF time0.00s ( 0.00s elapsed) EXIT time0.00s ( 0.00s elapsed) Total time0.50s ( 0.51s elapsed) %GC time 0.0% (0.5% elapsed) Alloc rate703,371,486 bytes per MUT second Productivity 100.0% of total user, 98.4% of total elapsed When checking for a space leak, I find the output of +RTS -s -RTS more helpful than the allocation stats in the .prof: $ cat Test.prof Thu Jul 21 05:12 2011 Time
Re: [Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
On 21 July 2011 11:10, Arlen Cuss wrote: > Hi cafe! > > I feel a bit like I'm speaking out of turn for bringing this up -- and > I'm sure it must have been brought up many times before -- but I hope > there can be something fruitful had from a discussion. > > In my travels I've read several people with much better grasp of Haskell > than I have mention -- with a sad sigh of resignation -- that functions > like liftM and return abound because some Monads don't state their > fulfillment of Functor (or Applicative, but that's even more recent), > and thus we can't use fmap/<$> or pure. Well, for fmap vs liftM, you have that liftM is automatically defined for you rather than needing to make the Functor instance, so if you're quickly defining a Monad for internal use then you can just use liftM, etc. without needing to also make Functor and Applicative instances (note that AFAIK, return and pure are the same thing, in that return isn't automatically defined like liftM is). That said, stylistically speaking when I'm writing monadic code, I tend to prefer to use liftM rather than fmap as a personal preference. Note that if you're writing polymorphic Monad functions (i.e. you have "Monad m => ..." in your type signature rather than a specific Monad) then you have to use liftM and the like because we currently don't have that Monad implies Functor. > I understand a motivation might be that code would break if the former > lot were removed, but surely they could shifted to the latter (and the > former simply be defined as the latter). It might be a very large > effort, I suppose, to comb through the standard libraries and make > everything compile again, but is there something else I'm surely missing? It would remove backwards-compatability if/when the typeclass hierarchy is fixed, and thus a lot of code would break; as such I believe that it _is_ on the table for a future version of Haskell' that will not be 100% backwards compatible with Haskell98 and Haskell2010. The big effort here would be with user code and packages, rather than standard libraries (as the former presumably has more LOC than the latter). -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
Hi cafe! I feel a bit like I'm speaking out of turn for bringing this up -- and I'm sure it must have been brought up many times before -- but I hope there can be something fruitful had from a discussion. In my travels I've read several people with much better grasp of Haskell than I have mention -- with a sad sigh of resignation -- that functions like liftM and return abound because some Monads don't state their fulfillment of Functor (or Applicative, but that's even more recent), and thus we can't use fmap/<$> or pure. I understand a motivation might be that code would break if the former lot were removed, but surely they could shifted to the latter (and the former simply be defined as the latter). It might be a very large effort, I suppose, to comb through the standard libraries and make everything compile again, but is there something else I'm surely missing? Cheers, A ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pointer equality
On 07/21/2011 10:30 AM, Pedro Vasconcelos wrote: On Wed, 20 Jul 2011 12:48:48 -0300 Thiago Negri wrote: Is it possible to implement (==) that first check these thunks before evaluating it? (Considering both arguments has pure types). E.g., Equivalent thunks, evaluates to True, does not need to evaluate its arguments: [1..] == [1..] Thunks are just expressions and equality of expressions is undecidable in any Turing-complete language (like any general-purpose programming language). Note that syntactical equality is not sufficient because (==) should be referentially transparent. I think the following code pretty much models what Thiago meant for a small subset of haskell that constructs possibly infinite lists. Thunks are made explicit as syntax trees. 'Cycle' is the syntactic symbol for a function whose definition is given by the respective case in the definition of 'evalOne'. (I chose cycle here instead of the evalFrom example above to because it doesn't need an Enum constraint). The interesting part is the definition of 'smartEq'. import Data.List (unfoldr) import Data.Function (on) -- let's say we have syntactic primitives like this data ListExp a = Nil | Cons a (ListExp a) | Cycle (ListExp a) deriving (Eq, Ord, Read, Show) -- derives syntactic equality conss :: [a] -> ListExp a -> ListExp a conss xs exp = foldr Cons exp xs fromList :: [a] -> ListExp a fromList xs = conss xs Nil -- eval the next element, return an expression defining the tail -- (if non-empty) evalOne :: ListExp a -> Maybe (a, ListExp a) evalOne Nil = Nothing evalOne (Cons h t) = Just (h, t) evalOne e@(Cycle exp) = case eval exp of [] -> Nothing (x:xs) -> Just (x, conss xs e) eval :: ListExp a -> [a] eval = unfoldr evalOne -- semantic equality evalEq :: (Eq a) => ListExp a -> ListExp a -> Bool evalEq = (==) `on` eval -- semantic equality, but check syntactic equality first. -- In every next recursion step, assume the arguments of the current recursion -- step to be equal. We can do that safely because two lists are equal iff -- they cannot be proven different. smartEq :: (Eq a) => ListExp a -> ListExp a -> Bool smartEq a b = smartEq' a b [] smartEq' :: (Eq a) => ListExp a -> ListExp a -> [(ListExp a, ListExp a)] -> Bool smartEq' a b eqPairs = if a == b || (a, b) `elem` eqPairs then True else case (evalOne a, evalOne b) of (Just _, Nothing) -> False (Nothing, Just _) -> False (Nothing, Nothing) -> True (Just (h1, t1), Just (h2, t2)) -> h1 == h2 && smartEq' t1 t2 ((a, b):eqPairs) Examples: *Main> smartEq (Cycle $ fromList [1]) (Cycle $ fromList [1,1]) True *Main> smartEq (Cons 1 $ Cycle $ fromList [1]) (Cycle $ fromList [1]) True *Main> smartEq (Cons 2 $ Cycle $ fromList [1]) (Cycle $ fromList [1]) False Any examples for hangups of 'smartEq' are greatly appreciated, I couldn't produce any so far. -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pointer equality
On Wed, 20 Jul 2011 12:48:48 -0300 Thiago Negri wrote: > Is it possible to implement (==) that first check these thunks before > evaluating it? (Considering both arguments has pure types). > > > E.g., > > Equivalent thunks, evaluates to True, does not need to evaluate its > arguments: [1..] == [1..] > > Thunks are just expressions and equality of expressions is undecidable in any Turing-complete language (like any general-purpose programming language). Note that syntactical equality is not sufficient because (==) should be referentially transparent. Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Please help me spot where space leak occur.
Greetings Haskell community, I stuck with a space leak problem in simple task. I have a function described with a list of pairs: type Fn a b = [(a, b)] mapping values from a to b. And I have a composition operation which accepts two functions and returns theirs composition: compose :: Eq b => Fn a b -> Fn b c -> Fn a c Finding composition of 1,000,000 functions takes about 240M with the following implementation: type Fn a b = [(a, b)] lkup :: Eq a => a -> Fn a b -> b lkup x ((a, b) : abs) = if x /= a then lkup x abs else b compose :: Eq b => Fn a b -> Fn b c -> Fn a c compose ((a, b) : abs) bcs = (a, lkup b bcs) : compose abs bcs compose [] _ = [] fldl :: (a -> b -> a) -> a -> [b] -> a fldl f z (x:xs) = fldl f (f z x) xs fldl _ z [] = z fna = [(1, 2), (2, 3), (3, 1)] fni = [(1, 1), (2, 2), (3, 3)] test = fldl compose fni (replicate 100 fna) main = print test I build with: ghc --make -prof -auto-all -caf-all -fforce-recomp -rtsopts Test.hs Profile results: Test.exe +RTS -K50M -p -RTS total time =0.34 secs (17 ticks @ 20 ms) total alloc = 240,003,820 bytes (excludes profiling overheads) COST CENTREMODULE %time %alloc composeMain 58.8 80.0 lkup Main 35.30.0 test Main 5.9 11.7 fldl Main 0.08.3 After reading 'High-Performance Haskell' by Johan Tibell I tried to made my compose function strict: compose :: Eq b => Fn a b -> Fn b c -> Fn a c compose ((a, b) : abs) bcs = let c = lkup b bcs in c `seq` (a, c) : compose abs bcs compose [] _ = [] and memory consuption reduced down to 180M. Good achievement but still too much! Profile results: Test.exe +RTS -K50M -p -RTS total time =0.24 secs (12 ticks @ 20 ms) total alloc = 180,003,820 bytes (excludes profiling overheads) COST CENTREMODULE %time %alloc composeMain 83.3 73.3 lkup Main 8.30.0 fldl Main 8.3 11.1 test Main 0.0 15.6 I tried to make fldl strict as well: fldl :: (a -> b -> a) -> a -> [b] -> a fldl f z (x:xs) = let z' = f z x in z' `seq` fldl f z' xs fldl _ z [] = z and end up with 160M of total allocations. Profile results: Test.exe +RTS -K32M -p -RTS total time =0.30 secs (15 ticks @ 20 ms) total alloc = 160,003,820 bytes (excludes profiling overheads) COST CENTREMODULE %time %alloc composeMain 46.7 82.5 lkup Main 40.00.0 test Main 6.7 17.5 fldl Main 6.70.0 Please help me spot where space leak occur, I see no other places for space leaks. I'll appreciate any help. (I intentionally wrote my own implementations of lookup and foldl to have direct control on them.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe