[Haskell-cafe] [Haskell-beginners] Re: Is Haskell for me?
Sorry for not sending to the list. - Forwarded message from Felipe Lessa felipe.le...@gmail.com - On Fri, Nov 06, 2009 at 07:58:30PM -0200, Felipe Lessa wrote: On 11/6/09, Gaius Hammond ga...@gaius.org.uk wrote: To be fair, Python offloads its heavy lifting to C libraries - NumPy and SciPy run at very close to full C speed on large datasets. This is also how Matlab works. Unladen Swallow is an upcoming JIT compiler for Python. Where Haskell shines for computation is when you can leverage lazy evaluation. *If* you can offload most of your work to SciPy. Depending on what you do this is at least difficult. I don't know how much of a neural network can be represented as big fat matrix :). I would also like to add that Haskell shines for parallel computation, being easy and rewarding to use multiple cores or processors in a SMP machine. Parallel computing in Python is at least ugly because you need to use multiple processes, while the same task in C++ needs to be dealt with manually using concurrency. -- Felipe. - End forwarded message - ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Weekly News: Issue 138 - November 07, 2009
On Fri, Nov 06, 2009 at 10:04:45PM -0800, jfred...@gmail.com wrote: * mauke: @unpl const (flip const) lambdabot: (\ _ c d - d) I didn't get this one, is it just because lambdabot didn't change 'c' to an underscore? Thanks for the HWN, as always :), -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Weekly News: Issue 138 - November 07, 2009
On Sat, Nov 7, 2009 at 10:48 AM, Felipe Lessa felipe.le...@gmail.com wrote: On Fri, Nov 06, 2009 at 10:04:45PM -0800, jfred...@gmail.com wrote: * mauke: @unpl const (flip const) lambdabot: (\ _ c d - d) I didn't get this one, is it just because lambdabot didn't change 'c' to an underscore? We were experimenting with @pl and yes, that's part of it, but it's also that it skipped a entirely in this case. Just struck me as weird. -- Svein Ove Aas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Card games
Hi! I would like to know if anybody has already thought of or tried to code an EDSL for card games. Ideally you should be able to write the rules the games and get for free: - Game generator: given an input deck, construct the initial state of the game. - Random game generator: besides just creating a random deck and using the item above, it should be nice to be able to randomly construct the game from the final positions. This should guarantee that all random games are solvable. - Hints generator: IOW list possible moves given a game state. - Playable game: probably the EDSL should include at least some information to be able to properly place the cards on the screen. - Game solver: this is somewhat harder to do efficiently, but an inneficient one should be doable. - Demo mode: related to the above, an auto-play distract-me mode. - Tutorial mode: show a screen for each of the rules written? - ...anything more? Just curious, this looks like a perfect job for an EDSL. Also, I guess anybody trying to do something like this should read PySol's code to have some ideas. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Card games
You might peek at my library HCard (it's on Hackage), it uses associated datatypes to allow for a very general playing-card interface. It was only ever a toy to play w/ Assoc. types for me, but I imagine it could be a decent starting point for someone interested in turning it into a real EDSL. It's got a cribbage counter example program bundled with it. /Joe On Nov 7, 2009, at 5:54 AM, Felipe Lessa wrote: Hi! I would like to know if anybody has already thought of or tried to code an EDSL for card games. Ideally you should be able to write the rules the games and get for free: - Game generator: given an input deck, construct the initial state of the game. - Random game generator: besides just creating a random deck and using the item above, it should be nice to be able to randomly construct the game from the final positions. This should guarantee that all random games are solvable. - Hints generator: IOW list possible moves given a game state. - Playable game: probably the EDSL should include at least some information to be able to properly place the cards on the screen. - Game solver: this is somewhat harder to do efficiently, but an inneficient one should be doable. - Demo mode: related to the above, an auto-play distract-me mode. - Tutorial mode: show a screen for each of the rules written? - ...anything more? Just curious, this looks like a perfect job for an EDSL. Also, I guess anybody trying to do something like this should read PySol's code to have some ideas. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsing Haskell
Thanks, I'll check it out. At 22:03 06/11/2009, S. Doaitse Swierstra wrote: The UHC compiler contains a combinator based Haskell parser from which you can borrow fragments, Doaitse Swierstra On 6 nov 2009, at 15:49, Eric Macaulay wrote: Hi all, I was hoping to use Language.Haskell.Parser to parse fragments of Haskell code. However, it appears that one can only use this module to parse complete Haskell programs. Is there anyway around this, or must I write a Haskell parser from scratch? Eric M. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Parsing Haskell
It has indeed reached me. Thanks! At 16:23 06/11/2009, Niklas Broberg wrote: You'd have to modify the parser in haskell-src(-exts) to do add the entry points, though. Actually haskell-src-exts already defines entry points for Module, Stmt, Exp, Pat and Type (as well as [Module] in 1.3.x). Not sure if this message reaches the original poster though. Cheers, /Niklas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Card games
Hi Felipe Close (or maybe not...), Martin Erwig and Eric Walkingshaw have a few papers on embedding a DSL in Haskell for game theory available from Martin's web site: http://web.engr.oregonstate.edu/~erwig/papers/abstracts.html Best wishes Stephen 2009/11/7 Felipe Lessa felipe.le...@gmail.com: Hi! I would like to know if anybody has already thought of or tried to code an EDSL for card games. Ideally you should be able to write the rules the games and get for free: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Card games
Hi Felipe, Interesting idea. But I guess you should clarify what kind of card games you want to support. E.g, a DSL for trick taking games like Bridge, Skat or Doppelkopf might be different from one that's good for Canasta or Rummy. Or do you aim at Solitaire? I'd suggest starting with a very small scope of the domain for a very first version. Good luck writing a `solver' for Doppelkopf! Cheers, Matthias. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Card games
On Sat, Nov 07, 2009 at 08:46:07AM -0500, Matthias Görgens wrote: Interesting idea. But I guess you should clarify what kind of card games you want to support. E.g, a DSL for trick taking games like Bridge, Skat or Doppelkopf might be different from one that's good for Canasta or Rummy. Or do you aim at Solitaire? I'd suggest starting with a very small scope of the domain for a very first version. Hmm, good catch. I was thinking about solitaire, i.e. single player, games. Multiplayer card games certainly have their own set of interesting challenges. If I ever get to develop something capable of expressing nicely Patience, Spider, Pyramid and Black Hole I'll be more than satisfied :). Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: control-monad-exception 0.5 with monadic call traces
Luke Palmer escribió: On Fri, Nov 6, 2009 at 6:54 PM, klondike klondikehaskellc...@xiscosoft.es wrote: Henning Thielemann escribió: That's what I meant with my post: Programming errors (like head []) are not handled by control-monad-exception. As far as I understand, control-monad-exception makes _exceptions_ explicit in the type signatures, not programming errors. Why and how would you make possible programming errors explicit in the type? But for exceptions (e.g. file could not be found) a detailed stack trace is not of much use. I think you have overlooked a few things. First, not every developer knows each one of the lines in the code well enough as to see where a exception comes from, specially when you are not the author of that code. Of course, that wouldn't mind so much unless you see another thing, if we don't know which exceptions can be launched by a operation then you will get it on the upper frame and rendered unable to solve it. Use typed exceptions (as this library intends to) you may say. Ok, now we have another problem, the strange habit of coders to keep the exceptions they don't know/can't treat going up and up and up, until then usually hit the top frame and you are screwed. You can check some Java code (to see an example on how this happens) as some of these exceptional conditions are put on the method's signature. You sound like you are expecting something that works exactly like the imperative exception handling mechanisms you are used to, and are not willing to accept anything else. No, I sound like I am expecting programmers comming from the imperative world to do ugly things, maybe because I once was one. This strange habit of programmers is simply bad practice, and leads to just as brittle code as no exception handling, except that you get inexplicable error message boxes with OK buttons instead of crashes. You might as well just put the whole program in a catch block in IO and bail with something noncomittal. Now comes the time when I have to show you that not every exception could be handled, IE a file not found exception when looking for the config file can be fatal and force the program to stop. But what if this is on a library? How do you suggest that the programmer knows that the File Not Found exception is due to the lack of that config file, specially when the code is badly (or not) documented. IMO, Haskell's typed exceptions (via eg. explicit-exception) *are* the way to go. They keep the number of exceptional conditions that can occur in a body of code small -- if some code has many exceptional conditions, it forces you to *compose* them somehow, to come up with a more precise idea of what your code is doing and how it can fail. Yeah, the thing comes when you get the same kind of exceptions from different places, you need a way to tell them appart. If you are just blindly passing exceptions up from the code below, the interface to your code is getting more and more complex. With typed exceptions, the types are reflecting the complexity of the interface (which is precisely the purpose of types). Well, it's not like blindly pass exceptions up but more like passing exceptions I don't know how to handle up. signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] virus/trojan in bamse package?
hi, my Avira antivirus program says that there is a trojan in the bamse-0.9.5 package. I downloaded the hackage-torrent a week ago, and Avira says TR/Crypt.CFI.Gen is in bamse. To be sure, I downloaded bamse-0.9.5 from hackage today, and now avira says less specificly that there are some viruses and/or unwanted programs inside. Since I have some trojan trouble for a few days now, bamse might be the reason for that, but I am not sure. Maybe it is a false alarm, I can't determine this. (bamse is a framework for building Windows Installer, so it might contain code that looks like a virus or alike wrongly?) Does anybody know if this is really a virus/trojan? Best regards, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad Comprehensions
Hello Ryan, thank you for your email, it's much appreciated. In summary I'd like to say that in the 2 years that I have been using Haskell I have managed to get a good working knowledge of the language which allows me to construct programs that are concise, correct and without greater redundancy. However I also realize more and more that in order to harness the full power of Haskell I need to gain a greater understanding of the underlying math and go beyond mechanical application. It is only lately that I am recognizing the significance of the often used term abstraction. Certainly this is pointed out in the Haskell world often enough, but hey I'm a noob. For someone like me this is not immediately apparent. I mean there seems to be almost no end of what I still have to learn, barely scratching the surface, tip of the iceberg, that sort of thing. DSLs are apparently *the* way to go in the abstraction department. Oleg Co's Finally Tagless style is my favorite when it comes to implementation. It bears this simplicity and elegance that I have come to recognize and what to me *is* mathematical. Not all of my dealings in Haskell are goal-oriented. Well there is that of course, but mostly there are all these shiny beautiful things. I get distracted quite a lot too. Trying to dig deeper on the subject of Dan Piponis video for instance. BTW I found Phil Wadlers paper Comprehending Monads quite helpful here. I also find my focus of interest on the topics of articles on haskell-cafe shift. Before I would basically skip deep stuff, ie. theoretical / abstract topics, and focus on technical details. Now I focus much more on mathematical issues despite the fact that I can barely understand them, it'll come to me eventually. Because now I consider the mathematical discussions far more fundamental and more lasting. Technical details I can look up as the need arises and they will likely change over time, so no need to bother with them beforehand, they may be out-dated when you need them. Mathematical ones won't, they'll be good forever. Well that's my 2 cents for now. Günther Am 07.11.2009, 09:37 Uhr, schrieb Ryan Grant rgr...@rgrant.org: 2009/11/1 Günther Schmidt gue.schm...@web.de: In short, I'm truly lost. If anyone else, with roughly the same starting point as me, has found their way through this jungle I'd certainly appreciate some tips. In particular I wonder if someone has been able to follow what Dan demonstrates in this video, or was it a jaw-dropping experience for everyone else just as me? Günther, i have been lurking in H-cafe, and enjoying your pace of exploration. AFAIK, you are trying to understand how to make excellent languages using Haskell. you are asking some practical questions that i find relevant to my own journey into Haskell. best practices for specifying a DSL are not well agreed upon, partly due to recent advances. i sense this problem in your question and in the newsworthiness of Dan's talk, (which i also enjoyed with a jaw-drop). i encourage you to say exactly what you want from your DSL (do it again, if you have already). i hope to follow your footsteps, maybe not in exact DSL needs, but in path of discovery. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsing Haskell
The UHC compiler contains a combinator based Haskell parser from which you can borrow fragments, ... and the nhc98/yhc compiler likewise has a combinator parser for full Haskell'98 (the combinators are in applicative style). Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: virus/trojan in bamse package?
Am 07.11.2009, 16:28 Uhr, schrieb Daniel van den Eijkel d...@gmx.net: hi, my Avira antivirus program says that there is a trojan in the bamse-0.9.5 package. I downloaded the hackage-torrent a week ago, and Avira says TR/Crypt.CFI.Gen is in bamse. To be sure, I downloaded bamse-0.9.5 from hackage today, and now avira says less specificly that there are some viruses and/or unwanted programs inside. .Gen usually means that the file isn't a known virus but some heuristics triggered. This can also happen if a file is compressed with an executable packer that the virus scanner can't decompress, which wouldn't be strange for an installer tool. I don't know if that's the problem in this case but I had a lot of trouble with virus scanners in combination with executable packers so it might be. -- Jannis ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] WinGHCi stuck in a loop
L.S., I changed the options in WinGHCi and now WinGHCi is stuck in a loop each time I start it; how can I edit the options? I cannot find them in the registry. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Haskell as a first language?
Duncan Coutts wrote: On Tue, 2009-07-14 at 03:01 -0700, Michael Vanier wrote: Charles, Haskell is a wonderful language (my favorite language by far) but it is pretty difficult for a beginner. In fact, it is pretty difficult for anyone to learn in my experience, because it has so many advanced concepts that simply don't exist in other languages, and trying to absorb them all at once will likely be overwhelming. As a contrary data-point, at Oxford we teach functional programming (using Haskell) as the first course at the very beginning of the computer science degree. I know several other universities also use FP and Haskell very early on in their CS courses. At Minho we've been using Haskell as first programming course in CS degrees since 1997-98. Such a 'functional first' approach is the natural way to start a background on programming. Look at the hardware side, for instance: which of the following kinds of digital system is taught first: combinatorial (eg. nand, nor gates) or sequential (eg. flip-flops)? The first, of course, because such circuits are functional (no state, no feedback). More recently I had a go at teaching Haskell to beginners in a non CS context (to arts students studying musicology, actually). If you are interested, have a look at the slides available from the course's URL: www.di.uminho.pt/~jno/html/ipm.html#sec:mp (Under Acrobat some scores will start playing music once you click the pin symbol on the right.) All comments, suggestions etc are welcome. jno ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Card games
On Sat, Nov 7, 2009 at 8:07 AM, Felipe Lessa felipe.le...@gmail.com wrote: On Sat, Nov 07, 2009 at 08:46:07AM -0500, Matthias Görgens wrote: Interesting idea. But I guess you should clarify what kind of card games you want to support. E.g, a DSL for trick taking games like Bridge, Skat or Doppelkopf might be different from one that's good for Canasta or Rummy. Or do you aim at Solitaire? I'd suggest starting with a very small scope of the domain for a very first version. Hmm, good catch. I was thinking about solitaire, i.e. single player, games. Multiplayer card games certainly have their own set of interesting challenges. If I ever get to develop something capable of expressing nicely Patience, Spider, Pyramid and Black Hole I'll be more than satisfied :). I'd be interested in something which could model games of Dominion [1], as it's my current addiction; it's a (non-collectable) card game where you build and tune your deck as you play, and aside from money and victory point cards (which are always available) randomly has available ten possible action card types to buy each game (out of the total set of action card types — 76, as of the latest expansion). There have already been various basic analyses of various possible strategies assuming simple rules; if a strategy can't beat the baseline strategy Big Money (which involves buying nothing but money and victory points the entire game), it should probably be scrapped. [1] http://www.boardgamegeek.com/boardgame/36218 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] ANNOUNCE: control-monad-exception 0.5 with monadic call traces
When using happstack, I find it really annoying to get a Prelude.head: null list error (or similar) in my web browser window because somewhere, some library used something unsafe -- and of course, since this is haskell, no stack trace. if c-m-e can offer benefits around this, I would be very interested in adopting it. That's what I meant with my post: Programming errors (like head []) are not handled by control-monad-exception. As far as I understand, control-monad-exception makes _exceptions_ explicit in the type signatures, not programming errors. Why and how would you make possible programming errors explicit in the type? But for exceptions (e.g. file could not be found) a detailed stack trace is not of much use. It seems again to me, that mixing of (programming) errors and exceptions is going on, and I assumed that the purpose of control-monad-exception is to separate them in a better way. Sorry for the confusion, I never meant that c-m-e can show stack traces for asynchronous exceptions. It can not. I used the head of empty list error to draw a simile of why you would like to have a stack trace. I do not share your opinion that monadic call traces are not of much use. Your example looks a bit conspicuous to me. Consider a web application using HDBC to interface with a database, where a SQLError can arise and there is no way to find out where it is coming from. The safe-failure package (not officially released yet, but an early version is available in Hackage) provides monadic versions of several partial functions in the Prelude. An applicative interface is available which can make programming with those much more palatable. That means you can in effect obtain a stack trace for a head of empty list error. I would like, as much as anyone else, to see stack traces available for pure Haskell code. There are others already pursuing that goal, but as the situation stands now, stack traces are available only through expensive program transformations which cannot be used in production code. And I don't believe that situation is going to change in the close future. In contrast, monadic call traces have a simple implementation model by extending the bind operation with source locations. They are available now through the MonadLoc preprocessor which is not tied in any way to c-m-e. And moreover, they are unexpensive, can be used in production code, and can make your life much easier in many, many cases. I'm not sure if I managed to dispel your doubts, if not perhaps you could make your points more clear. Thanks, pepe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Master's thesis topic sought
On Pi, 2009-11-06 at 17:25 -0500, Brent Yorgey wrote: On Fri, Nov 06, 2009 at 03:29:47PM +, Stephen Tetley wrote: Hello all, Are any of the of the more exotic recursion schemes definable without a least-fixed point /Mu/ type? Note that Haskell datatypes have a built-in implicit mu (that is, I'd say Mu gets you a greatest-fixed point. I don't have a proof, I just note that Mu(ΛX. 1 + A x X) contains infinite lists, too. I wonder whether this is a problem; if I want to define an initial algebra of a functor, I should take a least fixed point (if I understand it correctly) -- but all I have is Mu. Inductively defined functions will loop on infinite lists, which are included in the resulting type, and -- i imagine -- the type system might prevent such errors, by not enabling casting from greatest-Mu(F) to least-Mu(F). But that's probably too restrictive to be useful. Anyway, is there a possibility to restrict Mu to a least-fixed-point operator? Matus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Names for properties of operators
Hi, We have names for properties of operators/functions. For example, if this holds: a % b = b % a for some operator %, we say that % is commutative. Similarly, if this holds: (a % b) % c = a % (b % c) we say that % is associative. Is there a name for this property, which I'm numbering 1, (where (%) :: a - b - b; i.e. the operator is potentially, but not necessarily, asymmetrically typed): 1: a % (b % c) = b % (a % c) For example, `Set.insert` obeys 1 for any values of a, b and c. (Any operator that is both associative and commutative automatically satisfies this property, but this property can be satisfied without the operator being either of those.) Given this property, we could prove useful follow-on results, such as: foldr (%) x ys = foldr (%) x (reverse ys) foldr (%) x ys = foldl (flip (%)) x ys The property 1 effectively states that the far-right hand element in a chain of such operators is special, but the ordering of everything to the left of it doesn't matter. One could conceive of a mirror property (where (%) :: a - b - a): 2: (a % b) % c = (a % c) % b If (%) obeys 1, flip (%) obeys 2 (and vice versa). I think these properties are useful -- I'd like to know if they have names already to describe them by. A similar property of two relations (where ((%), (~)) :: (a - b - b, c - b - b) ) would be: 3: a % (b ~ c) = b ~ (a % c) with mirror version (and adjusted types): 4: (a % b) ~ c = (a ~ c) % b Do these have a name? As an example, `Set.insert` and `Set.union` obey property 3 for all values of a, b and c. There are also symmetrically-typed examples of these operators, but the Set operations are easy and familiar. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Fwd: [Haskell-cafe] Is () a 0-length tuple?
The syntax is similar, but what else is? In JavaScript there is a null value, that is the only value of the null type. Isn't () the same thing? The only value of the unary type? Best, titto 2009/11/6 John Dorsey hask...@colquitt.org: In what sense () is a 0-length tuple? In what sense isn't it? Data.Tuple is much to narrow to be of any use here. () is in at least most, if not all, of the type classes that tuples are in. The syntax is strikingly similar. If you ask me, it walks/quacks/smells like a duck, so it's a duck. Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Pasqualino Titto Assini, Ph.D. http://quicquid.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is () a 0-length tuple?
2009/11/7 Pasqualino Titto Assini tittoass...@gmail.com: The syntax is similar, but what else is? In JavaScript there is a null value, that is the only value of the null type. Isn't () the same thing? The only value of the unary type? No, () has two values: () and undefined (t.i., _|_). Best, titto 2009/11/6 John Dorsey hask...@colquitt.org: In what sense () is a 0-length tuple? In what sense isn't it? Data.Tuple is much to narrow to be of any use here. () is in at least most, if not all, of the type classes that tuples are in. The syntax is strikingly similar. If you ask me, it walks/quacks/smells like a duck, so it's a duck. Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Pasqualino Titto Assini, Ph.D. http://quicquid.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is () a 0-length tuple?
Forgot to cc haskell-cafe. Trying again: -- Forwarded message -- From: Matthew Gruen wikigraceno...@gmail.com Date: Sat, Nov 7, 2009 at 2:16 PM Subject: Re: [Haskell-cafe] Is () a 0-length tuple? To: Pasqualino Titto Assini tittoass...@gmail.com On Sat, Nov 7, 2009 at 2:00 PM, Pasqualino Titto Assini tittoass...@gmail.com wrote: The syntax is similar, but what else is? In JavaScript there is a null value, that is the only value of the null type. Isn't () the same thing? The only value of the unary type? Best, titto Pasqualino Titto Assini, Ph.D. http://quicquid.org/ In JavaScript's case, there is not a null type. The null value belongs to the 'object' type, whereas the undefined value belongs to the 'undefined' type. This is all a lot less useful when you realize that JavaScript has a dynamic type system. But this is JSON, not JavaScript. In JSON, arrays, objects, strings, and numbers can be any number of values. Booleans can be two values. Null can only be one value. Personally, I think a better mapping for () would be JSNull, since both have only one value in normal form. However, there is not necessarily any natural mapping between Haskell values and JSON values. The library tries to provide as many as possible, including (), which it happens to map to JSArray [] instead of JSNull. As long as the library is internally consistent, though, it should be fine. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] ANNOUNCE: control-monad-exception 0.5 with monadic call traces
On Sat, 7 Nov 2009, Jose Iborra wrote: Sorry for the confusion, I never meant that c-m-e can show stack traces for asynchronous exceptions. It can not. My post was not related in any way to asynchronous exceptions. It's just the everlasting issue of the distinction of programming errors and exceptions. I'm not sure if I managed to dispel your doubts, if not perhaps you could make your points more clear. I'm trying that for years now, repeatedly in this mailing list and on the Wiki: http://www.haskell.org/haskellwiki/Error http://www.haskell.org/haskellwiki/Exception I don't know how I can make it still clearer. It's just like concurrency vs. parallelism - somehow related, but it is important to distinguish them. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Master's thesis topic sought
Matus Tejiscak wrote: On Pi, 2009-11-06 at 17:25 -0500, Brent Yorgey wrote: On Fri, Nov 06, 2009 at 03:29:47PM +, Stephen Tetley wrote: Hello all, Are any of the of the more exotic recursion schemes definable without a least-fixed point /Mu/ type? Note that Haskell datatypes have a built-in implicit mu (that is, I'd say Mu gets you a greatest-fixed point. I don't have a proof, I just note that Mu(ΛX. 1 + A x X) contains infinite lists, too. Mu is the notation for least-fixed, Nu is the notation for greatest-fixed. In Haskell, the two fixed points coincide due to laziness and _|_. I wonder whether this is a problem; if I want to define an initial algebra of a functor, I should take a least fixed point (if I understand it correctly) -- but all I have is Mu. Inductively defined functions will loop on infinite lists, which are included in the resulting type, and -- i imagine -- the type system might prevent such errors, by not enabling casting from greatest-Mu(F) to least-Mu(F). But that's probably too restrictive to be useful. If you want the type system to catch infinite looping like this, then you'll need to switch to a total functional programming language which distinguishes data and codata (and hence what can be inducted on vs what needs to be coinducted on). -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] help with Haskell performance
Hi all, The task I'm trying to accomplish: Given a log file containing several lines of white space delimited entries like this: [Sat Oct 24 08:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist [Sat Oct 24 08:12:37 2009] [error] GET /url2 HTTP/1.0]: Requested URI does not exist [Sat Oct 24 08:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist [Sat Oct 24 12:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist filter lines that match the string 08:, extract the 6th, 7th and 8th words from that line, group all lines that have the the same resulting string, do a count on them and sort the result in descending order of counts and print it out. So in the example above we'd end up with an output like this: (GET /url1 HTTP/1.1]:, 2) (GET /url2 HTTP/1.0]:, 1) Seems pretty straightforward, so I wrote a simple perl script to achieve this task (see the bottom of this email). The input file is 335 MB in size and contains about 2 million log line entires in it. The perl script does a pretty decent job and finishes in about 3 seconds. Now the interesting part. I decided to implememt this in Haskell (being my favorite language and all) and ended up with the following code: --- begin haskell code --- import Text.Regex.Posix ( (=~) ) import qualified Data.List as List import qualified Data.Map as Map import qualified Data.ByteString.Lazy.Char8 as LB main = do contents - LB.readFile log_file putStr . unlines . map ( show . (\(x, y) - ((LB.unpack x), y)) ) . -- create a Map grouping counting matching tokens and sort based on the counts List.sortBy (\(_, x) (_, y) - y `compare` x) . Map.toList . Map.fromListWith (+) . filtertokens . LB.lines $ contents where filtertokens = foldr (\x acc - if (f x) then ((g x) : acc) else acc) [] -- filter lines starting with 08: where f = (=~ 08:) . LB.unpack -- extract tokens 6, 7 8 and create an association list like so (GET /url2 HTTP/1.0]:, 1) g line = flip (,) 1 . LB.unwords . map (xs !!) $ [6, 7, 8] where xs = LB.words line --- end haskell code --- This haskell implementation takes a whopping 27 seconds to complete! About 9 times slower than the perl version! I'm using ghc 6.10.4, compiling with -O2 and even went to the extent of fusing an adjacent map and filter using a foldr like so: map f (filter g) = foldr ( if g x then f x ... ), fusing adjacents maps etc. Still the same result. I really hope I'm missing some obvious optimization that's making it so slow compared to the perl version, hence this email soliciting feedback. Thanks in advance. P.S. For reference, here's my corresponding perl implementation: --- start perl code --- #!/usr/bin/perl use strict; use warnings FATAL = 'all'; my %urls; open(FILE, '', $ARGV[0]); while(FILE) { if (/ 08:/) { my @words = split; my $key = join( , ($words[6], $words[7], $words[8])); if (exists $urls{$key}) { $urls{$key}++ } else { $urls{$key} = 1 } } } for (sort { $urls{$b} = $urls{$a} } keys %urls) { print ($_, $urls{$_})\n } --- end perl code --- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with Haskell performance
2009/11/8 Gokul P. Nair gpnai...@yahoo.com Hi all, The task I'm trying to accomplish: Given a log file containing several lines of white space delimited entries like this: [Sat Oct 24 08:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist [Sat Oct 24 08:12:37 2009] [error] GET /url2 HTTP/1.0]: Requested URI does not exist [Sat Oct 24 08:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist [Sat Oct 24 12:12:37 2009] [error] GET /url1 HTTP/1.1]: Requested URI does not exist filter lines that match the string 08:, extract the 6th, 7th and 8th words from that line, group all lines that have the the same resulting string, do a count on them and sort the result in descending order of counts and print it out. So in the example above we'd end up with an output like this: (GET /url1 HTTP/1.1]:, 2) (GET /url2 HTTP/1.0]:, 1) Seems pretty straightforward, so I wrote a simple perl script to achieve this task (see the bottom of this email). The input file is 335 MB in size and contains about 2 million log line entires in it. The perl script does a pretty decent job and finishes in about 3 seconds. Now the interesting part. I decided to implememt this in Haskell (being my favorite language and all) and ended up with the following code: --- begin haskell code --- import Text.Regex.Posix ( (=~) ) First, you are using Text.Regex.Posix which is dog slow. Use regex-tdfa or regex-pcre. Second, you are using it on a String! Third, you are unpacking a lazy bytestring for that! This alone is more than enough to make things ridiculously slow. import qualified Data.List as List import qualified Data.Map as Map import qualified Data.ByteString.Lazy.Char8 as LB main = do contents - LB.readFile log_file putStr . unlines . map ( show . (\(x, y) - ((LB.unpack x), y)) ) . This piece of code also does unpacking. If the output is small, it's ok, otherwise assemble output in the form of a bytestring and print it with B.putStr. -- create a Map grouping counting matching tokens and sort based on the counts List.sortBy (\(_, x) (_, y) - y `compare` x) . Map.toList . Map.fromListWith (+) . filtertokens . The lambda can be replaced by flip (comparing snd) LB.lines $ contents Here, you should not use Map.fromListWith (+) because Map is not strict in its entries and you end up having big fat thunks there. You should use Map.fromListWith plus where x `plus` y = x `seq` y `seq` x+y. where filtertokens = foldr (\x acc - if (f x) then ((g x) : acc) else acc) [] -- filter lines starting with 08: where f = (=~ 08:) . LB.unpack -- extract tokens 6, 7 8 and create an association list like so (GET /url2 HTTP/1.0]:, 1) g line = flip (,) 1 . LB.unwords . map (xs !!) $ [6, 7, 8] where xs = LB.words line You are using random access on a list three times in a row. map (xs!!) [6,7,8] is much faster when implemented as take 3 (drop 6 xs). So.. Well. Try these suggestions, show the resulting performance and then we'll see. --- end haskell code --- This haskell implementation takes a whopping 27 seconds to complete! About 9 times slower than the perl version! I'm using ghc 6.10.4, compiling with -O2 and even went to the extent of fusing an adjacent map and filter using a foldr like so: map f (filter g) = foldr ( if g x then f x ... ), fusing adjacents maps etc. Still the same result. I really hope I'm missing some obvious optimization that's making it so slow compared to the perl version, hence this email soliciting feedback. Thanks in advance. P.S. For reference, here's my corresponding perl implementation: --- start perl code --- #!/usr/bin/perl use strict; use warnings FATAL = 'all'; my %urls; open(FILE, '', $ARGV[0]); while(FILE) { if (/ 08:/) { my @words = split; my $key = join( , ($words[6], $words[7], $words[8])); if (exists $urls{$key}) { $urls{$key}++ } else { $urls{$key} = 1 } } } for (sort { $urls{$b} = $urls{$a} } keys %urls) { print ($_, $urls{$_})\n } --- end perl code --- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with Haskell performance
On Sun, Nov 08, 2009 at 12:15:57AM +0300, Eugene Kirpichov wrote: Here, you should not use Map.fromListWith (+) because Map is not strict in its entries and you end up having big fat thunks there. You should use Map.fromListWith plus where x `plus` y = x `seq` y `seq` x+y. fromListWith is implemented with insertWithKey; is defining plus like above enough? I would guess that we need fromListWith' implemented with insertWithKey'. The problem is that it will build a thunk (x `plus` y) and your seq's only say that whenever you evaluate that thunk you'll evaluate the arguments as well. If the thunk itself isn't needed, it won't be evaluated. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with Haskell performance
gpnair78: I really hope I'm missing some obvious optimization that's making it so slow compared to the perl version, hence this email soliciting feedback. Here's my first attempt. 1.5s on a 2M line log file in the format you give. General notes: * unpack is almost always wrong. * list indexing with !! is almost always wrong. * words/lines are often wrong for parsing large files (they build large list structures). * toList/fromList probably aren't the best strategy * sortBy (comparing snd) * use insertWith' Spefically, avoid constructing intermediate lists, when you can process the entire file in a single pass. Use O(1) bytestring substring operations like take and drop. Compiling: $ ghc -O2 /tmp/B.hs --make Running: $ time /tmp/B (GET /url1 HTTP/1.1],100) (GET /url2 HTTP/1.0],50) /tmp/B 1.38s user 0.21s system 99% cpu 1.595 total And the code: {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} import qualified Data.ByteString.Char8 as L import qualified Data.Map as M main = do l - L.readFile /tmp/x mapM_ print . M.toList $ go l M.empty where go !s !acc | L.null s = acc | 08: `L.isPrefixOf` s1 = go s4 acc' | otherwise= go s4 acc where s1 = L.drop 11 s-- drop prefix to timestamp -- now extract the key (_,s2) = L.breakSubstring GET s1 (k,s3) = L.break ((==) ':') s2 -- drop the rest of the line s4 = L.tail (L.dropWhile ((/=) '\n') s3) acc' = M.insertWith' (+) k 1 acc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with Haskell performance
Ah, you're right. Then we need a foldl' insertWith with a strict plus. 2009/11/8 Felipe Lessa felipe.le...@gmail.com: On Sun, Nov 08, 2009 at 12:15:57AM +0300, Eugene Kirpichov wrote: Here, you should not use Map.fromListWith (+) because Map is not strict in its entries and you end up having big fat thunks there. You should use Map.fromListWith plus where x `plus` y = x `seq` y `seq` x+y. fromListWith is implemented with insertWithKey; is defining plus like above enough? I would guess that we need fromListWith' implemented with insertWithKey'. The problem is that it will build a thunk (x `plus` y) and your seq's only say that whenever you evaluate that thunk you'll evaluate the arguments as well. If the thunk itself isn't needed, it won't be evaluated. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: control-monad-exception 0.5 with monadic call traces
On Sat, Nov 7, 2009 at 9:54 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Sat, 7 Nov 2009, Jose Iborra wrote: Sorry for the confusion, I never meant that c-m-e can show stack traces for asynchronous exceptions. It can not. My post was not related in any way to asynchronous exceptions. It's just the everlasting issue of the distinction of programming errors and exceptions. I'm not sure if I managed to dispel your doubts, if not perhaps you could make your points more clear. I'm trying that for years now, repeatedly in this mailing list and on the Wiki: http://www.haskell.org/haskellwiki/Error http://www.haskell.org/haskellwiki/Exception I don't know how I can make it still clearer. It's just like concurrency vs. parallelism - somehow related, but it is important to distinguish them. And yet if I use library ABC, which I expected to be error-free, and it in fact has a programming error, is this an error or an exception from my point of view? Based on the definitions you posted, I believe the correct answer is error. However, I'd much rather have a way to recover from that kind of error if it's logical. For example, let's say that I'm writing a web browser in Haskell (it could happen). If there's an error in the HTTP library which causes it to die on certain types of headers, I'd much rather be able to tell the user sorry and let them continue browsing than to up and die with a Prelude.head message in their console. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with Haskell performance
2009/11/7 Eugene Kirpichov ekirpic...@gmail.com: Ah, you're right. Then we need a foldl' insertWith with a strict plus. We only need a foldl' insertWith' : (+) is already strict for all the numeric types in the Prelude. -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Small Japi binding for GHC
JAPI is by far my favorite GUI library. Since every machine has Java RE installed, JAPI offers GUI with a very small footprint. Besides this, it is very easy to code, and delivers GUI programs that are hardly larger than console applications. I use Jorlano's version of JAPI, coded for Java 2, which is very cool. I study Computer Science in a small college, and I always handle my homework in JAPI. When I took functional programming one year ago, the language chosen by Professor Lopes was Clean, that has a GUI. However, I feel that JAPI is much easier than ObjectIO; therefore, I used JAPI for my homework. So, I searched for JAPI bindings for Haskell. The only library I found was something called Small Japi binding for GHC. The package is incomplete, and bug ridden. I wonder whether the author fixed the bugs, completed the package, and added more examples. I would appreciate if people could send me links to a complete Japi binding for GHC. In the mean time, I fixed the bugs of Small Japi Binding, and added a few important components (j_textfield, j_settext, j_gettext, j_button, etc.) Of course, a link to a more recent version of the official binding will save me a lot of work. __ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: What's the deal with Clean?
John van Groningen johnvg at cs.ru.nl writes: Doaitse Swierstra wrote: One of this differences between Haskell and Clean I did not see mentioned in this discussion is that Clean does not allow so-called partial parametrisation. I.e. all function calls have to be fully saturated I don't understand what you mean. Can you give an example ? Kind regards, John van Groningen I think the idea was that Clean doesn't support a syntax like map (**2) for a function that will take a list and square its elements. The call to map there is not fully saturated, since it's waiting for another argument. (As a disclaimer, I've not used Clean, so I could be speaking nonsense; it's just how I read the original statement.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Names for properties of operators
1. and 2. are called left- and right-commutative. And I think that 3. and 4. are left- and right-commutative rings (please correct me if I'm wrong here). Cheers, Thomas 2009/11/7 Neil Brown nc...@kent.ac.uk: Hi, We have names for properties of operators/functions. For example, if this holds: a % b = b % a for some operator %, we say that % is commutative. Similarly, if this holds: (a % b) % c = a % (b % c) we say that % is associative. Is there a name for this property, which I'm numbering 1, (where (%) :: a - b - b; i.e. the operator is potentially, but not necessarily, asymmetrically typed): 1: a % (b % c) = b % (a % c) For example, `Set.insert` obeys 1 for any values of a, b and c. (Any operator that is both associative and commutative automatically satisfies this property, but this property can be satisfied without the operator being either of those.) Given this property, we could prove useful follow-on results, such as: foldr (%) x ys = foldr (%) x (reverse ys) foldr (%) x ys = foldl (flip (%)) x ys The property 1 effectively states that the far-right hand element in a chain of such operators is special, but the ordering of everything to the left of it doesn't matter. One could conceive of a mirror property (where (%) :: a - b - a): 2: (a % b) % c = (a % c) % b If (%) obeys 1, flip (%) obeys 2 (and vice versa). I think these properties are useful -- I'd like to know if they have names already to describe them by. A similar property of two relations (where ((%), (~)) :: (a - b - b, c - b - b) ) would be: 3: a % (b ~ c) = b ~ (a % c) with mirror version (and adjusted types): 4: (a % b) ~ c = (a ~ c) % b Do these have a name? As an example, `Set.insert` and `Set.union` obey property 3 for all values of a, b and c. There are also symmetrically-typed examples of these operators, but the Set operations are easy and familiar. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Names for properties of operators
No, they aren't rings, because rings are distributive... 2009/11/8 Thomas Danecker tdanec...@gmail.com: 1. and 2. are called left- and right-commutative. And I think that 3. and 4. are left- and right-commutative rings (please correct me if I'm wrong here). Cheers, Thomas 2009/11/7 Neil Brown nc...@kent.ac.uk: Hi, We have names for properties of operators/functions. For example, if this holds: a % b = b % a for some operator %, we say that % is commutative. Similarly, if this holds: (a % b) % c = a % (b % c) we say that % is associative. Is there a name for this property, which I'm numbering 1, (where (%) :: a - b - b; i.e. the operator is potentially, but not necessarily, asymmetrically typed): 1: a % (b % c) = b % (a % c) For example, `Set.insert` obeys 1 for any values of a, b and c. (Any operator that is both associative and commutative automatically satisfies this property, but this property can be satisfied without the operator being either of those.) Given this property, we could prove useful follow-on results, such as: foldr (%) x ys = foldr (%) x (reverse ys) foldr (%) x ys = foldl (flip (%)) x ys The property 1 effectively states that the far-right hand element in a chain of such operators is special, but the ordering of everything to the left of it doesn't matter. One could conceive of a mirror property (where (%) :: a - b - a): 2: (a % b) % c = (a % c) % b If (%) obeys 1, flip (%) obeys 2 (and vice versa). I think these properties are useful -- I'd like to know if they have names already to describe them by. A similar property of two relations (where ((%), (~)) :: (a - b - b, c - b - b) ) would be: 3: a % (b ~ c) = b ~ (a % c) with mirror version (and adjusted types): 4: (a % b) ~ c = (a ~ c) % b Do these have a name? As an example, `Set.insert` and `Set.union` obey property 3 for all values of a, b and c. There are also symmetrically-typed examples of these operators, but the Set operations are easy and familiar. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Names for properties of operators
Hi Neil, You wrote: [...] Is there a name for this property, which I'm numbering 1, (where (%) :: a - b - b; i.e. the operator is potentially, but not necessarily, asymmetrically typed): 1: a % (b % c) = b % (a % c) I don't know any snappy names for this, but the following might help to reveal some structure. Pick some specific (but arbitrary) types: (%) :: A - B - B And some values: x, y :: A z :: B f, g :: B - B f = (x%) g = (y%) Then: x % (y % z) == f (g z) == (f . g) z y % (x % z) == g (f z) == (g . f) z So (%) has property 1 iff the sub-monoid of Endo [1], which is generated by Endo (x%) forall x :: A, is commutative. Property 3 is the same, but with a larger generator set. Note that in your examples, the sub-monoid generated by insert+union is just the same as that generated by insert alone (assuming no infinite sets). This particular sub-monoid also happens to be a bounded join-semilattice (isomorphic to the finite subsets of A), which also makes it idempotent. Regards, Matthew [1]http://haskell.org/ghc/docs/latest/html/libraries/base/src/Data-Monoid.html#Endo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Nice addition to Foreign: castAny
castAny :: (Storable a, Storable b) = a - b castAny = unsafePerformIO . genericCast where genericCast :: (Storable a, Storable b) = a - IO b genericCast v = return undefined = \r - allocaBytes (max (sizeOf v) (sizeOf r)) $ \p - poke p v if False then return r else peek (castPtr p) let a = -1000 :: Int16 castAny a :: Word16 -- 64536 castAny a :: Ptr () 0xb4c2fc18 Try it on a big endian architecture, or one that has alignment restrictions, or a different size for HsChar or so forth. Casting by 'punning' (as the C folks like to call it) does have uses, but they are generally hardware dependent and useful only in certain rare circumstances that a generic cast probably isn't likely to fill. Do you think this could be used as a way to handle C unions? If I had something like union example { struct firstview { char c; int n; } fv; long double ld; }; and 'firstview' had been mapped in Haskell as, say, FirstView {firstViewC :: CChar, firstVewN :: CInt} I could check what I would get after pokeing values using: (firstViewN . unionCast) (pi :: CDouble) Note that I changed the name from castAny to unionCast to reflect its use. Thanks for your comments, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe