From szefirov at ot.ru Thu Feb 1 00:32:14 2007 From: szefirov at ot.ru (szefirov@ot.ru) Date: Thu Feb 1 00:27:47 2007 Subject: [Haskell-cafe] How did you stumble on Haskell? In-Reply-To: <7c737f300701281901y5fe25d20wf4f6572510fa1a17@mail.gmail.com> References: <7c737f300701281901y5fe25d20wf4f6572510fa1a17@mail.gmail.com> Message-ID: <45C17B5E.6000303@ot.ru> > What's folks most interesting ways to arrive at FP? Mine isn't most interesting. I did some interesting (I think so) research in visualisation and coded it in C. Then I tried to extend it - speed it up, add more features, etc, - and found C unsatisfactory. It is error prone and C programs cannot be modified easily. Then I tried some macro languages, M4 and like, again without satisfaction - the same modification failures. No one can keep things tied up for me. Then I search and roam, I left my visualisation research behind programming languages field and found Haskell. It got me by syntax then by type system. I still hope I'll return to visualisation research. From dons at cse.unsw.edu.au Thu Feb 1 01:04:00 2007 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Feb 1 00:58:58 2007 Subject: [Haskell-cafe] Let's welcome the Ruby hackers! Message-ID: <20070201060400.GA7164@cse.unsw.EDU.AU> As seen here, reports from 'Rails Edge': http://notes-on-haskell.blogspot.com/2007/01/haskell-open-secret.html > It seems like everyone is turning onto Haskell these days. > At Rails Edge last week, I saw a few telltale signs that some of the > speakers (including a few members of the Rails core team) were playing with > Haskell. In one case, a speaker was flipping through TextMate projects, and > briefly displayed one project named "Haskell". In another case, the > presenter's browser had a link to All About Monads centered in the middle > of the bookmarks bar. > Of course, I had to take the opportunity to see why these speakers were > interested in Haskell. One speaker was looking into Parsec for some > insights into language design (for DSLs, probably), while another was > revisiting the language after he tried to learn it a few years ago. > It turns out that a few members of the Rails team have informally chosen > Haskell as their language of the year this year. Nothing formal, just a > bunch of folks who hang out on irc periodically trading bits and pieces of > Haskell. > Somehow, I think this bodes well for both Rails and Haskell. More from the same guy: http://notes-on-haskell.blogspot.com/2007/01/ruby-vs-haskell-choose-what-works.html (On not writing Rails support code in C, instead in Haskell). So a big hello to any Ruby/Rails hackers lurking out there! Free lambdas for all if you drop by #haskell... Cheers, Don From bd.haskell at uguu.us Thu Feb 1 02:02:55 2007 From: bd.haskell at uguu.us (Bryan Donlan) Date: Thu Feb 1 01:56:40 2007 Subject: [Haskell-cafe] Re: DevRandom In-Reply-To: <2608b8a80701310155t65c83d0ak5b97c6062e1c39e0@mail.gmail.com> References: <2608b8a80701300647i25dd7c77y75c2920309ab5e5d@mail.gmail.com> <2608b8a80701301010w3c583446yc9307ce0114e63bf@mail.gmail.com> <45BF9E72.6030502@uguu.us> <2608b8a80701310155t65c83d0ak5b97c6062e1c39e0@mail.gmail.com> Message-ID: <45C1909F.7050303@uguu.us> Yitzchak Gale wrote: > Bryan Donlan wrote: >> This re-opens the device every time we need it. >> How about opening once, when it's first needed? > > Good idea. > >> hDevRandom :: Handle >> {-# NOINLINE hDevRandom #-} >> hDevRandom = unsafePerformIO $ openFile "/dev/random" ReadMode >> >> hDevURandom :: Handle >> {-# NOINLINE hDevURandom #-} >> hDevURandom = unsafePerformIO $ openFile "/dev/urandom" ReadMode > > The NOINLINE guarantees that openFile is called only > once. But does it guarantee that openFile is NOT called > if we do not need it? We could check what the compilers > actually do, but I am not sure we have a guarantee here. There's commentary in GHC/Conc.lhs that this is the case: {-# NOINLINE pendingEvents #-} {-# NOINLINE pendingDelays #-} (pendingEvents,pendingDelays) = unsafePerformIO $ do startIOManagerThread reqs <- newIORef [] dels <- newIORef [] return (reqs, dels) -- the first time we schedule an IO request, the service thread -- will be created (cool, huh?) I don't know if this is a documented guarentee however. From bulat.ziganshin at gmail.com Thu Feb 1 02:47:36 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 02:43:12 2007 Subject: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation In-Reply-To: <1170290356.29376.13.camel@localhost> References: <20070126025101.GC6772@cse.unsw.EDU.AU> <20070129153804.GA13237@soi.city.ac.uk> <20070129225201.GC27625@cse.unsw.EDU.AU> <20070130093826.GA6255@soi.city.ac.uk> <1170152578.16642.264.camel@localhost> <93992509.20070131143804@gmail.com> <1170290356.29376.13.camel@localhost> Message-ID: <1756116558.20070201104736@gmail.com> Hello Duncan, Thursday, February 1, 2007, 3:39:16 AM, you wrote: >> > Can anyone see a real serialisation use case that needs a monad for the >> > serialisation side? I'd thought I had an example, but I was wrong. >> >> my program, FreeArc, has its own compression level on top of >> serializing - i.e. data serialized sent in 64k blocks to the C >> compression routine and both serialization and compression are run at >> the same time using threads i mean that in real world, programs may need to do something in IO monad - work with database, network, call C libs -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dmhouse at gmail.com Thu Feb 1 03:27:07 2007 From: dmhouse at gmail.com (David House) Date: Thu Feb 1 03:22:01 2007 Subject: [Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6 In-Reply-To: References: <936F862B-8EBF-4A22-8030-8262F6B09AC1@Cs.Nott.AC.UK> Message-ID: On 31/01/07, David House wrote: > dw :: (a -> Bool) -> [a] -> [a] > dw p = reverse . fst . foldl comb ([],False) > where comb (xs,done) x | done = (x:xs, True) > | p x = (xs, False) > | otherwise = (x:xs, True) I forgot to mention: I used foldl because it was neater, but you can easily convert it to use foldr by reversing the list first and swapping the arguments to comb. -- -David House, dmhouse@gmail.com From benjamin.franksen at bessy.de Thu Feb 1 04:09:42 2007 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Feb 1 04:04:59 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <9810465297.20070131024023@gmail.com> References: <9810465297.20070131024023@gmail.com> Message-ID: <200702011009.42866.benjamin.franksen@bessy.de> [sorry, this was meant to go to the list] On Wednesday 31 January 2007 00:40, Bulat Ziganshin wrote: > Saturday, January 27, 2007, 12:00:11 AM, you wrote: > > and support operational reasoning, i.e. creating and understanding > > programs by mentally modeling their execution on a machine. This form > > of reasoning appeals to 'common sense', it is familiar to almost all > > (even completely un-educated) people and is therefore easier acessible > > to them. > > > > greatly simplifies denotional resp. equational reasoning(**), i.e. to > > understand a program as an abstract formula with certain logical > > properties; an abstract entity in its own right, independent of the > > possibility of execution on a machine. This way of thinking is less > > familiar to most people > > i think you are completely wrong! FP way is to represent everything as > function, imperative way is to represent everything as algorithm. > there is no "natural thinking way", the only think that matters is > *when* student learned the appropriate concept. What I meant is that it is more similar to the way we use to think in our daily life. Noone thinks about day-to-day practical problems in a formal way -- in most cases this would be a completely inappropriate approach. Formal thinking comes naturally to only a gifted few of us, most find it exceptionally hard to learn. However, I didn't mean to say that formal reasoning is something that cannot be learned. I would even say that it is easier to learn if done right from the start as something completely new instead of appealing to intuition, thus trying to connect it to the more 'natural' ways of thinking -- because the latter have to be 'unlearned' to a certain extent before the new way of thinking can take hold. > all the problem of learning FP paradigm for college-finished > programmers is just that their brains are filled with imperative > paradigm and they can't imagine non-imperative programming. it was > hard for me, too :) > > we should change college programs to make FP programming available for > the masses Absolutely. Cheers Ben -- "Programming = Mathematics + Murphy's Law" (Dijkstra in EWD1008) From ithika at gmail.com Thu Feb 1 04:24:03 2007 From: ithika at gmail.com (Dougal Stanton) Date: Thu Feb 1 04:12:31 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <20070201000916.GA3569@die.therning.org> References: <9810465297.20070131024023@gmail.com> <20070131084553.GF2514@die.therning.org> <45C117F0.2000108@imageworks.com> <20070201000916.GA3569@die.therning.org> Message-ID: <20070201092403.GA29860@glowfish> Quoth Magnus Therning, nevermore, > I'm not sure how a "functional" recipe would look, maybe something like > this: > > White_sauce is a combination of ... . > > Chopped_onions is onions cut into small pieces. > > White_sauce_with_chopped_onions is the combination of white_sauce and > chopped_onions. The functional approach > whitesauce = foldl stir base milks > where base = flour + (heat butter) compared with the imperative > whitesauce > base = flour + heat(butter); > while (milks > 0) > stir(base, milk); > milks--; I'm going to go out on a limb here and suggest that, like Feynman's example of how people count in their heads, both of these explanations are accurate. If I were to explain the process to someone it would be in the imperative style: literally "giving commands", which is what a recipe is. But in my mind I imagine it as the gradual process of stirring milk into a base, which is far more adequately described in the functional style. The question is --- how would an expert describe such a process? Would a professional chef give instructions in the functional or imperative style? I think that is relevant, since the approach to the problem may change depending on proficiency. We may *learn* in the imperative style but *think* in the functional. Cheers, Dougal. From gale at sefer.org Thu Feb 1 04:37:01 2007 From: gale at sefer.org (Yitzchak Gale) Date: Thu Feb 1 04:31:55 2007 Subject: [Haskell-cafe] Re: DevRandom In-Reply-To: <45C1909F.7050303@uguu.us> References: <2608b8a80701300647i25dd7c77y75c2920309ab5e5d@mail.gmail.com> <2608b8a80701301010w3c583446yc9307ce0114e63bf@mail.gmail.com> <45BF9E72.6030502@uguu.us> <2608b8a80701310155t65c83d0ak5b97c6062e1c39e0@mail.gmail.com> <45C1909F.7050303@uguu.us> Message-ID: <2608b8a80702010137n4ab1115xb83d38a0545fc490@mail.gmail.com> Bryan Donlan wrote: >>> {-# NOINLINE hDevRandom #-} >>> hDevRandom = unsafePerformIO $ openFile "/dev/random" ReadMode I wrote: >> The NOINLINE guarantees that openFile is called only >> once. But does it guarantee that openFile is NOT called >> if we do not need it? We could check what the compilers >> actually do, but I am not sure we have a guarantee here. > There's commentary in GHC/Conc.lhs that this is the case: > {-# NOINLINE pendingEvents #-} > {-# NOINLINE pendingDelays #-} > (pendingEvents,pendingDelays) = unsafePerformIO $ do > startIOManagerThread > reqs <- newIORef [] > dels <- newIORef [] > return (reqs, dels) > -- the first time we schedule an IO request, the service thread > -- will be created (cool, huh?) > I don't know if this is a documented guarentee however. Hmm. I'm not sure what that comment means. They are doing just what I did - creating only an empty IORef, with the actual resource allocated only when needed. Also, this is located inside a module that is explicitly GHC-specific. Regards, Yitz From magnus at therning.org Thu Feb 1 04:43:56 2007 From: magnus at therning.org (Magnus Therning) Date: Thu Feb 1 04:38:58 2007 Subject: [Haskell-cafe] Data.ByteString.Lazy.Char8 and finding substrings Message-ID: <20070201094356.GB2614@die.therning.org> I'm curious, why doesn't Data.ByteString.Lazy.Char8 have the functions for searching for substrings that Data.ByteString.Char8 has (isPrefixOf, isSuffixOf, isSubstringOf, findSubstring and findSubstrings)? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070201/7d8acf83/attachment.bin From Alistair_Bayley at invescoperpetual.co.uk Thu Feb 1 05:05:29 2007 From: Alistair_Bayley at invescoperpetual.co.uk (Bayley, Alistair) Date: Thu Feb 1 05:00:29 2007 Subject: [Haskell-cafe] Takusen - error handling and DBM monad In-Reply-To: <79990c6b0701310902o1c927554k8fe2a0995453e5e2@mail.gmail.com> Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA9891B16@GBLONXMB02.corp.amvescap.net> > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Paul Moore > > catcher :: DBException -> DBM mark Session () > catcher x = do > liftIO $ putStrLn $ show x > > main = do > withSession (connect "..." "..." "...") ( do > catchDB (do ... > ) > catcher > ) > > But this doesn't catch errors in the connect call. > > Wrapping the withSession in catchDB doesn't work, as withSession is in > the IO monad [1], not the DBM one. But using catch with catcher > doesn't work, as that expects an error handler in the IO monad, but > catcher is in the DBM monad. There's an example in the README file, in which we see: main = flip catchDB reportRethrow $ withSession (connect "sqlite_db") (do ... which basically wraps withSession with catchDB. This does catch errors in the connect call. The difference between your example and this is in the handler; your handler has type: > catcher :: DBException -> DBM mark Session () whereas the README example handler is from the library, and has type: > reportRethrow :: CaughtMonadIO m => DBException -> m () CaughtMonadIO isn't something we've bothered to explain in the docs, but this is simply a way of catching exceptions in a monad that is in the MonadIO class, which is something the standard libraries don't support. In Control.Exception, catch and friends are stuck in the IO monad. This problem has been discussed before on this list: http://www.haskell.org/pipermail/haskell/2006-February/017547.html http://www.haskell.org/pipermail/haskell/2006-April/017893.html And may well be fixed for Haskell-Prime? http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/ticket/110 So you just need to float your handler out one level (so it wraps withSession), and make it usable in the regular IO monad :-) That should be as simple as changing the type sig: > catcher :: CaughtMonadIO m => DBException -> m () > catcher x = liftIO $ putStrLn $ show x There are a couple of simple handlers in Database.Enumerator already, which I'd recommend you start with: > basicDBExceptionReporter :: CaughtMonadIO m => DBException -> m () > basicDBExceptionReporter e = liftIO (putStrLn (formatDBException e)) > reportRethrow :: CaughtMonadIO m => DBException -> m () > reportRethrow e = basicDBExceptionReporter e >> IE.throwDB e If you need something fancier then I suggest copying the code in Database.Enumerator and modifying to suit your needs. > I'm getting very confused about the relationship between the DBM stuff > and the IO monad. I'm sure there are good reasons for the DBM monad, > but at the moment I'm missing them, and all I'm doing is trying random > things, to little avail. The idea is to prevent resources used in database code from escaping into other, non-database, parts of your program. This lets us safely use the with- idiom to manage resources. For example, although code in the DBM monad has access to the connection object (somewhat indirectly, but it is there), it cannot return this object out of the DBM monad. When withSession closes the connection, we can be sure that further access is not possible. This is a similar technique to that used by the ST monad, I think. Oleg explains it here: http://www.haskell.org/pipermail/haskell/2006-January/017410.html Please feel free to mail me directly with questions, too, at this address or alistair@abayley.org (although my access to that maibox during working hours is sporadic and infrequent). Al Falloon wrote: > what does withSession return if there is a DBException? Well, whatever the handler returns, same as with any other exception handler. Note that this must have the same type as whatever withSession returns, and this constraint is enforced by the type of catch/catchDB: > catchDB :: CaughtMonadIO m => m a -> (DBException -> m a) -> m a ... which is modelled on Control.Exception.catch (for regular IO monad exceptions): > catch :: IO a -> (Exception -> IO a) -> IO a Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** From tomasz.zielonka at gmail.com Thu Feb 1 05:15:39 2007 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Thu Feb 1 05:10:35 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages In-Reply-To: <7810250795.20070131194615@gmail.com> References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk> <44684289.20070131024627@gmail.com> <20070131090116.GA4825@lambda> <7810250795.20070131194615@gmail.com> Message-ID: <20070201101539.GA5341@lambda> On Wed, Jan 31, 2007 at 07:46:15PM +0300, Bulat Ziganshin wrote: > Wednesday, January 31, 2007, 12:01:16 PM, you wrote: > > >> there are also many other similar issues, such as lack of good syntax > >> for "for", "while", "break" and other well-known statements, > > > On the other hand you have an ability to define your own control > > structures. > > i have a lot, but their features are limited, both in terms of > automatic lifting and overall syntax. let's consider > > while (hGetBuf h buf bufsize == bufsize) > crc := updateCrc crc buf bufsize > break if crc==0 > print crc A direct translation could look like this: whileM c b = do { x <- c; when x (b >> whileM c b) } f h buf = flip runContT return $ do callCC $ \break -> do flip execStateT 0 $ do whileM (liftIO (liftM (== bufsize) (hGetBuf h buf bufsize))) $ do do crc <- get crc' <- liftIO (updateCrc crc buf bufsize) put crc' crc <- get when (crc == 0) (lift (break crc)) liftIO (print crc) Which, admittedly, is much more lengthy. If we assume that hGetBuf, updateCrc and print can work in any MonadIO, and we define inContT x = flip runContT return x then it becomes slightly shorter: inContT $ callCC $ \break -> do flip execStateT 0 $ do whileM (liftM (== bufsize) (hGetBuf h buf bufsize)) $ do do crc <- get crc' <- updateCrc crc buf bufsize put crc' crc <- get when (crc == 0) (lift (break crc)) Let's define: modifyM f = do x <- get x' <- f x put x' and change the order of parametrs in updateCrc. We get: inContT $ callCC $ \break -> do flip execStateT 0 $ do whileM (liftM (== bufsize) (hGetBuf h buf bufsize)) $ do modifyM (updateCrc buf bufsize) crc <- get when (crc == 0) (lift (break crc)) print crc > how this can be expressed in Haskell, without losing clarity? I think it's quite clear what it does. > > "inability" is an exaggeration - you can use the ContT monad > > transformer, which even allows you to choose how "high" you > > want to jump. But you probably already know this and just want to point > > that it is cumbersome? > > don't know and don't want to use such a hard way. I gave an example above. You can "break" with a return value, so it seem it's what you want. > there is a simpler solution, but it still requires to write more > boilerplate code than C: > > res <- doSomething > if isLeft res then return$ fromLeft res else do > let (Right x) = res > ... Not simpler, but easier... and uglier. Somehow I don't like to solve problems on the level of programming language syntax. Best regards Tomasz From gale at sefer.org Thu Feb 1 05:28:38 2007 From: gale at sefer.org (Yitzchak Gale) Date: Thu Feb 1 05:23:33 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <4683d9370701310734p5d11cb22ve0e270c18d8631dc@mail.gmail.com> References: <9810465297.20070131024023@gmail.com> <20070131084553.GF2514@die.therning.org> <20070131085120.GG17031@cse.unsw.EDU.AU> <1170239816.15209.15.camel@localhost> <4683d9370701310734p5d11cb22ve0e270c18d8631dc@mail.gmail.com> Message-ID: <2608b8a80702010228q26bbb2c7hc0cc930b4faab62e@mail.gmail.com> On 1/31/07, Kirsten Chevalier wrote: > On 1/31/07, Bill Wood wrote: > > On Wed, 2007-01-31 at 19:51 +1100, Donald Bruce Stewart wrote: > > . . . > > > foldl (\water dish -> wash water dish) soapywater dishes :: [Dishes] > > > > Nice example. First, note that you can't get close with map -- you need > > accumulation across the dishes. Second, the correctness of this plan > > depends on the rather strong frame axiom that no entity in the > > environment is changed during a step of the fold, so no broken dishes. > > Finally, that doesn't work so well when there are constraints on the > > order that the dishes are washed, for example when washing the cruddiest > > dishes first while there are more suds. > It also assumes that there's necessarily a natural decomposition on > the dishes, and if you think there is, you haven't seen my kitchen! In my kitchen, there is a natural decomposition on the dishes. Especially on the ones that have been at the bottom of the pile for the longest time. -Yitz From duncan.coutts at worc.ox.ac.uk Thu Feb 1 05:35:11 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Thu Feb 1 05:29:58 2007 Subject: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation In-Reply-To: <1756116558.20070201104736@gmail.com> References: <20070126025101.GC6772@cse.unsw.EDU.AU> <20070129153804.GA13237@soi.city.ac.uk> <20070129225201.GC27625@cse.unsw.EDU.AU> <20070130093826.GA6255@soi.city.ac.uk> <1170152578.16642.264.camel@localhost> <93992509.20070131143804@gmail.com> <1170290356.29376.13.camel@localhost> <1756116558.20070201104736@gmail.com> Message-ID: <1170326111.29376.29.camel@localhost> On Thu, 2007-02-01 at 10:47 +0300, Bulat Ziganshin wrote: > Hello Duncan, > > Thursday, February 1, 2007, 3:39:16 AM, you wrote: > > >> > Can anyone see a real serialisation use case that needs a monad for the > >> > serialisation side? I'd thought I had an example, but I was wrong. > >> > >> my program, FreeArc, has its own compression level on top of > >> serializing - i.e. data serialized sent in 64k blocks to the C > >> compression routine and both serialization and compression are run at > >> the same time using threads > > i mean that in real world, programs may need to do something in IO > monad - work with database, network, call C libs Most of this can be done in a modular and mostly pure way. In that example I gave, the compression function - while pure - was of course calling out to a C library. As an example of a real world program that uses this stuff and does networking, keeps a persistent store and calls C libs, see http://hpaste.org/ It uses HappS, ByteStrings and stores the pastes in compressed form on disk (using my pure zlib wrapper library). Duncan From neil at integility.com Thu Feb 1 05:53:58 2007 From: neil at integility.com (Neil Bartlett) Date: Thu Feb 1 05:48:52 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <20070201092403.GA29860@glowfish> References: <9810465297.20070131024023@gmail.com> <20070131084553.GF2514@die.therning.org> <45C117F0.2000108@imageworks.com> <20070201000916.GA3569@die.therning.org> <20070201092403.GA29860@glowfish> Message-ID: <44739.204.4.130.140.1170327238.squirrel@integ-45100-001.dsvr.co.uk> > The question is --- how would an expert describe such a process? Would a > professional chef give instructions in the functional or imperative > style? I think a sufficiently expert chef would not even need the functional style. Everything would be declarative. Dave Thomas (of "Pragmatic Programmers" fame) tells of finding his late grandmother's recipe cards, which she accumulated over her entire life. He was able to track their evolution from an extremely pedantic, imperative style, through to the almost Zen-like cards that read: "Spice cake: like chocolate cake. No chocolate, add spice". From dons at cse.unsw.edu.au Thu Feb 1 06:07:51 2007 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Feb 1 06:02:55 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <44739.204.4.130.140.1170327238.squirrel@integ-45100-001.dsvr.co.uk> References: <9810465297.20070131024023@gmail.com> <20070131084553.GF2514@die.therning.org> <45C117F0.2000108@imageworks.com> <20070201000916.GA3569@die.therning.org> <20070201092403.GA29860@glowfish> <44739.204.4.130.140.1170327238.squirrel@integ-45100-001.dsvr.co.uk> Message-ID: <20070201110751.GA8700@cse.unsw.EDU.AU> neil: > > The question is --- how would an expert describe such a process? Would a > > professional chef give instructions in the functional or imperative > > style? > > I think a sufficiently expert chef would not even need the functional > style. Everything would be declarative. > > Dave Thomas (of "Pragmatic Programmers" fame) tells of finding his late > grandmother's recipe cards, which she accumulated over her entire life. He > was able to track their evolution from an extremely pedantic, imperative > style, through to the almost Zen-like cards that read: > > "Spice cake: like chocolate cake. No chocolate, add spice". Surely this is the arrow or monad transformer of recipe abstractions! Entirely new functionality, and such information density, on a single line. -- Don From gale at sefer.org Thu Feb 1 06:18:42 2007 From: gale at sefer.org (Yitzchak Gale) Date: Thu Feb 1 06:13:35 2007 Subject: [Haskell-cafe] Levels of recursion In-Reply-To: References: Message-ID: <2608b8a80702010318x75836aadv8effc22a11355d9e@mail.gmail.com> Hi Andrew, You wrote: > combine :: [Int] -> [Int] -> [[Int]] > combine [] _ = [] > combine (x:xs) ys = (take x ys) : (combine xs (drop x ys)) > > ...A much more experienced haskeller told me he > preferred to write it like this: > > combine' :: [Int] -> [Int] -> [[Int]] > combine' xs ys = snd $ mapAccumL aux ys xs > where aux ys n = (b,a) > where (a,b) = splitAt n ys > > Ack! For real work, I like your version better. I might make it a little more clear what I am trying to do by writing it as: combine :: [Int] -> [a] -> [[a]] combine (x:xs) ys = let (h, t) = splitAt x ys in h : combine xs t combine _ _ = [] Raw recursions is a bit like goto in imperative programming - it is often the simplest, but it also can make programs very difficult to understand. But as you point out, you can lose more than you gain with higher-level constructs, unless they are simple, well-documented, and widely used. My favorite geeky way of writing your function would be: combine = evalState . mapM (State . splitAt) But in real life, I like yours better. Regards, Yitz From bulat.ziganshin at gmail.com Thu Feb 1 05:33:56 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 06:36:19 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages In-Reply-To: <20070201101539.GA5341@lambda> References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk> <44684289.20070131024627@gmail.com> <20070131090116.GA4825@lambda> <7810250795.20070131194615@gmail.com> <20070201101539.GA5341@lambda> Message-ID: <746489552.20070201133356@gmail.com> Hello Tomasz, Thursday, February 1, 2007, 1:15:39 PM, you wrote: >> while (hGetBuf h buf bufsize == bufsize) >> crc := updateCrc crc buf bufsize >> break if crc==0 >> print crc > inContT $ callCC $ \break -> do > flip execStateT 0 $ do > whileM (liftM (== bufsize) (hGetBuf h buf bufsize)) $ do > modifyM (updateCrc buf bufsize) > crc <- get > when (crc == 0) (lift (break crc)) > print crc >> how this can be expressed in Haskell, without losing clarity? > > I think it's quite clear what it does. first. it's longer than original. what we can learn here is that imperative languages have built-in "monadic" features support, including automatic lifting and continuations. OTOH, of course, they don't support type inference. so in one environment we need to explicitly declare types while in other environment we need to explicitly specify lifting operations second. unfortunately, current Haskell libs defined in terms of IO monad, not MonadIO. while this issue, i hope, will be addressed in future, i write programs right now :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From magnus at therning.org Thu Feb 1 06:51:26 2007 From: magnus at therning.org (Magnus Therning) Date: Thu Feb 1 06:51:08 2007 Subject: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages In-Reply-To: <20070201092403.GA29860@glowfish> References: <9810465297.20070131024023@gmail.com> <20070131084553.GF2514@die.therning.org> <45C117F0.2000108@imageworks.com> <20070201000916.GA3569@die.therning.org> <20070201092403.GA29860@glowfish> Message-ID: <20070201115126.GA27429@die.therning.org> On Thu, Feb 01, 2007 at 09:24:03 +0000, Dougal Stanton wrote: [..] >I'm going to go out on a limb here and suggest that, like Feynman's >example of how people count in their heads, both of these explanations >are accurate. If I were to explain the process to someone it would be >in the imperative style: literally "giving commands", which is what a >recipe is. But in my mind I imagine it as the gradual process of >stirring milk into a base, which is far more adequately described in >the functional style. > >The question is --- how would an expert describe such a process? Would >a professional chef give instructions in the functional or imperative >style? I think that is relevant, since the approach to the problem may >change depending on proficiency. We may *learn* in the imperative style >but *think* in the functional. There may be something in what you say. I kind of like it :-) Of course it makes me wonder if we have to _learn_ how to _learn_ in the functional style. I am convinced _some_ people are able to learn in that way, I doubt all are. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070201/c849e88b/attachment.bin From cgibbard at gmail.com Thu Feb 1 07:16:56 2007 From: cgibbard at gmail.com (Cale Gibbard) Date: Thu Feb 1 07:11:49 2007 Subject: [Haskell-cafe] Levels of recursion In-Reply-To: References: Message-ID: <89ca3d1f0702010416v36fdc59fn6739991a5c854543@mail.gmail.com> On 31/01/07, Andrew Wagner wrote: > Like I said, I'm familiar with map, foldr, etc. But this is the > first time it's dawned on me that I need to think in more general > recursive patterns like this instead of simple, raw recursion. That > map and foldr aren't JUST a nice way of doing things to a little list, > but they are recursive operators, building blocks that I need to use > as fluently as anything else. > > I suspect I'm not alone, though of course I could be wrong. But I > would bet that a significant difference between newbies and more > experienced Haskell programmers is the degree to which they can think > in this composition/HOF way. Where the beginner wants to program using > raw, simple recursion, the more experienced sees an opportunity to > apply an abstraction. > > So, a couple of questions to ponder about this: Is this unique to > Haskell, or could the same be said about any functional language? How > can we teach this better to newbies? Most of what I see in the > tutorials is "Higher order functions accept as parameters and/or > return other functions. Here's some examples: , > . Moving on, ..." But clearly, this is > something important, and I think we can do a better job of teaching > it. Suggestions? This is absolutely correct. I suppose I was lucky in that it was probably my first epiphany of functional programming, and came before I'd really learned much Haskell at all. I somehow determined that working on understanding the translation from loops in the imperative programming I knew to map, filter, zip, fold and so on was going to be important, which helped a lot. I had a good time taking things that way, and I certainly think it should be a key point near the beginning of any functional programming tutorial. Higher order functions, and higher-order list processing functions in particular, are the control structures of functional programming. They stick everything else together. They are every bit as important as loops are to the imperative programmer. They can also be more natural ways of thinking about how things fit together than the imperative approach offers. My friend, who'd had a bit of C++ and a bit of Java, (and had pretty much hated it), preferred the Haskell approach. He gave me the example that "map wash dishes" is a whole lot closer to what you're thinking when washing dishes than numbering the dishes and incrementing a counter, washing dish n at each step. This approach to functional programming is especially important in a lazy language, since it works so well. Lists are, in a sense, loops which haven't yet happened, and much of programming is done by transforming them. Due to laziness, those elements not needed won't be computed, which is a similar capability as that of being able to break out of a loop early. This inversion allows you to essentially extend the code which would be in the "loop body" after the fact (that is, without modifying the existing code), which is not something you could do in a strict imperative language unless you'd specifically provided for passing in a continuation in the loop, or were modelling lazy lists somehow. Eventually, you come to mostly forget about loops and just think in terms of the lists themselves, but it's a very useful alternate view to have handy. Of course, lists aren't the only data structure just as loops aren't the only kind of recursion. Laziness basically makes data structures into tools giving you the ability to "reify" recursion such that only those steps which end up needed later on are actually carried out. - Cale From dnavarro at gmail.com Thu Feb 1 07:19:06 2007 From: dnavarro at gmail.com (Diego Navarro) Date: Thu Feb 1 07:13:59 2007 Subject: [Haskell-cafe] Modulo-foo equivalence classes in Haskell? Message-ID: Watching the questions go by in #haskell, a still fuzzy but possibly pregnant idea popped up in my mind. Someone needed a nubBy function that returned an unique list modulo an arbitrary function foo. Well, in this case it wasn't arbitrary; he had a list of transposable matrices and wanted an unique list of matrices that couldn't be transposed into each other. I'm thinking there are many cases of fooBy functions that have to be constantly rewritten, and also a lot of ugly code by having to constantly add the modulo clauses (like in modular arithmetic). I'm inexperienced with type classes -- I've only done the simplest types and /some/ fundeps -- so I'm wondering what would be the clearest, most general way of having a Modulo-foo Eq class that could be parameterized with a function. The "transposable matrix" example shows how this could be useful for (some limited form) of data compression, but it could make some other forms of "algebraically modular" (this is not a proper term, it's me trying to get thoughts across) business rules, of which modular arithmetic is a special case. Uh, I've probably not expressed myself well enough; I hope I have a shot at trying to explain myself better if questions come up. -- -- Diego Navarro From haskell at list.mightyreason.com Thu Feb 1 07:31:22 2007 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Thu Feb 1 07:26:16 2007 Subject: [Haskell-cafe] Modulo-foo equivalence classes in Haskell? In-Reply-To: References: Message-ID: <45C1DD9A.5070800@list.mightyreason.com> Diego Navarro wrote: > Watching the questions go by in #haskell, a still fuzzy but possibly > pregnant idea popped up in my mind. Someone needed a nubBy function > that returned an unique list modulo an arbitrary function foo. Well, > in this case it wasn't arbitrary; he had a list of transposable > matrices and wanted an unique list of matrices that couldn't be > transposed into each other. I have seen situations that I needed nub/nubBy. But nubBy is O(n^2) and so I tend to avoid it if I can. If you can sort or sortBy then you can use (norep . sort) or the "*By" versions. -- | after sort or sortBy the use of nub/nubBy can be replaced by norep/norepBy norep :: (Eq a) => [a]->[a] norep [] = [] norep x@[_] = x norep (a:bs@(c:cs)) | a==c = norep (a:cs) | otherwise = a:norep bs -- | after sort or sortBy the use of nub/nubBy can be replaced by norep/norepBy norepBy :: (a -> a -> Bool) -> [a] -> [a] norepBy _ [] = [] norepBy _ x@[_] = x norepBy eqF (a:bs@(c:cs)) | a `eqF` c = norepBy eqF (a:cs) > > I'm thinking there are many cases of fooBy functions that have to be > constantly rewritten, and also a lot of ugly code by having to > constantly add the modulo clauses (like in modular arithmetic). > > I'm inexperienced with type classes -- I've only done the simplest > types and /some/ fundeps -- so I'm wondering what would be the > clearest, most general way of having a Modulo-foo Eq class that could > be parameterized with a function. You have a type X and it already has an Eq instance. But you want to (nubBy foo) a list [X]. You could use a newtype: newtype Y = Y { unY :: X } instance Eq Y where (==) = foo nub' :: [X] -> [X] nub' = map unY . sort . map Y > The "transposable matrix" example > shows how this could be useful for (some limited form) of data > compression, but it could make some other forms of "algebraically > modular" (this is not a proper term, it's me trying to get thoughts > across) business rules, of which modular arithmetic is a special case. > > Uh, I've probably not expressed myself well enough; I hope I have a > shot at trying to explain myself better if questions come up. > But I may have misunderstood what you want. Here is a solution to a related problem: http://portal.acm.org/citation.cfm?id=1017481&dl=ACM&coll=&CFID=15151515&CFTOKEN=6184618 From dnavarro at gmail.com Thu Feb 1 07:44:09 2007 From: dnavarro at gmail.com (Diego Navarro) Date: Thu Feb 1 07:39:02 2007 Subject: [Haskell-cafe] Modulo-foo equivalence classes in Haskell? In-Reply-To: <45C1DD9A.5070800@list.mightyreason.com> References: <45C1DD9A.5070800@list.mightyreason.com> Message-ID: > newtype Y = Y { unY :: X } > > instance Eq Y where (==) = foo > > nub' :: [X] -> [X] > nub' = map unY . sort . map Y > Yes, I thought of that. I'm really thinking of how I can generalize the Eq class so I dont have to go around manually "lifting" operations that are already defined (like operations on integers for modulo-n rings) -- Diego Navarro From dnavarro at gmail.com Thu Feb 1 07:45:02 2007 From: dnavarro at gmail.com (Diego Navarro) Date: Thu Feb 1 07:39:55 2007 Subject: [Haskell-cafe] Modulo-foo equivalence classes in Haskell? In-Reply-To: References: <45C1DD9A.5070800@list.mightyreason.com> Message-ID: > Yes, I thought of that. I'm really thinking of how I can generalize > the Eq class so I dont have to go around manually "lifting" operations > that are already defined (like operations on integers for modulo-n > rings) (I do realize it's a lucky chance that the ordinary (+) and (*) work so well on modulo-n rings. Anyway, that's besides the point.) From newhoggy at gmail.com Thu Feb 1 08:03:09 2007 From: newhoggy at gmail.com (John Ky) Date: Thu Feb 1 07:58:02 2007 Subject: [Haskell-cafe] Boost equivalent Message-ID: Hi, Does the Haskell community have an equivalent to C++ community's Boost project with the aim of writing libraries for the eventual inclusion into Haskell? Thanks -John -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070202/1ac1b1dc/attachment.htm From ndmitchell at gmail.com Thu Feb 1 08:09:26 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Feb 1 08:04:19 2007 Subject: [Haskell-cafe] Boost equivalent In-Reply-To: References: Message-ID: <404396ef0702010509g5ef5f7d8t21b406a27a6a2532@mail.gmail.com> Hi John, > Does the Haskell community have an equivalent to C++ community's Boost > project with the aim of writing libraries for the eventual inclusion into > Haskell? We have: 1) MissingH - a nice staging ground for things that may end up in the base library 2) Library submission process, to add things to the base libraries 3) Hackage - anyone can write a library that anyone can use. I think that covers most uses. Thanks Neil From bulat.ziganshin at gmail.com Thu Feb 1 08:23:02 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 08:18:37 2007 Subject: [Haskell-cafe] Connected! Message-ID: <1423719610.20070201162302@gmail.com> Hello haskell-cafe, i've just got ADSL connection here! it's slow (64k) and not cheap, but at least it is completely different from dial-up i've used before -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From joelr1 at gmail.com Thu Feb 1 08:25:45 2007 From: joelr1 at gmail.com (Joel Reymont) Date: Thu Feb 1 08:20:31 2007 Subject: [Haskell-cafe] Connected! In-Reply-To: <1423719610.20070201162302@gmail.com> References: <1423719610.20070201162302@gmail.com> Message-ID: <13563F10-0F5E-4B33-8BED-5E559A11453A@gmail.com> What part of Russia do you live in? On Feb 1, 2007, at 1:23 PM, Bulat Ziganshin wrote: > Hello haskell-cafe, > > i've just got ADSL connection here! it's slow (64k) and not cheap, but > at least it is completely different from dial-up i've used before -- http://wagerlabs.com/ From bulat.ziganshin at gmail.com Thu Feb 1 08:29:35 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 08:25:02 2007 Subject: [Haskell-cafe] Boost equivalent In-Reply-To: References: Message-ID: <1824905036.20070201162935@gmail.com> Hello John, Thursday, February 1, 2007, 4:03:09 PM, you wrote: > Does the Haskell community have an equivalent to C++ community's > Boost project with the aim of writing libraries for the eventual inclusion into Haskell? i guess that the only reason why C++ people need such project is because there are too many developers that want to develop such libs. that's not true for Haskell. for example, the most successful library of 2006 - ByteString - was developed by just 3 main contributors. if you want to develop somewhat useful - just do it. if you want to add more functionality to existing library - including base! - just send your patches to the maintainer. the only thing we missing, imho, is a darcs repository (or instructions for dummies like me on how to setup my own publicly accessible repository, say, on haskell.org) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From haskell at list.mightyreason.com Thu Feb 1 08:54:12 2007 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Thu Feb 1 08:49:12 2007 Subject: [Haskell-cafe] Boost equivalent In-Reply-To: <1824905036.20070201162935@gmail.com> References: <1824905036.20070201162935@gmail.com> Message-ID: <45C1F104.1000100@list.mightyreason.com> Bulat Ziganshin wrote: > Hello John, > > Thursday, February 1, 2007, 4:03:09 PM, you wrote: >> Does the Haskell community have an equivalent to C++ community's >> Boost project with the aim of writing libraries for the eventual inclusion into Haskell? The Haskell community is hosted on the wiki at haskell.org. > i guess that the only reason why C++ people need such project is > because there are too many developers that want to develop such libs. > that's not true for Haskell. for example, the most successful library > of 2006 - ByteString - was developed by just 3 main contributors. if > you want to develop somewhat useful - just do it. if you want to add > more functionality to existing library - including base! - just send > your patches to the maintainer. the only thing we missing, imho, is a > darcs repository (or instructions for dummies like me on how to setup > my own publicly accessible repository, say, on haskell.org) > When I wrote the regex-* packages to upgrade and extend and replace Text.Regex I worked alone and then submitted them in time for the GHC 6.6 / base 2.0 release. They gave me darcs space (which I am still using for the project) on darcs.haskell.org. This was useful for the GHC developers since they needed some of it there for GHC anyway. From bulat.ziganshin at gmail.com Thu Feb 1 08:57:19 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 08:52:46 2007 Subject: [Haskell-cafe] Connected! In-Reply-To: <13563F10-0F5E-4B33-8BED-5E559A11453A@gmail.com> References: <1423719610.20070201162302@gmail.com> <13563F10-0F5E-4B33-8BED-5E559A11453A@gmail.com> Message-ID: <107951316.20070201165719@gmail.com> Hello Joel, Thursday, February 1, 2007, 4:25:45 PM, you wrote: > What part of Russia do you live in? Tatarstan. we make Kamaz here :) if you are interested, such situation is very common for Russia - except for Moscow and a few other largest cities, internet costs are very high. you will stop wondering if i say that son of Tatarstan's chief - the richest man in Tatarstan. and he is not a genius - he just own the biggest independent Tatarstan Internet provider, his wealth built from those crazy rates. other businessmen that want to become providers, just don't got appropriate licenses from his father and this situation isn't unique. richest woman in Russia is a wife of Moscow mayor. she build houses in Moscow. you may guess that other builders just don't got licenses/land for their work. as a result, Moscow has highest cost of floor space in the world so Moscow has cheap internet and expensive apartments, and we - vice versa :) btw, all the underdeveloped countries has the same situation with corruption - and this is one of reasons why they are underdeveloped ;) > On Feb 1, 2007, at 1:23 PM, Bulat Ziganshin wrote: >> Hello haskell-cafe, >> >> i've just got ADSL connection here! it's slow (64k) and not cheap, but >> at least it is completely different from dial-up i've used before -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From asandroq at gmail.com Thu Feb 1 09:03:36 2007 From: asandroq at gmail.com (Alex Queiroz) Date: Thu Feb 1 08:58:29 2007 Subject: [Haskell-cafe] Connected! In-Reply-To: <107951316.20070201165719@gmail.com> References: <1423719610.20070201162302@gmail.com> <13563F10-0F5E-4B33-8BED-5E559A11453A@gmail.com> <107951316.20070201165719@gmail.com> Message-ID: <54e12800702010603s668391aao2536689959ad4020@mail.gmail.com> Hallo, On 2/1/07, Bulat Ziganshin wrote: > > so Moscow has cheap internet and expensive apartments, and we - vice > versa :) btw, all the underdeveloped countries has the same situation > with corruption - and this is one of reasons why they are underdeveloped ;) > Yeah, I share your pain. :-) -- -alex http://www.ventonegro.org/ From prozen at gmail.com Thu Feb 1 09:41:08 2007 From: prozen at gmail.com (Pavel Rozenblioum) Date: Thu Feb 1 09:36:00 2007 Subject: [Haskell-cafe] data package Message-ID: <9b3a3470702010641oebc39dame5ed02234307255c@mail.gmail.com> Hi, I am trying to compile the GLR examples from Happy 1.16, but I get the message that I am missing the "data" package. Where can I download it from? I am using GHC 6.6 /pavel From gale at sefer.org Thu Feb 1 09:47:26 2007 From: gale at sefer.org (Yitzchak Gale) Date: Thu Feb 1 09:42:21 2007 Subject: [Haskell-cafe] Importance of MonadRandom Message-ID: <2608b8a80702010647g6fcb90cdt92028dc656c97cfc@mail.gmail.com> I would like to point out the importance of Cale Gibbard's MonadRandom, beyond what is currently mentioned on its wiki page: http://www.haskell.org/haskellwiki/New_monads/MonadRandom This monad makes it possible to write functions that use randomness without having to specify in advance whether the source of randomness will be a pure pseudorandom number generator, as in System.Random, or physical randomness via the IO monad, such as your operating system's source of physical randomness, or random.org, or a hardware random generator. Before use of MonadRandom becomes widespread - and I think it ought to - I would like to suggest a change to the interface. (I mentioned this once to Cale on #haskell, but I didn't say what change I meant.) Currently, the members of the MonadRandom class mimic the members of the Random class in System.Random. I think it would be better if instead they mimicked the members of RandomGen. Like this: \begin{code} class (Monad m) => MonadRandom m where nextR :: m Int splitR :: m (m ()) rangeR :: m (Int, Int) getR :: (forall g . RandomGen g => g -> a) -> m a \end{code} The extra function getR provides access not only to the member functions of Random, but to any function that generates random variables of any type. You would use getR random, getR $ randomR (a, b), etc. instead of getRandom, getRandomR (a, b), etc. Provide a default method for getR as follows: \begin{code} getR f = do r <- nextR (lo, hi) <- rangeR return $ f $ TrivialGen r lo hi data TrivialGen = TrivialGen Int Int Int instance RandomGen TrivialGen where next (TrivialGen r _ _) = r genRange (TrivialGen _ lo hi) = (lo, hi) split _ = undefined \end{code} We would use the default method of getR for MonadRandom instances of things like DevRandom, DevURandom, RandomDotOrg, etc. For the Rand and RandT instances we provide explicit methods: \begin{code} -- For RandT: getR f = RandT $ gets f --For Rand: getR =Rand $ getR f \end{code} I think this is better for several reasons: o We anyway need getR for general random variables o We could lose precision getting other random variables via getRandom in the case where genRange /= (minBound, maxBound) o I think it is a better semantic fit Regards, Yitz From madhadron at gmail.com Thu Feb 1 10:11:32 2007 From: madhadron at gmail.com (Frederick Ross) Date: Thu Feb 1 10:06:25 2007 Subject: [Haskell-cafe] Think of a monad... In-Reply-To: <20070131190802.GC224@dewdrop.local> References: <20070131190802.GC224@dewdrop.local> Message-ID: And we have reached the monadic equivalent of Schrodinger's cat. On 1/31/07, Eric Y. Kow wrote: > Dear Haskellers, > > In the recent HWN, I noticed a new monad metaphor by Don Stewart: > Think of a monad as a spacesuite full of nuclear waste in the ocean next to a > container of apples. now, you can't put oranges in the space suite or the > nucelar waste falls in the ocean, *but* the apples are carried around > anyway, and you just take what you need > > This metaphor very clearly captures the essence of monads. Perhaps it > will be even more helpful if accompanied by a small illustration: > http://koweycode.blogspot.com/2007/01/think-of-monad.html > > I hope this turns out to be useful to somebody, > > -- > Eric Kow http://www.loria.fr/~kow > PGP Key ID: 08AC04F9 Merci de corriger mon fran?ais. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > -- Frederick Ross Graduate Fellow, (|Siggia> + |McKinney>)/sqrt(2) Lab The Rockefeller University Je ne suis pas Fred Cross! From afalloon at synopsys.com Thu Feb 1 10:21:02 2007 From: afalloon at synopsys.com (Al Falloon) Date: Thu Feb 1 10:16:25 2007 Subject: [Haskell-cafe] Re: Takusen - error handling and DBM monad In-Reply-To: <125EACD0CAE4D24ABDB4D148C4593DA9891B16@GBLONXMB02.corp.amvescap.net> References: <79990c6b0701310902o1c927554k8fe2a0995453e5e2@mail.gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA9891B16@GBLONXMB02.corp.amvescap.net> Message-ID: Bayley, Alistair wrote: > Al Falloon wrote: >> what does withSession return if there is a DBException? > > Well, whatever the handler returns, same as with any other exception > handler. Note that this must have the same type as whatever withSession > returns, and this constraint is enforced by the type of catch/catchDB: Sorry, I wasn't clear. What does it return when there is an uncaught exception? It sounds like it raises an exception in IO. Is this correct? From d.w.mead at gmail.com Thu Feb 1 10:22:50 2007 From: d.w.mead at gmail.com (Dan Mead) Date: Thu Feb 1 10:17:52 2007 Subject: [Haskell-cafe] Think of a monad... In-Reply-To: References: <20070131190802.GC224@dewdrop.local> Message-ID: <59ba068d0702010722j7a782dd2mc3a43f6c7f3858a2@mail.gmail.com> so are monads whats holding the nuclear waste or whats holding the apples? ;) On 2/1/07, Frederick Ross wrote: > > And we have reached the monadic equivalent of Schrodinger's cat. > > On 1/31/07, Eric Y. Kow wrote: > > Dear Haskellers, > > > > In the recent HWN, I noticed a new monad metaphor by Don Stewart: > > Think of a monad as a spacesuite full of nuclear waste in the ocean > next to a > > container of apples. now, you can't put oranges in the space suite or > the > > nucelar waste falls in the ocean, *but* the apples are carried around > > anyway, and you just take what you need > > > > This metaphor very clearly captures the essence of monads. Perhaps it > > will be even more helpful if accompanied by a small illustration: > > http://koweycode.blogspot.com/2007/01/think-of-monad.html > > > > I hope this turns out to be useful to somebody, > > > > -- > > Eric Kow http://www.loria.fr/~kow > > PGP Key ID: 08AC04F9 Merci de corriger mon fran?ais. > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > > > > -- > Frederick Ross > Graduate Fellow, (|Siggia> + |McKinney>)/sqrt(2) Lab > The Rockefeller University > Je ne suis pas Fred Cross! > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070201/36567ca0/attachment.htm From bulat.ziganshin at gmail.com Thu Feb 1 10:27:55 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 10:23:20 2007 Subject: [Haskell-cafe] Think of a monad... In-Reply-To: References: <20070131190802.GC224@dewdrop.local> Message-ID: <1639979317.20070201182755@gmail.com> Hello Frederick, Thursday, February 1, 2007, 6:11:32 PM, you wrote: > And we have reached the monadic equivalent of Schrodinger's cat. yes, it's exact reason why we love monads - the appropriate fruits in container are appeared depending on environment where it's used. you send probabilistic container to the friend, she should just say "i believe that it contains apples" before opening it >> In the recent HWN, I noticed a new monad metaphor by Don Stewart: >> Think of a monad as a spacesuite full of nuclear waste in the ocean next to a >> container of apples. now, you can't put oranges in the space suite or the >> nucelar waste falls in the ocean, *but* the apples are carried around >> anyway, and you just take what you need >> >> This metaphor very clearly captures the essence of monads. Perhaps it >> will be even more helpful if accompanied by a small illustration: >> http://koweycode.blogspot.com/2007/01/think-of-monad.html >> >> I hope this turns out to be useful to somebody, >> >> -- >> Eric Kow http://www.loria.fr/~kow >> PGP Key ID: 08AC04F9 Merci de corriger mon francais. >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> >> -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From claus.reinke at talk21.com Thu Feb 1 10:34:23 2007 From: claus.reinke at talk21.com (Claus Reinke) Date: Thu Feb 1 10:29:20 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability andthe Future of Languages References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk><44684289.20070131024627@gmail.com> <20070131090116.GA4825@lambda><7810250795.20070131194615@gmail.com><20070201101539.GA5341@lambda> <746489552.20070201133356@gmail.com> Message-ID: <014801c74616$7405f200$82317ad5@cr3lt> >>> while (hGetBuf h buf bufsize == bufsize) >>> crc := updateCrc crc buf bufsize >>> break if crc==0 >>> print crc > >> inContT $ callCC $ \break -> do >> flip execStateT 0 $ do >> whileM (liftM (== bufsize) (hGetBuf h buf bufsize)) $ do >> modifyM (updateCrc buf bufsize) >> crc <- get >> when (crc == 0) (lift (break crc)) >> print crc > > first. it's longer than original. is it, though? what makes it longer are features that the original doesn't have, I think. so how about a less ambitious translation, with crc in an MVar and a while-loop that can be broken from the body as well as the condition: while (hGetBuf h buf bufzise .==. (return bufsize)) $ do crc =: updateCrc crc buf bufsize breakIf ((val crc) .==. (return 0)) `orElse` do printM (val crc) od using definitions roughly like this while c b = do { r <- c; when r (b >>= flip when (while c b)) } continueIf c m = c >>= \b-> if b then od else m breakIf c m = c >>= \b-> if b then return False else m orElse = ($) od :: Monad m => m Bool od = return True x .==. y = liftM2 (==) x y printM x = x >>= print v =: x = do { rx <- x; swapMVar v rx } val = readMVar not that I like that style;-) Claus From martindemello at gmail.com Thu Feb 1 10:59:09 2007 From: martindemello at gmail.com (Martin DeMello) Date: Thu Feb 1 10:54:02 2007 Subject: [Haskell-cafe] Let's welcome the Ruby hackers! In-Reply-To: <20070201060400.GA7164@cse.unsw.EDU.AU> References: <20070201060400.GA7164@cse.unsw.EDU.AU> Message-ID: On 2/1/07, Donald Bruce Stewart wrote: > > So a big hello to any Ruby/Rails hackers lurking out there! > Free lambdas for all if you drop by #haskell... I came to Haskell from Ruby the first time around, but didn't have anything real to write in it so I lost steam somewhat. This time I'm here following the parser combinator trail, so hopefully it'll stick :) martin p.s. Is there a collection of parsec parsers for various languages maintained anywhere? I hunted around but didn't find anything. From Alistair_Bayley at invescoperpetual.co.uk Thu Feb 1 11:18:31 2007 From: Alistair_Bayley at invescoperpetual.co.uk (Bayley, Alistair) Date: Thu Feb 1 11:13:24 2007 Subject: [Haskell-cafe] Re: Takusen - error handling and DBM monad In-Reply-To: Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA9891B19@GBLONXMB02.corp.amvescap.net> > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Al Falloon > > Bayley, Alistair wrote: > > Al Falloon wrote: > >> what does withSession return if there is a DBException? > > > > Well, whatever the handler returns, same as with any other exception > > handler. Note that this must have the same type as whatever > withSession > > returns, and this constraint is enforced by the type of > catch/catchDB: > > Sorry, I wasn't clear. What does it return when there is an uncaught > exception? It sounds like it raises an exception in IO. Is > this correct? Well, a function raising an uncaught exception doesn't really return anything - it's raised an exception. I'm not clear on the semantics of exceptions in Haskell, but if you don't catch it then eventually it reaches the RTS, which will halt your program with an uncaught exception error. If you're asking if it propagates up to the RTS, then the answer is yes. The downside is that because it's a dynamic exception, the RTS can't/won't show anything other than "uncaught dynamic exception", which isn't helpful. Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** From bulat.ziganshin at gmail.com Thu Feb 1 11:41:19 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Feb 1 11:37:25 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability andthe Future of Languages In-Reply-To: <014801c74616$7405f200$82317ad5@cr3lt> References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk><44684289.20070131024627@gmail.com> <20070131090116.GA4825@lambda><7810250795.20070131194615@gmail.com><20070201101539.GA5341@lambda> <746489552.20070201133356@gmail.com> <014801c74616$7405f200$82317ad5@cr3lt> Message-ID: <1689917135.20070201194119@gmail.com> Hello Claus, Thursday, February 1, 2007, 6:34:23 PM, you wrote: > is it, though? what makes it longer are features that the original doesn't have, and what i don't need :) > I think. so how about a less ambitious translation, with crc in an MVar and a > while-loop that can be broken from the body as well as the condition: > while (hGetBuf h buf bufzise .==. (return bufsize)) $ do > crc =: updateCrc crc buf bufsize > breakIf ((val crc) .==. (return 0)) `orElse` do > printM (val crc) > od your solution is just to make lifted copy of each and every pure operation. so one should define 2^n operations where n is number of arguments -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From deliverable at gmail.com Thu Feb 1 13:17:36 2007 From: deliverable at gmail.com (Alexy Khrabrov) Date: Thu Feb 1 13:12:45 2007 Subject: [Haskell-cafe] Boost equivalent In-Reply-To: References: Message-ID: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> One of the great strengths of Python is Boost.Python. Practitioners say it's a major advantage of Python over Ruby, for example. So the question is not whether there's a Boost in Haskell -- C++ and Haskell are too different for it to have much meaning -- but whether there's or going to be a Boost.Haskell? Cheers, Alexy On Feb 1, 2007, at 5:03 AM, John Ky wrote: > Does the Haskell community have an equivalent to C++ community's > Boost project with the aim of writing libraries for the eventual > inclusion into Haskell? From jgbailey at gmail.com Thu Feb 1 14:38:07 2007 From: jgbailey at gmail.com (Justin Bailey) Date: Thu Feb 1 14:33:01 2007 Subject: [Haskell-cafe] "Circular" programming (aka time-travel) resources? Message-ID: In "The Monad.Reader - Issue 6", that just came out, there is a really interesting article that uses a "circular" technique to implement an assembly language in Haskell. The technique demonstrated seems fascinating. Can someone point me to more resources on the topic? A quick google search turned up a couple of blogs and some papers - but is there more out there? Thanks for any help! Justin From ndmitchell at gmail.com Thu Feb 1 14:44:06 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Feb 1 14:38:58 2007 Subject: [Haskell-cafe] "Circular" programming (aka time-travel) resources? In-Reply-To: References: Message-ID: <404396ef0702011144p6a44974bj5c7b9f9433755bfb@mail.gmail.com> Hi Justin, > A quick google search turned up a couple of blogs and some papers - > but is there more out there? http://news.cs.york.ac.uk/ftpdir/pub/colin/jfp97lw.ps.gz Laziness, circularity and prime numbers all in one :) Thanks Neil From paul at cogito.org.uk Thu Feb 1 14:46:05 2007 From: paul at cogito.org.uk (Paul Johnson) Date: Thu Feb 1 14:41:00 2007 Subject: [Haskell-cafe] Let's welcome the Ruby hackers! In-Reply-To: References: <20070201060400.GA7164@cse.unsw.EDU.AU> Message-ID: <45C2437D.2090308@cogito.org.uk> On 2/1/07, Donald Bruce Stewart wrote: >> So a big hello to any Ruby/Rails hackers lurking out there! >> Free lambdas for all if you drop by #haskell... I think we should also try to get some feedback about the learning experience: what tutorials work best, and what don't? Do metaphors for monads work? How did they get their heads around big-O complexity with lazy evaluation, and so on. Paul. From wss at cs.nott.ac.uk Thu Feb 1 15:09:49 2007 From: wss at cs.nott.ac.uk (Wouter Swierstra) Date: Thu Feb 1 15:15:41 2007 Subject: [Haskell-cafe] "Circular" programming (aka time-travel) resources? In-Reply-To: References: Message-ID: Hi Justin, > In "The Monad.Reader - Issue 6", that just came out, there is a really > interesting article that uses a "circular" technique to implement an > assembly language in Haskell. The technique demonstrated seems > fascinating. Can someone point me to more resources on the topic? I believe the classical reference is: Richard Bird: Using Circular Programs to Eliminate Multiple Traversals of Data. (http://www.springerlink.com/content/g74174vvl1861605/) There are a few more recent wiki pages worth checking out: http://www.haskell.org/hawiki/CircularProgramming and the more recent http://www.haskell.org/haskellwiki/Circular_programming Hope this helps, Wouter From afalloon at synopsys.com Thu Feb 1 15:35:31 2007 From: afalloon at synopsys.com (Al Falloon) Date: Thu Feb 1 15:30:36 2007 Subject: [Haskell-cafe] Re: Boost equivalent In-Reply-To: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> References: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> Message-ID: Boost.Python is for extending Python with C++, or embedding Python in C++. This is especially useful because it allows you to use Python as an extension language for a C++ program. Presumably Boost.Haskell would be for integrating Haskell code with C++, which would of course be useful, but the main use case (an embedded extension language) that draws people to Boost.Python isn't as much of a draw for Haskell because of the compilation phase. On the other hand, I suppose you could always integrate a Haskell interpreter like Hugs, or even go the HsPlugins route and dynamically load a compiled module, but the fit doesn't seem as natural as it does with a latently typed scripting language. There are also technical problems that are hard to overcome. Extending Python is mostly done in C, so a C++ library to add some nice sugar is a good fit. Haskell, OTOH, embeds C programs via its FFI. There doesn't seem to be any way to export functions and value from C++ to Haskell, but instead the C++ code must import from Haskell. All the heavy lifting is done on the Haskell side, so there isn't as much opportunity to write a slick C++ library. This could change if someone made a version of Hugs that can be linked in as a library with a documented C API for evaluating Haskell code and mucking with Haskell values. But I don't think its much of a priority right now :) -- Alan Falloon Alexy Khrabrov wrote: > One of the great strengths of Python is Boost.Python. Practitioners say > it's a major advantage of Python over Ruby, for example. So the > question is not whether there's a Boost in Haskell -- C++ and Haskell > are too different for it to have much meaning -- but whether there's or > going to be a Boost.Haskell? > > Cheers, > Alexy > > On Feb 1, 2007, at 5:03 AM, John Ky wrote: >> Does the Haskell community have an equivalent to C++ community's Boost >> project with the aim of writing libraries for the eventual inclusion >> into Haskell? From sjanssen at cse.unl.edu Thu Feb 1 16:07:01 2007 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Thu Feb 1 16:02:09 2007 Subject: [Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6 In-Reply-To: <936F862B-8EBF-4A22-8030-8262F6B09AC1@Cs.Nott.AC.UK> References: <936F862B-8EBF-4A22-8030-8262F6B09AC1@Cs.Nott.AC.UK> Message-ID: <53B9665F-9200-43F3-8771-2B65CEF3D030@cse.unl.edu> Yet another higher order solution: dropWhile' p0 xs = foldr f (const []) xs $ p0 where f y ys p | p y = ys p | otherwise = y : ys (const False) Spencer Janssen From bjpop at csse.unimelb.edu.au Thu Feb 1 17:08:46 2007 From: bjpop at csse.unimelb.edu.au (Bernie Pope) Date: Thu Feb 1 17:03:50 2007 Subject: [Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6 In-Reply-To: References: <936F862B-8EBF-4A22-8030-8262F6B09AC1@Cs.Nott.AC.UK> Message-ID: <45C264EE.50608@csse.unimelb.edu.au> David House wrote: > It was a great article though, seeing > fix's definition in terms of foldr was one of those mind-bending > moments which makes learning Haskell what it is. > It's nice to see so many new solutions posted in the cafe. The great thing about Haskell is that it keeps on giving :) Cheers, Bernie. From slavomir.kaslev at gmail.com Thu Feb 1 17:15:50 2007 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Feb 1 17:10:42 2007 Subject: [Haskell-cafe] Re: Boost equivalent In-Reply-To: References: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> Message-ID: <171dfd0a0702011415t6aa01ed8x85cab15cc0f8b036@mail.gmail.com> On 2/1/07, Al Falloon wrote: > Boost.Python is for extending Python with C++, or embedding Python in > C++. This is especially useful because it allows you to use Python as an > extension language for a C++ program. > > Presumably Boost.Haskell would be for integrating Haskell code with C++, > which would of course be useful, but the main use case (an embedded > extension language) that draws people to Boost.Python isn't as much of a > draw for Haskell because of the compilation phase. > > On the other hand, I suppose you could always integrate a Haskell > interpreter like Hugs, or even go the HsPlugins route and dynamically > load a compiled module, but the fit doesn't seem as natural as it does > with a latently typed scripting language. > > There are also technical problems that are hard to overcome. Extending > Python is mostly done in C, so a C++ library to add some nice sugar is a > good fit. Haskell, OTOH, embeds C programs via its FFI. There doesn't > seem to be any way to export functions and value from C++ to Haskell, > but instead the C++ code must import from Haskell. All the heavy lifting > is done on the Haskell side, so there isn't as much opportunity to write > a slick C++ library. > > This could change if someone made a version of Hugs that can be linked > in as a library with a documented C API for evaluating Haskell code and > mucking with Haskell values. But I don't think its much of a priority > right now :) > > -- > Alan Falloon > I think a more common scenario would be using C++ legacy code in Haskell project. I would imagine Boost.Haskell as collection of code generation templates for exposing C++ APIs to be used in Haskell. That would be sweet. Even sweeter is easily accessing .Net Framework from ghc, especially for Windows users. .Net Framework is huge. It is de-facto _the_ windows framework. Are there any projects going in this direction? -- Slavomir Kaslev From claus.reinke at talk21.com Thu Feb 1 18:39:53 2007 From: claus.reinke at talk21.com (Claus Reinke) Date: Thu Feb 1 18:34:49 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composabilityandthe Future of Languages References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk><44684289.20070131024627@gmail.com><20070131090116.GA4825@lambda><7810250795.20070131194615@gmail.com><20070201101539.GA5341@lambda><746489552.20070201133356@gmail.com><014801c74616$7405f200$82317ad5@cr3lt> <1689917135.20070201194119@gmail.com> Message-ID: <023601c7465a$47192660$82317ad5@cr3lt> >> while (hGetBuf h buf bufzise .==. (return bufsize)) $ do >> crc =: updateCrc crc buf bufsize >> breakIf ((val crc) .==. (return 0)) `orElse` do >> printM (val crc) >> od > > your solution is just to make lifted copy of each and every pure > operation. so one should define 2^n operations where n is number of > arguments ah, I thought the problem at hand was breaking out of a while loop. but if you look closely, I think you'll find it to be ~2 operations, the monadic one, and possibly a pure one to be lifted. one can always lift pure arguments via return, and use the fully lifted monadic operation, as I did in the example code (you were talking about imperative programming, after all?-). if one were to go down that route, one would probably want to overload literals, such as (Num a,Monad m) => Num (m a) for fromInteger, rather than writing (return 0) everywhere, and as usual, the obligatory superclasses would get in the way and would have to be ignored, and Bool isn't overloaded, .. all the usual suspects for hampering embedded DSLs in Haskell. Claus From chad.scherrer at gmail.com Thu Feb 1 19:18:29 2007 From: chad.scherrer at gmail.com (Chad Scherrer) Date: Thu Feb 1 19:13:22 2007 Subject: [Haskell-cafe] (a -> [b]) vs. [a -> b] Message-ID: Are (a -> [b]) and [a -> b] isomorphic? I'm trying to construct a function f :: (a -> [b]) -> [a -> b] that is the (at least one-sided) inverse of f' :: [a -> b] -> a -> [b] f' gs x = map ($ x) gs It seems like it should be obvious, but I haven't had any luck with it yet. Any help is greatly appreciated. Thanks, Chad -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070201/f1bda518/attachment.htm From jjinux at gmail.com Thu Feb 1 19:31:36 2007 From: jjinux at gmail.com (Shannon -jj Behrens) Date: Thu Feb 1 19:26:28 2007 Subject: [Haskell-cafe] "Write Yourself a Scheme in 48 Hours" Message-ID: I'm going through the "Write Yourself a Scheme in 48 Hours" tutorial. I like it a lot, but I have some concerns. Are the exercises in the tutorial known to be solvable by mere mortals? For instance: "Rewrite parseNumber using...explicit sequencing with the >>= operator" http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols There aren't any examples of using >>= previous to this question. Furthermore, the link to the Standard Prelude is not helpful because there aren't any examples of how to use >>=. Furthermore, consider the exercise: "Change parseNumber to support the Scheme standard for different bases. You may find the readOct and readHex functions useful." http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols I struggled against this for a couple hours last night. How is the reader supposed to figure out readOct, which is part of ReadS, without understanding the whole ReadS business? If the reader does understand the ReadS business, he probably already understands Haskell far better than the tutorial seems to suggest. I eventually figured out how to write: parseHexNumber = do char '#' char 'x' s <- many1 (oneOf "0123456789abcdefABCDEF") case readHex s of [(n,"")] -> return n but it was no small feat. Furthermore, it was only possible because I had already spent so much time trying to understand "A Gentle Introduction to Haskell". Worst of all, once I had it all implemented, the parser *from* the tutorial: parseExpr :: Parser LispVal parseExpr = parseAtom <|> parseString <|> parseNumber led to some surprising results. It turns out that "#o9", which should be an invalid attempt at an octal number, is getting parsed as an atom. There's a whole layer of difficulty that seems insurmountable by mere mortals like me using just this tutorial and minimal reference usage. What am I missing? Is it really solvable by mere mortals who don't already know Haskell, the Parsec module, etc.? Thanks, -jj -- http://jjinux.blogspot.com/ From haskell at brecknell.org Thu Feb 1 20:02:42 2007 From: haskell at brecknell.org (Matthew Brecknell) Date: Thu Feb 1 19:57:33 2007 Subject: [Haskell-cafe] (a -> [b]) vs. [a -> b] In-Reply-To: References: Message-ID: <1170378162.22684.1172488701@webmail.messagingengine.com> Chad Scherrer said: > Are (a -> [b]) and [a -> b] isomorphic? > > I'm trying to construct a function > > f :: (a -> [b]) -> [a -> b] > > that is the (at least one-sided) inverse of > > f' :: [a -> b] -> a -> [b] > f' gs x = map ($ x) gs > > It seems like it should be obvious, but I haven't had any luck with it > yet. > Any help is greatly appreciated. Have a look at this post and it's follow-ups: http://www.haskell.org/pipermail/haskell-cafe/2006-December/020041.html From sdowney at gmail.com Thu Feb 1 20:04:39 2007 From: sdowney at gmail.com (Steve Downey) Date: Thu Feb 1 19:59:30 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages Message-ID: The 70's and early 80's were very different in terms of information propagation. I really miss some the journals available back then, because the editors really did their jobs, both in selecting and helping to convey, information. OO did get oversold. The same way that putting it on the internet did at the beginning of this century (I love saying that, now, where's my flying car) but just like many of the good principles of structured programming inform OO, it should be possible to take good OO and apply it functionally. On 1/30/07, Bulat Ziganshin wrote: > Hello Steve, > > Friday, January 26, 2007, 10:03:09 PM, you wrote: > > > Haskell _is_ hard, although I don't think it's _too_ hard, or I wouldn't > ... > > > The audience for programming languages like Haskell is always going to > > be small, because it appeals to those who want to understand how the TV > > works, > > i don't think so :) imho, we just don't have good _teachers_. in > 70's, OOP audience was also small, but it was popularized later and > now every student know about polymorphism via inheritance. but most of > OOP programmers don't reinvent the wheels, they just use "patterns" > described in OOP bestselling books > > i have a positive experience of making "complex" concepts easy and > available for wide audience ([1]-[5]), [1] was even used to teach > students in some college. and i guess that good Haskell books, such as > yaht and printed ones, also make it easy to learn Haskell. but we need > to gather much more attention to Haskell to make it as "patternized" > as structured-programming and OOP. _nowadays_ there is no even one > "advanced Haskell" or "Haskell in Real World" book and this means that > anyone who want to learn Haskell in deep should study those terrible papers > > (well, it's very like higher education in Russia - no one really > teaches you at our colleges so you should either learn yourself or die :) > but this means that at least whose who still alive, are Real Machos :) > > the same apply to Haskell - now the only way to learn it is to learn > yourself, so we all definitely are cool mans. once i even got C# job > offer only because i know Haskell :) > > > [1] http://haskell.org/haskellwiki/IO_inside > http://haskell.org/haskellwiki/OOP_vs_type_classes > http://haskell.org/haskellwiki/Modern_array_libraries > http://haskell.org/bz/th3.htm > http://haskell.org/bz/thdoc.htm > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bos at serpentine.com Thu Feb 1 23:22:04 2007 From: bos at serpentine.com (Bryan O'Sullivan) Date: Thu Feb 1 23:16:55 2007 Subject: [Haskell-cafe] "Write Yourself a Scheme in 48 Hours" In-Reply-To: References: Message-ID: <45C2BC6C.5040607@serpentine.com> Shannon -jj Behrens wrote: > I'm going through the "Write Yourself a Scheme in 48 Hours" > > > tutorial. I like it a lot, but I have some concerns. Are the > exercises in the tutorial known to be solvable by mere mortals? The answer seems to be "yes, iff the mortals in question have grasped the basics of monads, so they can fill in the gaps in the exposition." > For instance: > > "Rewrite parseNumber using...explicit sequencing with the >>= operator" > http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols > > There aren't any examples of using >>= previous to this question. There's a peculiar mixture of assumptions in the article. He treats monads breezily, as if they're a given; but pattern matching (much more basic) receives some rather more detailed exposition. And he glosses over ">>", but doesn't mention the rewrite rule from "a<-x" to "x>>=\a->". So don't beat yourself up. The tutorial is missing a few bits and pieces. High performance strings on the shootout: http://shootout.alioth.debian.org/gp4/benchmark.php?test=sumcol&lang=all interesting alternative programs 0.5 Haskell GHC #5 1.29 90,880 270 1.0 Clean 2.77 600 136 2.0 C gcc 5.64 444 159 2.1 D Digital Mars #2 5.85 700 153 2.3 C++ g++ #2 6.46 848 244 Ah well, its illegally strict, but its good to know you can do it, eh? (A lazy bytestring version has been submitted, we'll see how that runs). -- Don From bonobo at bigpond.net.au Fri Feb 2 00:50:23 2007 From: bonobo at bigpond.net.au (Alexis) Date: Fri Feb 2 00:45:12 2007 Subject: [Haskell-cafe] Let's welcome the Ruby hackers! In-Reply-To: <45C2437D.2090308@cogito.org.uk> References: <20070201060400.GA7164@cse.unsw.EDU.AU> <45C2437D.2090308@cogito.org.uk> Message-ID: <200702021650.24390.bonobo@bigpond.net.au> On Fri, 2 Feb 2007 06:46 am, Paul Johnson wrote: > I think we should also try to get some feedback about the learning > experience: what tutorials work best, and what don't? Do metaphors for > monads work? Fwiw, here's an excerpt from something i wrote in my blog about monads (where i've substituted links with references to footnotes): "People have tried to communicate what Haskell monads are about in various ways: via 'container' metaphors (e.g. this[1] and this[2]; i found the former to be more illuminating than the latter); via relationship metaphors (e.g. this[3], which i found more confusing than helpful), and even via a 'monsters' metaphor[4] (which i found to be rather amusing)1. One tutorial that people on the Haskell-caf? list seem eager to recommend (and that's recommended on the Haskellwiki) is All about monads[5], but that just overwhelmed me when i first read it; and even now, when i've got a better understanding of monads, i still find it difficult to follow. In contrast, i found Tackling the awkward squad[6] and Monads for functional programming[7] to both be very enlightening. As far as i can tell, however, a monad simply seems to be a computational environment in which one can specify that certain types and methods of computation be performed, and in which the three monad laws are expected to hold." [1] http://www.haskell.org/haskellwiki/Monads_as_containers [2] http://en.wikibooks.org/wiki/Haskell/Understanding_monads [3] http://www.haskell.org/haskellwiki/Meet_Bob_The_Monadic_Lover [4] http://www.haskell.org/pipermail/haskell-cafe/2006-November/019190.html [5] http://www.nomaware.com/monads/html/ [6] http://research.microsoft.com/~simonpj/papers/marktoberdorf/ [7] http://homepages.inf.ed.ac.uk/wadler/topics/monads.html To that, i would also add that i've found Martin Grabmueller's "Monad Transformers Step by Step" ( http://uebb.cs.tu-berlin.de/~magr/pub/Transformers.en.html ) and Simon Peyton-Jones' "Beautiful Concurrency" ( http://programming.reddit.com/info/vsba/comments ) to be very readable and enlightening. Finally, i enjoyed reading Hal Daume III's "Yet Another Haskell Tutorial", since unlike many introductions to Haskell, it assumed that i was already familiar with a variety of programming concepts. My background: well, firstly, apropos of the recent discussions about the qualifications of those studying / learning Haskell, i have a Bachelor of Arts degree majoring in Womens' Studies. :-) i have, however, done professional development work using both Perl and VBA (the latter in the context of MS Access). The only formal mathematical training i've had is the mathematics i did at secondary school, which went up to and included the basics of differentiation and integration. Having said that, i have continued to teach myself various areas of mathematics (e.g. set theory and point-set topology - category theory i'd like to learn more about, but am struggling to get around to doing so). i must say i'm really enjoying learning Haskell: not only because, as a side effect :-), i'm ending up learning various bits and pieces about computer science; but also because i've come to very much appreciate the Haskell community. In contrast with other IT-related communities i've experienced, i've found the Haskell community (both here and on IRC) to generally be helpful, good-humoured and mercifully lacking in flames and alpha behaviours. :-) i'm really hoping this "Cookbook" project happens - it would be great to be able to turn to Haskell for solutions to the sort of problems i come across on a regular basis, so that i'm no longer solely thinking in terms of Perl solutions to those problems. :-) Alexis. From newsham at lava.net Fri Feb 2 02:01:18 2007 From: newsham at lava.net (Tim Newsham) Date: Fri Feb 2 01:56:09 2007 Subject: [Haskell-cafe] snd and tuples of various sizes... Message-ID: This seems to make using tuples of various sizes easier (and can also be applied to non-tuples). I think it more closely matches how I describe something in spoken language (when I say "second" its obvious what that means for any tuple size): {-# OPTIONS_GHC -fglasgow-exts #-} module Main where class Second a b | a -> b where snd :: a -> b instance Second (a,b) b where snd (a,b) = b instance Second (a,b,c) b where snd (a,b,c) = b instance Second (a,b,c,d) b where snd (a,b,c,d) = b instance Second (a,b,c,d,e) b where snd (a,b,c,d,e) = b instance Second (a,b,c,d,e,f) b where snd (a,b,c,d,e,f) = b instance Second [a] a where snd [] = error "don't got none" snd (x:y:xs) = y main = do print $ snd (1,2) print $ snd (8,9,3) print $ snd (9,8,9,3) print $ snd (4,9,8,9,3) print $ snd [3,4] Tim Newsham http://www.thenewsh.com/~newsham/ From hjgtuyl at chello.nl Fri Feb 2 02:34:08 2007 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri Feb 2 02:28:57 2007 Subject: [Haskell-cafe] "Write Yourself a Scheme in 48 Hours" In-Reply-To: References: Message-ID: See for examples of the usage of >>= "A tour of the Haskell monad functions", URL: members.chello.nl/hjgtuyl/tourdemonad.html On Fri, 02 Feb 2007 01:31:36 +0100, Shannon -jj Behrens wrote: > I'm going through the "Write Yourself a Scheme in 48 Hours" > > tutorial. I like it a lot, but I have some concerns. Are the > exercises in the tutorial known to be solvable by mere mortals? > > For instance: > > "Rewrite parseNumber using...explicit sequencing with the >>= operator" > http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols > > There aren't any examples of using >>= previous to this question. > Furthermore, the link to the Standard Prelude is not helpful because > there aren't any examples of how to use >>=. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From gale at sefer.org Fri Feb 2 04:04:49 2007 From: gale at sefer.org (Yitzchak Gale) Date: Fri Feb 2 03:59:40 2007 Subject: [Haskell-cafe] (a -> [b]) vs. [a -> b] In-Reply-To: References: Message-ID: <2608b8a80702020104m5f3da176yc63630afc0f11836@mail.gmail.com> Chad Scherrer wrote: > Are (a -> [b]) and [a -> b] isomorphic? I'm trying to construct a function > > f :: (a -> [b]) -> [a -> b] > > that is the (at least one-sided) inverse of > > f' :: [a -> b] -> a -> [b] > f' gs x = map ($ x) gs Anything better than this? f g = [\x -> g x !! n | n <- [0..]] -Yitz From p.f.moore at gmail.com Fri Feb 2 04:44:22 2007 From: p.f.moore at gmail.com (Paul Moore) Date: Fri Feb 2 04:39:14 2007 Subject: [Haskell-cafe] Re: Boost equivalent In-Reply-To: <171dfd0a0702011415t6aa01ed8x85cab15cc0f8b036@mail.gmail.com> References: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> <171dfd0a0702011415t6aa01ed8x85cab15cc0f8b036@mail.gmail.com> Message-ID: <79990c6b0702020144of911bdv91a251a772d2e44a@mail.gmail.com> On 01/02/07, Slavomir Kaslev wrote: > Even sweeter is easily accessing .Net Framework from > ghc, especially for Windows users. .Net Framework is huge. It is > de-facto _the_ windows framework. Are there any projects going in this > direction? That would indeed be nice - it would make a good replacement for the old H/Direct COM interface, which sadly no longer seems to be maintained... You might also be interested in a couple of "Haskell for .NET" projects: http://galois.com/~sof/hugs98.net/ (Hugs.NET) http://kahu.zoot.net.nz/ (Mondrian, includes Haskell.NET) http://php.cin.ufpe.br/~haskell/haskelldotnet/ (Haskell.NET) None seem maintained, unfortunately - the last URL is dead, which may be temporary... Paul. From haskell at list.mightyreason.com Fri Feb 2 05:28:55 2007 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Feb 2 05:23:52 2007 Subject: [Haskell-cafe] Channel9 Interview: Software Composability andthe Future of Languages In-Reply-To: <014801c74616$7405f200$82317ad5@cr3lt> References: <37882.204.4.130.140.1169831623.squirrel@integ-45100-001.dsvr.co.uk><44684289.20070131024627@gmail.com> <20070131090116.GA4825@lambda><7810250795.20070131194615@gmail.com><20070201101539.GA5341@lambda> <746489552.20070201133356@gmail.com> <014801c74616$7405f200$82317ad5@cr3lt> Message-ID: <45C31267.90205@list.mightyreason.com> Claus Reinke wrote: >>>> while (hGetBuf h buf bufsize == bufsize) >>>> crc := updateCrc crc buf bufsize >>>> break if crc==0 >>>> print crc >> >>> inContT $ callCC $ \break -> do >>> flip execStateT 0 $ do >>> whileM (liftM (== bufsize) (hGetBuf h buf bufsize)) $ do >>> modifyM (updateCrc buf bufsize) >>> crc <- get >>> when (crc == 0) (lift (break crc)) >>> print crc >> >> first. it's longer than original. > The above version required passing break explicitly. I can pack that into a Reader. The actual semantics of the while loop from 'c' are then more closely followed. This allows: > run_ = runner_ testWhile_ > runner_ m = runRWS (runContT m return) NoExit_ (17::Int) > testWhile_ = while_ (liftM (>10) get) innerWhile_ > innerWhile_ = do > v <- get > tell_ [show v] > when' (v==20) (tell_ ["breaking"] >> breakW_) > if v == 15 > then put 30 >> continueW_ > else modify pred The result is > ((),20,["17","16","15","30","29","28","27","26","25","24","23","22","21","20","breaking"]) Where there is the benefit over C of putting the break or continue in a sub-function. The full code (for two versions) is: -- By Chris Kuklewicz, BSD-3 license, February 2007 -- Example of pure "while" and "repeat until" looping constructs using -- the monad transformer library. Works for me in GHC 6.6 -- -- The underscore version is ContT of RWS and this works more -- correctly than the non-underscore version of RWST of Cont. -- -- Perhaps "Monad Cont done right" from the wiki would help? import Control.Monad.Cont import Control.Monad.RWS import Control.Monad.Error import Control.Monad.ST import System.IO.Unsafe import Data.STRef -- Note that all run* values are the same Type main = mapM_ print [run,run2,run_,run2_] run,run_,run2,run2_ :: MyRet () run = runner testWhile run2 = runner testRepeatUntil run_ = runner_ testWhile_ run2_ = runner_ testRepeatUntil_ runner_ m = runRWS (runContT m return) NoExit_ (17::Int) runner m = (flip runCont) id (runRWST m NoExit (17)) testRepeatUntil_ = repeatUntil_ (liftM (==17) get) innerRepeatUntil_ testRepeatUntil = repeatUntil (liftM (==17) get) innerRepeatUntil innerRepeatUntil_ = tell_ ["I ran"] >> breakW_ innerRepeatUntil = tell ["I ran"] >> breakW testWhile_ = while_ (liftM (>10) get) innerWhile_ testWhile = while (liftM (>10) get) innerWhile -- innerWhile_ :: ContT () (T_ (Exit_ () Bool Bool)) () innerWhile_ = do v <- get tell_ [show v] when' (v==20) (tell_ ["breaking"] >> breakW_) if v == 15 then put 30 >> continueW_ else modify pred innerWhile = do v <- get tell [show v] when' (v==20) (tell ["breaking"] >> breakW) if v == 15 then put 30 >> continueW else modify pred -- The Monoid restictions means I can't write an instance, so use tell_ tell_ = lift . tell -- Generic defintions getCC :: MonadCont m => m (m a) getCC = callCC (\c -> let x = c x in return x) getCC' :: MonadCont m => a -> m (a, a -> m b) getCC' x0 = callCC (\c -> let f x = c (x, f) in return (x0, f)) when' :: (Monad m) => Bool -> m a -> m () when' b m = if b then (m >> return ()) else return () -- Common types type MyState = Int type MyWriter = [String] type MyRet a = (a,MyState,MyWriter) -- RWST of Cont Types type T r = RWST r MyWriter MyState type Foo r a = T (Exit (MyRet r) a a) (Cont (MyRet r)) type WhileFunc = Foo () Bool type ExitFoo r a = Foo r a a -- (Exit r a a) (Cont r) a type ExitType r a = T (Exit r a a) (Cont r) a data Exit r a b = Exit (a -> ExitType r b) | NoExit -- ContT of RWS Types type T_ r = RWS r MyWriter MyState type ExitType_ r a = ContT r (T_ (Exit_ r a a)) a data Exit_ r a b = Exit_ (a -> ExitType_ r b) | NoExit_ -- Smart destructor for Exit* types getExit (Exit loop) = loop getExit NoExit = (\ _ -> return (error "NoExit")) getExit_ (Exit_ loop) = loop getExit_ NoExit_ = (\ _ -> return (error "NoExit")) -- I cannot see how to lift withRWS, so use local -- Perhaps "Monad Cont done right" from the wiki would help? withLoop_ loop = local (\r -> Exit_ loop) -- withRWST can change the reader Type withLoop loop = withRWST (\r s -> (Exit loop,s)) -- The condition is never run in the scope of the (withLoop loop) -- continuation. I could have invoked (loop True) for normal looping -- but I decided a tail call works as well. This decision has -- implication for the non-underscore version, since the writer/state -- can get lost if you call (loop _). while_ mCondition mBody = do (proceed,loop) <- getCC' True let go = do check <-mCondition when' check (withLoop_ loop mBody >> go) when' proceed go while mCondition mBody = do (proceed,loop) <- getCC' True let go = do check <-mCondition when' check (withLoop loop mBody >> go) when' proceed go repeatUntil_ mCondition mBody = do (proceed,loop) <- getCC' True let go = do withLoop_ loop mBody check <- mCondition when' (not check) go when' proceed go repeatUntil mCondition mBody = do (proceed,loop) <- getCC' True let go = do withLoop loop mBody check <- mCondition when' (not check) go when' proceed go -- breakW :: WhileFunc a breakW_ = ask >>= \e -> getExit_ e False >> return undefined breakW = ask >>= \e -> getExit e False >> return undefined -- continueW :: WhileFunc a continueW_ = ask >>= \e -> getExit_ e True >> return undefined continueW = ask >>= \e -> getExit e True >> return undefined From alistair at abayley.org Fri Feb 2 06:28:34 2007 From: alistair at abayley.org (Alistair Bayley) Date: Fri Feb 2 06:23:26 2007 Subject: [Haskell-cafe] ANN: Takusen 0.6 Message-ID: <79d7c4980702020328l1c415dfeo8cb98dcfc9167231@mail.gmail.com> We are pleased to announce a new release of Takusen. There are a large number of changes and bug-fixes: - Oracle support for processing cursors returned from procedure calls - withContinuedSession supports connection reuse (e.g. for persistent connections and connection pooling) - new README file with useful information about getting started with Takusen - new UTF8 en/de-coder (the old one was buggy) - PostgreSQL support for CalendarTime - improved Cabal Setup.hs script, which does a better job of modifying the installation to reflect installed DBMS's. This gives good ghci support (PostgreSQL users on Windows have a small extra step) - prepared statement API requires that users distinguish between queries and DML Our long-term plans are the same as ever: - large objects - ODBC and MS Sql Server backends Release: http://darcs.haskell.org/takusen/takusen-0.6.tar.gz Source: darcs get --partial http://darcs.haskell.org/takusen Oleg and Alistair From apfelmus at quantentunnel.de Fri Feb 2 06:30:24 2007 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Fri Feb 2 06:27:20 2007 Subject: [Haskell-cafe] Re: Let's welcome the Ruby hackers! In-Reply-To: <200702021650.24390.bonobo@bigpond.net.au> References: <20070201060400.GA7164@cse.unsw.EDU.AU> <45C2437D.2090308@cogito.org.uk> <200702021650.24390.bonobo@bigpond.net.au> Message-ID: Alexis wrote: > In contrast with other IT-related communities i've experienced, > i've found the Haskell community (both here and on IRC) to generally be > helpful, good-humoured and mercifully lacking in flames and alpha > behaviours. :-) I have to reject this claim because there are quite many alphas in here. For instance, ??.? notoriously tries to creep in every discussion, just because he thinks that he is principally more general than the others. Of course, he's a blatant liar. Another well known troll is ??.? -> ?. While at least not throwing in contradictory posts, he greatly overestimates his role. Most often, you can just elide his contributions as he only repeats prior arguments. Sometimes, he even signs his posts with the pseudonym (??.? -> ?)->(??.? -> ?) to rise in rank, but this is easily seen through. The list once tried to employ alpha-conversion to get rid of them. But the only effect was that now, the betas annoy us as well! A particularly persistent offspring is ??.? -> ? -> ? giving rise to much debate in regular intervals: he managed to subvert parametricity. Also, the mischievous ???.? -> ? even plotted with evil IO to get the attention he thinks he deserves. In the end, the alphas and betas are noisy braggarts, talking very long about what they want to do without doing anything at all. It's the lambdas who do all the real work. Fortunately, they most often don't need the signature from their alpha bosses. Regards, apfelmus PS: This mail is best viewed with Unicode (UTF-8). From moonlite at dtek.chalmers.se Fri Feb 2 07:28:49 2007 From: moonlite at dtek.chalmers.se (Mattias Bengtsson) Date: Fri Feb 2 07:23:41 2007 Subject: [Haskell-cafe] snd and tuples of various sizes... In-Reply-To: References: Message-ID: <1170419329.11573.5.camel@localhost.localdomain> On Thu, 2007-02-01 at 21:01 -1000, Tim Newsham wrote: > instance Second [a] a where > snd [] = error "don't got none" > snd (x:y:xs) = y Would'nt that instance mean this: snd [] produces error snd [x] gives [] I'd implement it something like this (if this works?): instance Second [a] (Maybe a) where snd [] = Nothing snd [x] = Nothing snd (x:y:xs) = Just y -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070202/c1d8a641/attachment.bin From d00farre at dtek.chalmers.se Fri Feb 2 07:45:04 2007 From: d00farre at dtek.chalmers.se (Andreas Farre) Date: Fri Feb 2 08:03:54 2007 Subject: [Haskell-cafe] snd and tuples of various sizes... In-Reply-To: <1170419329.11573.5.camel@localhost.localdomain> References: <1170419329.11573.5.camel@localhost.localdomain> Message-ID: <39354.213.65.251.99.1170420304.squirrel@webmail.chalmers.se> Mattias Bengtsson wrote: > On Thu, 2007-02-01 at 21:01 -1000, Tim Newsham wrote: >> instance Second [a] a where >> snd [] = error "don't got none" >> snd (x:y:xs) = y > > Would'nt that instance mean this: > snd [] produces error > snd [x] gives [] > > > I'd implement it something like this (if this works?): > > instance Second [a] (Maybe a) where > snd [] = Nothing > snd [x] = Nothing > snd (x:y:xs) = Just y And while we're re-implementing the Prelude with MPTC: class Currying a b | a -> b where curryC :: a -> b uncurryC :: b -> a instance Currying ((a, b) -> c) (a -> b -> c) where curryC = curry uncurryC = uncurry instance Currying ((a, b, c) -> d) (a -> b -> c -> d) where curryC f a b c = f (a, b, c) uncurryC f (a, b, c) = f a b c instance Currying ((a, b, c, d) -> e) (a -> b -> c -> d -> e) where curryC f a b c d = f (a, b, c, d) uncurryC f (a, b, c, d) = f a b c d instance Currying ((a, b, c, d, e) -> f) (a -> b -> c -> d -> e -> f) where curryC f a b c d e = f (a, b, c, d, e) uncurryC f (a, b, c, d, e) = f a b c d e ... Andreas -- some cannot be created more equal than others From haskell at list.mightyreason.com Fri Feb 2 08:44:37 2007 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Feb 2 08:39:34 2007 Subject: [Haskell-cafe] Array copy performance Message-ID: <45C34045.1090308@list.mightyreason.com> Hi, I am trying to improve the memory usage of regex-tdfa and I wanted to ask an array question. If I have two identical STUArrays (same type and bounds) then what is the most efficient way to overwrite the data in the destination with the data in the source? Does this work for STArrays? Is there a GHC only solution? Is there a way to avoid the long loop? > forM_ (range b) $ \index -> > readArray source index >>= writeArray destination index Is Data.Array.Storable the only route? I do not think Data.Array.Diff will work well since I have one source going to multiple destinations, each with a few different changes. -- Chris From max.vasin at gmail.com Fri Feb 2 08:49:06 2007 From: max.vasin at gmail.com (Max Vasin) Date: Fri Feb 2 08:44:44 2007 Subject: [Haskell-cafe] Re: snd and tuples of various sizes... References: <1170419329.11573.5.camel@localhost.localdomain> Message-ID: <8764ak8yb1.fsf@smtp.gmail.com> >>>>> "Mattias" == Mattias Bengtsson writes: Mattias> On Thu, 2007-02-01 at 21:01 -1000, Tim Newsham wrote: >> instance Second [a] a where snd [] = error "don't got none" snd >> (x:y:xs) = y Mattias> Would'nt that instance mean this: snd [] produces error Mattias> snd [x] gives [] No. It is non-exhaustive pattern. In fact this is needed: > instance Second [a] a where > snd (_:y:_) = y > snd _ = error "don't got none" Mattias> I'd implement it something like this (if this works?): Mattias> instance Second [a] (Maybe a) where snd [] = Nothing snd Mattias> [x] = Nothing snd (x:y:xs) = Just y Well, we also can define: > class SafeSecond a b | a -> b where > ssnd :: (Monad m) => a -> m b > instance SafeSecond [a] a where > ssnd (_:y:_) = return y > ssnd _ = fail "don't got none" > main = do > print $ (ssnd [1, 2, 3] :: Maybe Int) > print $ (ssnd [1] :: Maybe Int) -- WBR, Max Vasin. From haskell-cafe at martinpercossi.com Fri Feb 2 08:54:13 2007 From: haskell-cafe at martinpercossi.com (Martin Percossi) Date: Fri Feb 2 08:49:03 2007 Subject: [Haskell-cafe] Timezone Database Library Message-ID: <45C34285.30000@martinpercossi.com> Hello, is there a haskell library that provides facilities to read and use the tzfile format [1], or equivalent in Windows? TIA Martin [1] http://www.twinsun.com/tz/tz-link.htm From bulat.ziganshin at gmail.com Fri Feb 2 09:02:42 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Feb 2 08:58:12 2007 Subject: [Haskell-cafe] Array copy performance In-Reply-To: <45C34045.1090308@list.mightyreason.com> References: <45C34045.1090308@list.mightyreason.com> Message-ID: <309073228.20070202170242@gmail.com> Hello Chris, Friday, February 2, 2007, 4:44:37 PM, you wrote: > If I have two identical STUArrays (same type and bounds) then what is the most > efficient way to overwrite the data in the destination with the data in the > source? Does this work for STArrays? > Is there a way to avoid the long loop? >> forM_ (range b) $ \index -> >> readArray source index >>= writeArray destination index the topic of efficient looping over arrays is briefly covered in http://haskell.org/haskellwiki/Modern_array_libraries > Is there a GHC only solution? yes, use "unsafeCoerce# memcpy": module Data.Array.Base where ... #ifdef __GLASGOW_HASKELL__ thawSTUArray :: Ix i => UArray i e -> ST s (STUArray s i e) thawSTUArray (UArray l u arr#) = ST $ \s1# -> case sizeofByteArray# arr# of { n# -> case newByteArray# n# s1# of { (# s2#, marr# #) -> case unsafeCoerce# memcpy marr# arr# n# s2# of { (# s3#, () #) -> (# s3#, STUArray l u marr# #) }}} foreign import ccall unsafe "memcpy" memcpy :: MutableByteArray# RealWorld -> ByteArray# -> Int# -> IO () #endif /* __GLASGOW_HASKELL__ */ -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From joelr1 at gmail.com Fri Feb 2 09:06:38 2007 From: joelr1 at gmail.com (Joel Reymont) Date: Fri Feb 2 09:01:18 2007 Subject: [Haskell-cafe] A distributed and replicating native Haskell database Message-ID: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> Folks, Allegro Common Lisp has AllegroCache [1], a database built on B-Trees that lets one store Lisp objects of any type. You can designate certain slots (object fields) as key and use them for lookup. ACL used to come bundled with the ObjectStore OODBMS for the same purpose but then adopted a native solution. AllegroCache is not distributed or replicating but supports automatic versioning. You can redefine a class and new code will store more (or less) data in the database while code that uses the old schema will merrily chug along. Erlang [2] has Mnesia [3] which lets you store any Erlang term ("object"). It stores records (tuples, actually) and you can also designate key fields and use them for lookup. I haven't looked into this deeply but Mnesia is built on top of DETS (Disk-based Term Storage) which most likely also uses a form of B-Trees. Mnesia is distributed and replicated in real-time. There's no automatic versioning with Mnesia but user code can be run to read old records and write new ones. Would it make sense to build a similar type of a database for Haskell? I can immediately see how versioning would be much harder as Haskell is statically typed. I would love to extend recent gains in binary serialization, though, to add indexing of records based on a designated key, distribution and real-time replication. What do you think? To stimulate discussion I would like to ask a couple of pointed questions: - How would you "designate" a key for a Haskell data structure? - Is the concept of a schema applicable to Haskell? Thanks, Joel [1] http://franz.com/products/allegrocache/index.lhtml [2] http://erlang.org/faq/t1.html [3] http://erlang.org/faq/x1409.html -- http://wagerlabs.com/ From duncan.coutts at worc.ox.ac.uk Fri Feb 2 09:46:07 2007 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Fri Feb 2 09:40:50 2007 Subject: [Haskell-cafe] Array copy performance In-Reply-To: <309073228.20070202170242@gmail.com> References: <45C34045.1090308@list.mightyreason.com> <309073228.20070202170242@gmail.com> Message-ID: <1170427567.29376.118.camel@localhost> On Fri, 2007-02-02 at 17:02 +0300, Bulat Ziganshin wrote: > Hello Chris, > > Friday, February 2, 2007, 4:44:37 PM, you wrote: > > > If I have two identical STUArrays (same type and bounds) then what is the most > > efficient way to overwrite the data in the destination with the data in the > > source? Does this work for STArrays? > > > Is there a way to avoid the long loop? > >> forM_ (range b) $ \index -> > >> readArray source index >>= writeArray destination index > > the topic of efficient looping over arrays is briefly covered in > http://haskell.org/haskellwiki/Modern_array_libraries I should note that it is possible to generate good loops, though it's not easy yet from high level code. The binary package has a memory throughput benchmark which compares C and Haskell byte/word read/write loops: http://darcs.haskell.org/binary/tests/ All the Haskell versions compile down to good loops, though the loop body is bigger than in the C case (take a look at the assembly output for the -fasm route). However that's enough for the Haskell versions to get a significant fraction of the memory throughput of the C versions: C memory throughput benchmarks: 500MB of bytes written in 0.468s, at: 1068.3MB/s 500MB of bytes read in 0.380s, at: 1315.7MB/s 500MB of words written in 0.376s, at: 1329.7MB/s 500MB of words read in 0.192s, at: 2604.0MB/s Haskell memory throughput benchmarks: 500MB of bytes written in 1.560s, at: 320.5MB/s 500MB of bytes read in 2.192s, at: 228.1MB/s 500MB of words written in 0.340s, at: 1470.5MB/s 500MB of words read in 0.344s, at: 1453.4MB/s As you can see, the extra size of the loop body hurts us more in the byte size cases than in the word size one, where we're getting much closer to saturating the memory bandwidth of the box. It's a 64bit box so the words are 8 bytes. I'm not quite sure what is going on in the "words written" case. Perhaps someone can see why the C one is loosing out to the Haskell version. Duncan From paul at cogito.org.uk Fri Feb 2 10:06:53 2007 From: paul at cogito.org.uk (Paul Johnson) Date: Fri Feb 2 10:01:47 2007 Subject: [Haskell-cafe] A distributed and replicating native Haskell database In-Reply-To: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> References: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> Message-ID: <45C3538D.8070909@cogito.org.uk> Joel Reymont wrote: > Folks, > > Allegro Common Lisp has AllegroCache [1], a database built on B-Trees > that lets one store Lisp objects of any type. You can designate > certain slots (object fields) as key and use them for lookup. ACL used > to come bundled with the ObjectStore OODBMS for the same purpose but > then adopted a native solution. > > AllegroCache is not distributed or replicating but supports automatic > versioning. You can redefine a class and new code will store more (or > less) data in the database while code that uses the old schema will > merrily chug along. That implies being able to put persistent code into the database. Easy enough in Lisp, less easy in Haskell. How do you serialize it? As a rule, storing functions along with data is a can of worms. Either you actually store the code as a BLOB or you store a pointer to the function in memory. Either way you run into problems when you upgrade your software and expect the stored functions to work in the new context. > Erlang [2] has Mnesia [3] which lets you store any Erlang term > ("object"). It stores records (tuples, actually) and you can also > designate key fields and use them for lookup. I haven't looked into > this deeply but Mnesia is built on top of DETS (Disk-based Term > Storage) which most likely also uses a form of B-Trees. Erlang also has a very disciplined approach to code updates, which presumably helps a lot when functions are stored. > > Mnesia is distributed and replicated in real-time. There's no > automatic versioning with Mnesia but user code can be run to read old > records and write new ones. > > Would it make sense to build a similar type of a database for Haskell? > I can immediately see how versioning would be much harder as Haskell > is statically typed. I would love to extend recent gains in binary > serialization, though, to add indexing of records based on a > designated key, distribution and real-time replication. I very much admire Mnesia, even though I'm not an Erlang programmer. It would indeed be really cool to have something like that. But Mnesia is built on the Erlang OTP middleware. I would suggest that Haskell needs a middleware with the same sort of capabilities first. Then we can build a database on top of it. > What do you think? > > To stimulate discussion I would like to ask a couple of pointed > questions: > > - How would you "designate" a key for a Haskell data structure? I haven't tried compiling it, but something like: class (Ord k) => DataKey a k | a -> k where keyValue :: a -> k > - Is the concept of a schema applicable to Haskell? The real headache is type safety. Erlang is entirely dynamically typed, so untyped schemas with column values looked up by name at run-time fit right in, and its up to the programmer to manage schema and code evolution to prevent errors. Doing all this in a statically type safe way is another layer of complexity and checking. Actually this is also just another special case of the middleware case. If we have two processes, A and B, that need to communicate then they need to agree on a protocol. Part of that protocol is the data types. If B is a database then this reduces to the schema problem. So lets look at the more general problem first and see if we can solve that. There are roughly two ways for A and B to agree on the protocol. One is to implement the protocol separately in A and B. If it is done correctly then they will work together. But this is not statically checkable (ignoring state machines and model checking for now). This is the Erlang approach, because dynamic checking is the Erlang philosophy. Alternatively the protocol can be defined in a special purpose protocol module P, and A and B then import P. This is the approach taken by CORBA with IDL. However what happens if P is updated to P'? Does this mean that both A and B need to be recompiled and restarted simultaneously? Requiring this is a Bad Thing; imagine if every bank in the world had to upgrade and restart its computers simultaneously in order to upgrade a common protocol. (This protocol versioning problem was one of the major headaches with CORBA.) We would have to have P and P', live simultaneously, and processes negotiate the latest version of the protocol that they both support when they start talking. That way the introduction of P' does not need to be simultaneous with the withdrawal of P. There is still the possibility of a run-time failure at the protocol negotiation stage of course, if it transpires that the to processes have no common protocol. So we need a DSL which allows the definition of data types and abstract protocols (i.e. who sends what to whom when) that can be imported by the two processes (do we need N-way protocols?) on each end of the link. If we could embed this in Haskell directly then so much the better, but something that needs preprocessing would be fine too. However there is a wrinkle here: what about "pass through" processes which don't interpret the data but just store and forward it. Various forms of protocol adapter fit this scenario, as does the database you originally asked about. We want to be able to have these things talk in a type-safe manner without needing to be compiled with every data structure they transmit. You could describe these things using type variables, so that for instance if a database table is created to store a datatype D then any process reading or writing the data must also use D, even though the database itself knows nothing more of D than the name. Similarly a gateway that sets up a channel for datatype D would not need to know anything more than the name. Paul. From joelr1 at gmail.com Fri Feb 2 10:20:34 2007 From: joelr1 at gmail.com (Joel Reymont) Date: Fri Feb 2 10:15:16 2007 Subject: [Haskell-cafe] A distributed and replicating native Haskell database In-Reply-To: <45C3538D.8070909@cogito.org.uk> References: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> <45C3538D.8070909@cogito.org.uk> Message-ID: <23B95F1A-025B-45FD-A124-3C8C07D4B744@gmail.com> On Feb 2, 2007, at 3:06 PM, Paul Johnson wrote: > As a rule, storing functions along with data is a can of worms. > Either you actually store the code as a BLOB or you store a pointer > to the function in memory. Either way you run into problems when > you upgrade your software and expect the stored functions to work > in the new context. ACache does not store code in the database. You cannot read the database unless you have your original class code. ACache may store the "schema", i.e. the parent class names, slot names, etc. > Erlang also has a very disciplined approach to code updates, which > presumably helps a lot when functions are stored. No storing of code here either. What you store in Erlang is just tuples so there's no schema or class definition. No functions are stored since any Erlang code can fetch the tuples from Mnesia. You do need to have the original record definition around but this is just to be able to refer to tuple elements with field names rather name field position. > I very much admire Mnesia, even though I'm not an Erlang > programmer. It would indeed be really cool to have something like > that. But Mnesia is built on the Erlang OTP middleware. I would > suggest that Haskell needs a middleware with the same sort of > capabilities first. Then we can build a database on top of it. Right. That would be a prerequisite. > The real headache is type safety. Erlang is entirely dynamically > typed, so untyped schemas with column values looked up by name at > run-time fit right in, and its up to the programmer to manage > schema and code evolution to prevent errors. Doing all this in a > statically type safe way is another layer of complexity and checking. I believe Lambdabot does schema evolution. > Alternatively the protocol can be defined in a special purpose > protocol module P, and A and B then import P. This is the approach > taken by CORBA with IDL. However what happens if P is updated to > P'? Does this mean that both A and B need to be recompiled and > restarted simultaneously? Requiring this is a Bad Thing; imagine if > every bank in the world had to upgrade and restart its computers > simultaneously in order to upgrade a common protocol. I would go for the middle ground and dump the issue entirely. Lets be practical here. When a binary protocol is updated, all code using the protocol needs to be updated. This would be good enough. It would suite me just fine too as I'm not yearning for CORBA, I just want to build a trading infrastructure entirely in Haskell. > There is still the possibility of a run-time failure at the > protocol negotiation stage of course, if it transpires that the to > processes have no common protocol. So no protocol negotiation! > However there is a wrinkle here: what about "pass through" > processes which don't interpret the data but just store and forward > it. Various forms of protocol adapter fit this scenario, as does > the database you originally asked about. Any packet traveling over the wire would need to have a size, followed by a body. Any pass-through protocol can just take the binary blob and re-send it. Thanks, Joel -- http://wagerlabs.com/ From jgbailey at gmail.com Fri Feb 2 10:58:05 2007 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Feb 2 10:52:55 2007 Subject: [Haskell-cafe] Re: Boost equivalent In-Reply-To: <171dfd0a0702011415t6aa01ed8x85cab15cc0f8b036@mail.gmail.com> References: <31F5DB1A-8F24-4D36-A7A0-73C8C48F4269@gmail.com> <171dfd0a0702011415t6aa01ed8x85cab15cc0f8b036@mail.gmail.com> Message-ID: On 2/1/07, Slavomir Kaslev wrote: > would be sweet. Even sweeter is easily accessing .Net Framework from > ghc, especially for Windows users. .Net Framework is huge. It is > de-facto _the_ windows framework. Are there any projects going in this > direction? I would so love to see this happen. I'm actually surprised it hasn't, considering the GHC "guy" works for MS! If for nothing else, .NET has an excellent GUI in Windows Forms. Manipulating that from Haskell would be a dream come true! From rich.neswold at gmail.com Fri Feb 2 11:19:38 2007 From: rich.neswold at gmail.com (Rich Neswold) Date: Fri Feb 2 11:14:27 2007 Subject: [Haskell-cafe] A distributed and replicating native Haskell database In-Reply-To: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> References: <1718578E-90F4-468A-8CEA-FAAD0861CA66@gmail.com> Message-ID: <14cf844b0702020819r7518d5aoe7daf207453099bd@mail.gmail.com> On 2/2/07, Joel Reymont wrote: > Would it make sense to build a similar type of a database for > Haskell? > What do you think? I used mnesia in a little Erlang project I did. It did nearly everything I wanted it to (and stuff I didn't need since it does replication and my project didn't require it.) The one item I didn't care too much about is that your data integrity is enforced by your application. There didn't appear to be constructs that let mnesia protect data corruption. Admittedly, I am inexperienced with mnesia. There may be a way to add constraints and I just missed finding it