Re: [Haskell-cafe] pure crisis :)
Bulat Ziganshin wrote: Hello haskell-cafe, pure functional denotation for crisis: (_|_) Buy ⊥, sell ⊤! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] PRE-ANNOUNCE: cabal-debian (automatically debianize cabal packages)
Ketil Malde wrote: Christopher Lane Hinson <[EMAIL PROTECTED]> writes: Having a debianized cabal-install would be the biggest win in my book. If there were an unofficial debianized mirror of hackage, I probably wouldn't use it anyway. I might. I would. (I run Ubuntu at home, Debian on my personal mail/web server, and Debian at work.) I'd rather have all my software maintained by the distro's package-management system (if I can do it and still have access to the most recent versions). One of the things that made me tear my hair out when I first tried to learn Plone was that my Plone book, the Plone website, and Ubuntu all recommended different systems for installing Plone and all its dependencies, and IIRC they defaulted to different versions as well. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda and closures in PHP -- could someone please comment?
PR Stanley wrote: Blimey! Talk about rearranging the deckchairs :-) Today's xkcd seems apropos: http://xkcd.com/438/ It seems to me that if a PHP developer sees the Haskell community as a resource for advice on programming language implementation, we should take this as a compliment to the Haskell community. Repaying that compliment with "your language sucks rocks" strikes me as unwise. I'm familiar with a lot of arguments for why PHP is a poorly-designed language, and have found them sufficiently persuasive that I haven't bothered to learn PHP. But I don't see any point to repeating those arguments on this list. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Well-Typed LLP - The Haskell Consultants
Ian Lynagh wrote: Fellow Haskellers, We (Björn Bringert, Duncan Coutts and Ian Lynagh) are pleased to announce that we have recently set up a Haskell consultancy company, Well-Typed LLP (http://www.well-typed.com/). Congratulations! Do you have a plan to market your services to people who might be interested in, say, natural-language processing technology, but who have no particular interest in Haskell? Or do you have clients and potential clients that are specifically looking for Haskell programmers? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: US Homeland Security program language security risks
Daniel Fischer wrote: Am Sonntag, 6. Januar 2008 15:54 schrieb Achim Schneider: That's an interesting task: Design a non-touring complete, restricted language in which every expression is decidable, without making the language unusable for usual programming problems. I'm not a logician, but didn't Gödel prove that you couldn't express the (full) arithmetic of natural numbers in such a language? What if you restricted yourself to the arithmetic of natural numbers modulo 2^64? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why are OCaml and Haskell being used at these companies?
Jon Harrop wrote: When functional languages achieve these goals I believe the total number of users will increase dramatically as scientists and engineers adopt them alongside their standard tools. Bioinformaticians are among the first to adopt functional programming languages but I believe more mainstream natural sciences will follow. FWIW, a few years ago, when I was stubbornly unemployed[*], I wrangled a fifteen-minute informational interview with Kenan Sahin[**]. He advised me to look for work related to medical devices, on the grounds that as the US population got older there would be greater and greater demand for medical equipment, and software is becoming a more and more important component of these devices. [*] I had been working for Whitehead on the Human Genome Project, thinking that an academic job would be the perfect place to ride out the dot-com crash. Then they finished sequencing the human genome and didn't need so many programmers. So much for academic job security. [**] Sahin had founded of a company that I had worked for, which he had sold to Lucent for 1.5 gigabucks shortly *before* the dot-com crash. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Best Linux for Haskell?
Peter Verswyvelen wrote: Each year I give Linux a try. And usually I kick it off my harddrive after a month, and stick to Windows. However, it does get better each year, so… So which kind Linux works best for running GHC (6.8.1) and related tools? (I want to give Yi a go, I can’t get it to work on Windows). Debian? Fedora? Ubuntu? I don't know which Linux distribution is best *for Haskell*, but in my experience, Ubuntu has been the best distribution for getting up and running on Linux without fuss. The latest version lets you boot into Linux from a CD-ROM, so you can try it out and confirm that all your hardware is compatible before you touch anything on your hard drive. I haven't tried 6.8.1 yet, but I have downloaded and used the 6.6.x binaries on an Ubuntu system back when the repositories were still using an earlier version. I strongly suspect that if you got hold of 6.8.1 packages that were built for Debian, they would also install on Ubuntu, but I haven't tried doing that yet. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New slogan for haskell.org
Aha! Instead of the lambda surrounded by mathematical stuff as the haskell.org logo, we need a picture of a medicine bottle. "Haskell. Fewer headaches. No side effects." Alternatively, a picture of a red pill with an embossed lambda... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New slogan for haskell.org
"Nervous? Anxious? You found an irreproducable bug in your program and have to fix it until tomorrow? You feel that your code needs essential cleanup, but you postponed it for long in order to not introduce new bugs? You can hardly maintain the code as it grows and grows? Pause a minute! Maybe we can help. Try Haskell. Its effect is immediate and long-lasting. There are warrantedly no side effects. It's scientifically approved. Available without prescription." Aha! Instead of the lambda surrounded by mathematical stuff as the haskell.org logo, we need a picture of a medicine bottle. "Haskell. Fewer headaches. No side effects." ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New slogan for haskell.org
Henning Thielemann wrote: In my experience only the other way round works: Let people use C, Perl and Python until they find their programs unmaintainable. Then they will become interested in style and discipline and programming languages which _support_ good style. Perhaps this could be the kernel of a slogan: "If you're having trouble maintaining your code because ..., perhaps you should try Haskell." ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Pierce on type theory and category theory
Are Benjamin C. Pierce's _Types and Programming Languages_ and/or _Basic Category Theory for Computer Scientists_ suitable for self-study? (Do they have problem sets that can be checked by either looking up answers in The Back of the Book, or by trying to compile/run some code that the student writes?) FWIW, my formal math education--well, all the formal math education that I can remember at this point--stopped at freshman calculus plus one semester of statistics. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Shouldnt this be lazy too?
Vimal wrote: Hi all, I was surprised to find out that the following piece of code: length [1..] > 10 isnt lazily evaluated! I wouldnt expect this to be a bug, but in this case, shouldnt the computation end when the length function evaluation goes something like: 10 + length [11..] I suspect that > when defined on integers is strict in both arguments, i.e., defined to not be lazily evaluated. Even if it's not, when the reduction gets as far as "11 + length [12..] > 10", *we* are smart enough to break apart the left-hand argument to (>) and inspect the arguments to (+), observe that "length" will never return a negative value, and concluded that we can stop evaluating. But the implementation of (>) is not so smart. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] Math behind Haskell
I'm spending my Copious Free Time going through the Graham/Knuth/Patashnik _Concrete Mathematics_ textbook. This is the textbook used at one of Stanford's "on-beyond-calculus math for CS majors" classes. If nothing else, the discipline of doing the homework problems at the end of each chapter is good exercise for the little gray cells. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
Dougal Stanton wrote: On 12/09/2007, Seth Gordon <[EMAIL PROTECTED]> wrote: I � Unicode. Was it intentional that the central character appears as a little '?', even though the aleph on the line above worked? It was intentional. If I ♡ed Unicode, I would have said so. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
Andrea Rossato wrote: What puzzles me is the behavior of putStrLn. putStrLn is sending the following bytes to standard output: 97, 98, 195, 168, 195, 168, 195, 168, 10 Since the code that renders characters in your terminal emulator is expecting UTF-8[*], each (195, 168) pair of bytes is rendered as "è". The Unix utility "od" can be very helpful in figuring out problems like this. [*]At least on my computer, I get the same result *even if* I change "LANG" from "en_US.utf8" to "C". ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
Andrea Rossato wrote: Hi, supposed that, in a Linux system, in an utf-8 locale, you create a file with non ascii characters. For instance: touch abèèè Now, I would expect that the output of a shell command such as "ls ab*" would be a string/list of 5 chars. Instead I find it to be a list of 8 chars...;-) The file name may have five *characters*, but if it's encoded as UTF-8, then it has eight *bytes*. It appears that in spite of the locale definition, hGetContents is treating each byte as a separate character without translating the multi-byte sequences *from* UTF-8, and then putStrLn sends each of those bytes to standard output without translating the non-ASCII characters *to* UTF-8. So the second line of your program's output is correct...but only by accident. Futzing around a little bit in ghci, I see that I can define a string "\1488", but if I send that string to putStrLn, I get nothing, when I should get א (the Hebrew letter aleph). I � Unicode. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Explaining monads
Sebastian Sylvan wrote: On 14/08/07, Dan Piponi <[EMAIL PROTECTED]> wrote: If I was one of your students and you said that monads are recipes I would immediately ask you where the monads are in my factorial program regardless of whether you had introduced one or two different analogies for recipes. Why would you? I really don't see where you would get that idea? If I tell you that a function returns "a fruit", would you ask where the fruit in your factorial program is? Probably not. Why would you go off and take an analogy for monads and apply it to something completely different and still think the analogy holds? A function is *not* a recipe in this analogy, it's just a function (which you hopefully should've covered by the time you get to monads. Monadic values, and *only* monadic values (not functions!) are to be viewed as analogous to real world cooking recipes in this analogy. Functions shouldn't. If you start mixing things together it will get confused, so just don't! As a mostly-newbie who is working on his own monad tutorial (bwah-hah-hah), I share Dan's confusion about your analogy. Teacher: "Monads are like recipes." Student: "Aren't functions like recipes, too?" Teacher: "Well, yes, but we're talking about monads now, not functions." That response doesn't help the student, because the student already knows about functions, and would probably understand monads a lot better if he or she knew how monads are *different from* functions. (Especially since, umm, isn't the ((->) a) data type a monad?) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad Description For Imperative Programmer
Kim-Ee Yeoh wrote: Seth Gordon wrote: Functors are a generalization from lists to "things that can be mapped over" in general, and then monads are a generalization of functors. Way to go! That way lies true co/monadic enlightenment. I feel like I still don't understand comonads. Maybe I just need a Zen comaster to hit me with a costick and then I'll become coenlightened. Haskell solves the "how can I do I/O in a pure functional language" problem by *turning the world inside-out*. Instead of taking data from the mutable outside world, using functions to manipulate it, and depositing results back into that world, you put your functions into the IO monad. But (the illusion of) taking data out from the real world, manipulating it, and then putting it back is exactly what the monadic-do syntax sugar accomplishes: The type system turns the world inside-out and then the do-notation provides a right-side-in syntax to code functions in the inside-out world. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] OS swapping and haskell data structures
Alex Jacobson wrote: > Ok, so for low throughput applications, you actually need a disk > strategy. Got it. > > Ok, is there a standard interface to BerkleyDB or some other disk based > store? I would absolutely kvell if there were some way to use a disk-based store to back Haskell objects without going through the IO monad. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad Description For Imperative Programmer
My own perspective on monads is this: In procedural and OO languages, when dealing with compound data structures, we think in terms of getters (*taking data out* of the structure) and setters (*putting data in* to the structure). Languages with some impure functional features (Lisp, Scheme, Perl, Python) let you operate on lists with a "map" function ("mapcar" in Common Lisp), where instead of *taking data out* of a list, you *put a function in*, and the function manipulates each element without being aware of the context. You *turn the data structure inside-out*, as it were, so you don't have to think about how the elements are accessed. Functors are a generalization from lists to "things that can be mapped over" in general, and then monads are a generalization of functors. Haskell solves the "how can I do I/O in a pure functional language" problem by *turning the world inside-out*. Instead of taking data from the mutable outside world, using functions to manipulate it, and depositing results back into that world, you put your functions into the IO monad. It's like the joke about how a theoretical mathematician catches an elephant: build a cage, go inside, close the door, and redefine outside as inside. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New HaskODell user groups
Donald Bruce Stewart wrote: > > P.S. Some obvious user group candidates, in my opinion, would be a > Portland group, a Bay Area group and something at Chalmers... ;-) Are there any other Haskellers in the Boston area? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How Albus Dumbledore would sell Haskell
Paul Johnson wrote: >> You cannot win over the entrepreneur with promises of "easier and more >> robust". This translates to "anyone can do it" and the valuable "trade >> secret" of arcane wizardry is now devalued. > > I suggest reading extracts from "Beating the Averages" by Paul Graham. > Then explain that Graham only wrote in Lisp because his university > didn't teach Haskell. I think a more powerful argument would be to talk about cases where Haskell is *actually being used* industrially. E.g., "these folks at Credit Suisse are using Haskell for their analytics because in their line of work, if the implementation of the code doesn't match up perfectly with the spec, their employer could lose millions of dollars, and the programmers might not notice the bug until those millions were long gone". ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: problems installing ghc 6.6 with extralibs (bad interface file)
Thomas Hartman wrote: > Thanks. I incorporated these changes, and it cranks longer now before > failing. But still fails, now with a seg fault. > * > gcc: Internal error: Segmentation fault (program cc1) > Please submit a full bug report. > See http://gcc.gnu.org/bugs.html> for instructions. > For Debian GNU/Linux specific bug reporting instructions, see > . According to conventional wisdom, when gcc segfaults on a big compilation job (e.g., the Linux kernel), it could be a sign of a transient memory error; gcc exercises the RAM so much that the error rate on a typical computer's memory chips can have a practical effect. You can either buy more expensive RAM or run the build again and hope for better luck. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A "real" Haskell Cookbook
P. R. Stanley wrote: > I'm referring to math symbols which do not get successfully > translated into an intelligible symbol in the screen reader browse buffer. Is there a way to make the symbols both look right on a screen and sound right from a screen reader? E.g., Σ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] TFP 2007: Registration and Program
> I assume that there is no way to change the date for *this* conference; > it would require renegotiating agreements and rejuggling schedules with > too many actors (hotels, restaurants, important speakers, etc.). > > But I would like everyone involved in planning *future* conferences to > keep this issue in mind. PS: A friend of mine wrote a convenient CGI script to help planners out with this issue: http://jik2.kamens.brookline.ma.us/cgi-bin/holidays.cgi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] TFP 2007: Registration and Program
Murray Gross wrote: > First, I suspect that the date is now cast in stone and cannot be > changed, and it is fair to suspect that holiday observance is going to > reduce attendance (at the very least, in the later afternoon). I assume that there is no way to change the date for *this* conference; it would require renegotiating agreements and rejuggling schedules with too many actors (hotels, restaurants, important speakers, etc.). But I would like everyone involved in planning *future* conferences to keep this issue in mind. > I would suggest that if the dates cannot be moved around by a > few days, the conference organizers should make a concerted attempt to > see to it that food acceptable for Passover consumption is available for > those that require it (like myself) and that conference attendees know > this in advance. Given how much variation there is in how people define "food acceptable for Passover consumption", this could easily lead to embarassment on both sides. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] TFP 2007: Registration and Program
TFP 2007 wrote: > > Dear Colleagues, > > You may now resgister for TFP 2007! TFP 2007 will be held April 2-4, > 2007 in New York City, USA. Aaargh! April 2 is the first night of Passover. This is not one of those obscure holidays whose names are Hebrew for "alternate-side parking suspended"[*]; a solid majority of Jews, even of unaffiliated Jews, observe Passover. You wouldn't schedule an academic CS conference to be held over Christmas or Easter, would you? Please treat Passover[**] the same way. [*] If you don't live in New York City you may not get this joke. [**]And, as long as I'm on the topic, Rosh Hashana or Yom Kippur... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange memory consumption problems in something that should be tail-recursive
Jefferson Heard wrote: > > Argh, bitten by the scheme bug! Right -- NO tail recursion... So that leaves > me with some rather non-intuitive strategies for achieving execution time > efficiency. Anyone care to point me in the direction of a document on > efficiency in Haskell? I found this page to be helpful: http://haskell.org/haskellwiki/Stack_overflow ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] still wrestling with io
Martin DeMello wrote: > Code here: http://zem.novylen.net/anagrid.html > > I've got an instance of IO appearing unexpectedly and I can't figure > out where from. It throws up the following error: > > $ ghc --make test.hs > Chasing modules from: test.hs > Compiling Main ( test.hs, test.o ) > > test.hs:38:15: >Couldn't match `StaticText ()' against `IO (StaticText ())' > Expected type: StaticText () > Inferred type: IO (StaticText ()) >In the application `staticText p [text := (labelText a b)]' >In the definition of `textOf': >textOf p a b = staticText p [text := (labelText a b)] According to the http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Controls.html page, "staticText" has the type signature "Window a -> [Prop (StaticText ())] -> IO (StaticText ())". Your textOf function has the type signature "Panel () -> String -> Anagrams -> StaticText ()". Your textOf *definition*, therefore, something of type "StaticText()" left side and type "IO (StaticText ())" on the right. The compiler doesn't like that. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO is not a monad
Aaron McDaid wrote: > Could seq be changed so that it will not give an error if it finds > undefined? Am I right in thinking that seq is supposed to > theoretically do nothing, but simply give a hint to the compiler so to > speak? If that is true, it should merely attempt to evaluate it, but > ignore it if it cannot evaluate it. ⊥ represents any unsuccessful computation, not just the exception that a Haskell implementation throws when it evaluates "undefined". In particular, a program that does not terminate at all can be described as returning ⊥. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages
Ketil Malde wrote: > Using a lazy fold may not be the best choice. Although it may > sound enticing to delay washing until a clean dish is actually required > (and having the dirty dishes removed by the garbage collector, hopefully > before they start naturally decomposing), you will quickly run out of stack > space. Sounds like an experience I had with one of my roommates ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strings in Haskell
John Meacham wrote: > On Mon, Jan 22, 2007 at 09:37:21PM -0500, Bryan Donlan wrote: > >>Or you can get the best of both worlds by using Data.ByteString.Lazy :) >>Even with laziness, all the indirections that String causes hurts >>performance. > > > actually, strictness analysis is really good at unboxing things like > this, so the indirections probably hurt less than one would initially > think. One thing that's impressed me with the Haskell application I'm currently working on (as I am trying to bully the code into handling 10M rows of data, which must all be kept in memory at once, without keeling over) is how often adding explicit strictness annotations *hasn't* improved performance. I guess this means that GHC's strictness analysis isn't much worse than my own. (and that my algorithms are such crap that issues of laziness/strictness are the least of my problems... :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO is not a monad (and seq, and in general _|_)
Brandon S. Allbery KF8NH wrote: > Can someone explain to me, given that (a) I'm not particularly expert > at maths, (b) I'm not particularly expert at Haskell, and (c) I'm a bit > fuzzybrained of late: Me too... > Given that _|_ represents in some sense any computation not > representable in and/or not consistent with Haskell, why/how is > reasoning about Haskell program behavior in the presence of _|_ *not* > like reasoning about logic behavior in the presence of (p^~p)->q? The only catch I see to that POV is that the way `seq` is defined, "undefined `seq` 42" *must* return an error. If this were analogous to "(p^~p)->q", then "undefined `seq` 42" would be allowed to return any value whatsoever. (Imagine an "unsafeSeq" operator, such that "undefined `unsafeSeq` 42" could *either* raise an exception or return 42, and implementations would be free to replace "a `unsafeSeq` b" with "b" when optimizing. Would this be useful?) Can we treat "a `seq` b" as a sort of pragma and not a "real" function? Does Haskell semantics become tractable again if we treat Haskell excluding "seq" (and excluding exceptions? and excluding threads?) as a category, and the exceptions as operating on some kind of meta-level? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New (simple) Lazy Evaluation tutorial
Andrew Wagner wrote: > Hi all, > > An interesting question came up in #haskell the other day, and I took > the resulting discussion and wrapped it up into a simple tutorial for > the wiki. Since I'm quite a newbie to haskell myself, I'd appreciate > any double-checking of my logic and, of course, any other > comments/suggestions. Thanks to Cale for his efforts on this problem, > and to the original asker, whose name I can't recall. > > http://www.haskell.org/haskellwiki/Haskell/Lazy_Evaluation Rather than use the Fibonacci series as an example, why not something like this...? contains :: String -> String -> Bool contains _ "" = False contains "" _ = True contains (x:xs) (y:ys) = ((x == y && contains xs ys) || contains (x:xs) ys) infiniteBanana :: String infiniteBanana = "banana" ++ infiniteBanana contains "na" infiniteBanana ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] an advanced foldification problem
I have a data type "Group", representing a group of geographic information that is all referring to the same location, and a function "mergeGroups" that tries to merge two groups: mergeGroups :: Group -> Group -> Maybe Group Then I have a function "mergeGroupToList" that tries to merge its first argument with every element of the second argument: mergeGroupToList :: Group -> [Group] -> [Group] mergeGroupToList g [] = [g] mergeGroupToList g1 (g2:gs) = case (mergeGroups g1 g2) of Nothing -> g2 : (mergeGroupToList g1 gs) Just g3 -> mergeGroupToList g3 gs How can I rewrite mergeGroupToList in terms of foldr? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellForge?
Yitzchak Gale wrote: > tphyahoo wrote: > >> I think people want something like CPAN. This implies a centralized >> "official" repository > > > I agree. > > I think we also need a notion of a canonical > standard package for each popular category. For some categories, it might be better to have a canonial standard *typeclass* and let various packages derive from that class. Cf. the Python DB-API (http://www.python.org/dev/peps/pep-0249/) and WSGI (http://www.python.org/dev/peps/pep-0333/). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Composing functions with runST
David House wrote: > >> So I can't just tell someone who's just starting to learn Haskell that >> "f $ g y" is equivalent to "f (g y)"; I have to say "those two are >> *almost always* equivalent, but if you use $ and the compiler complains >> about not being able to match the expected and the inferred type and a >> type signature in the error message has the word 'forall', try rewriting >> that expression without the $ and see if it compiles". Eeeww. > > Why would someone just starting to learn Haskell be using ST? The > canonical tutorial structure is to start with the pure stuff and only > introduce the (more complicated!) impure stuff (ST, IORefs, etc.) in > an 'advanced techniques' or similar section. I (and one other person on this list) ran into this issue when I was trying to use takusen to make Haskell talk to a RDBMS. You obviously need to learn advanced techniques to *implement* such a thing, but you shouldn't need advanced knowledge to *use a library* that happens to use higher-rank polymorphic types in its API. There are many routes to fluency in a language, and not everybody is suitable for the route of "here are the axioms underlying the language and the simplest code that applies them; after you thoroughly understand those, we'll show you how to make something practical". Some of us prefer the route of "here are some examples of how to get practical things done; after you're comfortable with them, we'll show you the theory that underlies them". Actually, I suspect that *most* of us prefer the second route. Set theory is closer to the theoretical foundations of mathematics than arithmetic, but when elementary schools tried teaching kids set theory, it didn't work out so well. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Composing functions with runST
Simon Peyton-Jones wrote: > Conor and others are right; it's all to do with type inference. There is > nothing wrong with the program you are writing, but it's hard to design a > type inference algorithm that can figure out what you are doing. > > The culprit is that you want to instantiate a polymorphic function (here (.) > or ($) in your examples) with a higer-rank polymorphic type (the type of > runST, in this case). That requires impredicative polymorphism and while GHC > now allows that, it only allows it when it's pretty obvious what is going on > --- and sadly this case is not obvious enough. I don't know enough type theory to suggest a specific patch, but I hope a future version of GHC can do the right thing for (.) and ($) in this situation (and possibly for other functions that simply rearrange their arguments, like flip). >From a friendliness-to-newbies point of view, these error messages are a tremendous wart. I've been on haskell-cafe for a little over three months and seen postings from three people who were tripped up by this (the first of them was myself). So I can't just tell someone who's just starting to learn Haskell that "f $ g y" is equivalent to "f (g y)"; I have to say "those two are *almost always* equivalent, but if you use $ and the compiler complains about not being able to match the expected and the inferred type and a type signature in the error message has the word 'forall', try rewriting that expression without the $ and see if it compiles". Eeeww. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A suggestion for the next high profile Haskell project [Was: Re: What is a hacker?]
Joachim Durchholz wrote: >> Trying to fully evaluate an infinite data structure will result in >> looping or memory exhaustion, and you have that possibilities in almost >> all languages. > > Yes, but I suspect that Haskell makes it easier to make that kind of bug. > Worse, it's easy to introduce this kind of bug: just pass a list > returned from function a to function b, not being aware that a may > return an infinite list and that b may do something with it that > requires that it's evaluated. In other words, this kind of bug can come > into existence during code integration... and the type system doesn't > warn you when you do it. If you're worrying about some unexpected input causing a function never to terminate, don't you also have to worry about some unexpected input causing a function to become so glacially slow that from the user's perspective, it *might as well* never terminate? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivial database access in Haskell)
Paul Moore wrote: > db.hs:10:64: >Couldn't match expected type `forall mark. DBM mark Session a' > against inferred type `a1 b' >In the second argument of `($)', namely >`do r <- doQuery > (sql "select username from all_users") query1Iteratee [] > liftIO $ (putStrLn $ (show r))' >In the expression: > (withSession (connect "USER" "PASSWORD" "DB")) >$ (do r <- doQuery > (sql "select username from all_users") > query1Iteratee [] >liftIO $ (putStrLn $ (show r))) >In the expression: >do (withSession (connect "USER" "PASSWORD" "DB")) > $ (do r <- doQuery > (sql "select username from all_users") > query1Iteratee [] > liftIO $ (putStrLn $ (show r))) I had the same problem... ($) doesn't have the expected semantics with existential types (like "forall mark. DBM mark Session a"). Some day I will be able to explain why this is so, but in the meantime, if you replace "liftIO $ putStrLn $ show r" with "liftIO (putStrLn (show r))", it should work. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing "Haskell For Dummies Or At Least For People Who Feel Like Dummies When They See The Word 'Monad'"
Paul Hudak wrote: > Hi Sebastian. As a writer of one of those "academic" Haskell textbooks, > I've been following this thread with some interest. BTW, I found your textbook very helpful. The first time I tried to learn Haskell, I got the Bird and Wadler textbook, and got bogged down about halfway through. It just wasn't the sort of approach that was good for someone in my position, i.e., trying to pick up the language in my spare time without the structure of a college class to check my work and give me the occasional kick in the rear. But with SOE--ooh! pretty pictures! (The only problem was figuring out the magic incantation to make Hugs on my system talk to the SOEGraphics library.) > Maybe some of you can do better, but it's really tough to show someone > how an /advanced/ Haskell programmer would solve /advanced /problems > that arise in the real world. As a simple example, I love this recent > quote by Garrett Morris: > > "I'm personally fond of framing most non-trivial Haskell problems as > defining domain specific languages; as a result, everything over about > 200 lines that I've written in the past 3 years has used the mtl [Monad > Transformer Library] in some form or fashion. It's great." > > So how do we teach Garrett's way of programming (which I like very much) > to the masses? One would guess that we'd need to explain not only > monads, but also monad transformers, first. My first thought would be to develop some kind of cheap-ass NLP system, starting with simple "VERB NOUN" constructions or some kind of text filter, and building up to the kind of parser that the Infocom Z-machine uses. (N.B.: applications that are too reminiscent of math class, like arithmetic-expression evaluators or symbolic differentiators, are turn-offs. If the rest of us were that thoroughly comfortable with math, we'd be expert Haskell programmers already. :-) > Sebastian Sylvan wrote: >> There must be some way of teaching Haskell "breadth first", so to speak. In the ed biz they call this a "spiral curriculum". As applied to a Haskell textbook, what I would suggest is something like this: In chapter 1, introduce the IO monad, and point out a few key features (e.g., explain why a function with type "IO a -> a" would be unsafe). In chapter 2, introduce the Maybe monad, and point out that constructions like "(Just 5) >>= putStrLn" won't compile. In the next few chapters, introduce other common and useful monads, so the student has some hope of getting an intuitive sense of what's going on with them; at the same time, dribble in a few useful facts about monads or useful operators for manipulating them. *Then*, no earlier than chapter 5, provide the formal definition of a monad and explain how you can roll your own. (I'm not sure whether it would be helpful to give some examples of monad transformers before the formal definition of a monad, or whether those should come afterward.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Good Haskell introduction for an Ocaml programmer?
Brian Hurt wrote: > > Greetings, all. I'm an experienced Ocaml programmer, looking to broaden > my horizons yet further and pick up Haskell, and I'm wondering if > there's a good introduction to Haskell for me. Okasaki's _Purely Functional Data Structures_ discusses (among other things) the pros and cons of lazily evaluated structures. The examples in the body of the book are in ML and an appendix has "translations" into Haskell. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trivial database access in Haskell
Taral wrote: > On 12/11/06, Paul Moore <[EMAIL PROTECTED]> wrote: > >> F:\cabal-1.1.6.1>runhaskell Setup.lhs install >> Installing: C:\Program Files\Haskell\Cabal-1.1.6.1\ghc-6.6 & >> C:\Program Files\Haskell\bin Cabal-1.1.6.1... >> Setup.lhs: Error: Could not find module: Distribution.Compiler with >> any suffix: >> ["hi"] > > > The magic commands are: > > runhaskell Setup.lhs configure Also, if you're going to profile the code that uses this module, you need to compile the libraries with profiling enabled; you can do this by doing "configure -p" instead of "configure" above. > runhaskell Setup.lhs build > runhaskell Setup.lhs install > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Aim Of Haskell
Donald Bruce Stewart wrote: > > Who wants to join the Lisp is not functional programming movement with me? Oh, lordy. As if the "Scheme is not Lisp" flames on comp.lang.lisp weren't enough... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] strange type mismatch when trying to use takusen
Taral wrote: Ah, the dreaded $ with existential types problem. $ is not quite equivalent to application -- the type checker does something funny with forall types. Just take out the $ and you'll be fine. Is this a ghc bug, or some subtlety of the type system that I don't understand? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] strange type mismatch when trying to use takusen
I have a simple test program for takusen and PostgreSQL: import Database.Enumerator import Database.PostgreSQL.Enumerator import Control.Monad.Trans gazdbSession dbname = connect [CAdbname dbname] resultCollector :: (Monad m) => String -> IterAct m [String] resultCollector str accum = result' (str:accum) main = do withSession (connect [CAdbname "template1"]) $ main' main' = do r <- doQuery (sql "select 'fred'") resultCollector [] liftIO $ putStrLn $ show r But it won't compile: [1 of 1] Compiling Main ( takusen-test.hs, takusen-test.o ) takusen-test.hs:11:57: Couldn't match expected type `forall mark. DBM mark Session a' against inferred type `DBM mark sess ()' In the second argument of `($)', namely `main'' In the expression: (withSession (connect [CAdbname "template1"])) $ main' In the expression: do (withSession (connect [CAdbname "template1"])) $ main' Adding an explicit "main' :: DBM mark Session ()" type signature doesn't change the error message. The takusen source that I'm using was updated from darcs on November 14 and compiled with ghc 6.6. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] the case of the 100-fold program speedup
As Lily Tomlin would say, neVERmind. Simon P-J asked me, in email, whether the deforestation was the thing that actually made the program faster or whether it was just the thing that made me think about how to solve the problem. I realized that my fast program had *another* difference from the earlier, slower program: it was based on an algorithm that was specifically designed to clip polygons to rectangles, whereas OGR just had a function to compute the intersection between two arbitrary polygons. So I threw together a version that accumulated all the vertices of the clipped polygon in a list and then iterated through the list to compute the centroid--i.e., preserving everything from my fast program except the deforestation--and it ran at almost exactly the same speed as the deforested program. (Actually, it ran 2% faster, but that could be just random variation from things like the load on the database server.) "The tragedy of science: a beautiful theory slain by an ugly fact." "T. H. Huxley said it first." ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] the case of the 100-fold program speedup
Henning Thielemann wrote: > On Tue, 14 Nov 2006, Seth Gordon wrote: > > >>It took me a week to figure out the right algorithm for combining these >>two procedures and write some almost-working code that implemented it. >>It took a co-worker of mine another few days to find the bugs that had >>eluded me. > > > Were these bugs of the kind that would have been found by a static type > checker, say the one of Haskell? The most significant bug that my co-worker caught was in the math, not the implementation--when translating the centroid formula from big-sigma notation to a recurrence, I accidentally wrote (x_i x_{i+1}) when I should have written (x_i + x_{i+1}). My stupidity surpasses the stupidity-catching power of the type checker. There were less significant bugs that probably would have been caught by static type checking, but in this case I think the unit tests caught them just as quickly. The "producer" part of the clip-and-centroid algorithm generates 0, 1, or 2 vertices for every vertex of the original polygon, which are then fed into the "consumer" part to compute the centroid. It did cross my mind as I was writing the Python code that this sort of thing could be handled much more concisely with the List monad, but doing the whole thing in Haskell would have required (a) writing Haskell glue code to either interface with the OGR library or parse WKT strings, and (b) convincing my co-workers that Haskell was *so* incredibly useful that it was worth adding another language as a build-time dependency. (I'm laying the groundwork for (b) in my Copious Free Time) > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] the case of the 100-fold program speedup
One of Alan Perlis's "Epigrams in Programming" is "A language that doesn't affect the way you think about programming, is not worth knowing". I recently had an experience that demonstrated this principle. I had to write some code that took a polygon (encoded in WKT, a standard format for geographic information exchange), computed its intersection with several rectangles, and then compute the centroid of each one of these intersections. No problem, I thought. People who know more than me about this geometry stuff have written an open-source library, OGR, which has functions for parsing WKT, computing intersections, computing centroids, and computing all sorts of other things. And there are Python bindings for OGR so I don't have to wrestle with C++ to solve my problem. So I wrote a Python program that used OGR to crunch the numbers, ran it through the data set we needed to process, and...it took over sixteen hours to run. Since we want to have this program process this data set with every build of our software, adding sixteen hours to our build time was not a pleasant thought. Then I thought about some of the things I'd read about optimization of functional programming languages, and said, "Hey! The algorithm for clipping the polygon to the rectangle is producing a sequence of vertices, and the algorithm for computing the centroid is consuming a sequence of vertices. I can do some deforestation here!" It took me a week to figure out the right algorithm for combining these two procedures and write some almost-working code that implemented it. It took a co-worker of mine another few days to find the bugs that had eluded me. But after the program worked for my test cases, I ran it again on the full data set...and it took ten minutes. In other words, I sped up the code by two orders of magnitude. And I didn't even have to drop into C++ to do the number-crunching; I used OGR to parse the WKT strings and to look up the coordinates of each vertex of the polygon, but the algorithm itself was implemented in Python. w00t! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie and working with IO Int and Int
Víctor A. Rodríguez wrote: > Hi all, > > I'm really newbie to Haskell, and working on a program I'm trying to make > some testing. > I make some test on certain know values ( e.g. adding 10 to 15 must return > 25) and some test on random values (eg. adding rnd1 to rnd2 must return > rnd1+rnd2). > > The problem that makes me mad is the random number generation. I can obtain > random numbers through module Random but all of them return IO Int values > (all I need are Ints) instead of Int. > I know that I can adjust my own functions to use IO Int instead of Int but > the call to certain functions must contain Int parameters, because these > ones can't be changed to accept IO Int (I read > http://haskell.org/hawiki/ThatAnnoyingIoType and know that can convert from > IO Int to Int :-P). What's wrong with doing it this way? -- ** UNTESTED CODE ** verifyAdd :: Int -> Int -> Int -> Bool verifyAdd a b sum | a + b == sum = True otherwise= False testAddMundane :: Int -> Int -> Bool testAddMundane a b = verifyAdd a b (a + b) -- all the IO-dependent stuff is below this line -- testAddRandom :: IO Bool testAddRandom = do a <- randomIO b <- randomIO return verifyAdd a b (a + b) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting a DB library working with ghc 6.6 and PostgreSQL 7.4.7
> I installed HDBC, but when I tried running a simple program that used > it, I get the error message > > ghc-6.6: > /usr/local/lib/HDBC-postgresql-1.0.1.0/ghc-6.6/HSHDBC-postgresql-1.0.1.0.o: > unknown symbol `PQserverVersion' Ah, I figured it out. The PQserverVersion function is documented in the PostgreSQL 8.0 and 8.1 manuals as follows: "Applications may use this to determine the version of the database server they are connected to. The number is formed by converting the major, minor, and revision numbers into two-decimal-digit numbers and appending them together. For example, version 7.4.2 will be returned as 70402, and version 8.1 will be returned as 80100 (leading zeroes are not shown). Zero is returned if the connection is bad." You'd think, from the description, that the libpq for PostgreSQL 7.4 would also have this function. But it doesn't. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] getting a DB library working with ghc 6.6 and PostgreSQL 7.4.7
I'm looking for an alternative to HSQL for database connectivity -- the lack of prepared statements in HSQL is particularly worrisome. I installed HDBC, but when I tried running a simple program that used it, I get the error message ghc-6.6: /usr/local/lib/HDBC-postgresql-1.0.1.0/ghc-6.6/HSHDBC-postgresql-1.0.1.0.o: unknown symbol `PQserverVersion' Looking more closely at the README.txt file there, it seems that the PostgreSQL driver is expecting 8.1, and I'm using 7.4.7. I installed the ODBC driver, and I know that in theory one can connect to my PostgreSQL server with ODBC, but as far as I can tell from the documentation, I would have to configure a separate DSN for every database instance that I would want to connect to, which makes it kind of useless for a utility that any user could pass database names to on the command line. The takusen package looks interesting, but when I checked it out and tried to build it (with "ghc --make -o setup Setup.hs"), I got the error message Setup.hs:6:7: Could not find module `Distribution.Compat.FilePath': it is hidden (in package Cabal-1.1.6) How do I work around these? Is there another library worth looking into? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: tail-recursing through an associative list
[EMAIL PROTECTED] wrote: > For logarithmic access times, you should use a binary search tree like > Data.Map or similar. The problem in your case could be that matchKeys is > only approximate and your keys cannot be ordered in suitable fasion. That is precisely the problem that I was dealing with. I've been ruminating on some way to use a map to solve the problem, although since this project has been demoted from "cool side project for work" to "cool side project for my Copious Free Time", I don't know when I'll be able to implement it. Thanks for all your suggestions--at least I feel like I am on the right track. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] tail-recursing through an associative list
In my first posting, I mentioned that I was going to try to translate some of our code to Haskell and see how it worked. Well, I don't have a stunning demonstration of the power of pure functional programming, but I do have an interesting problem. I chose to port a program that we use in our build system that takes a table of geographic data and groups the rows in the table according to [REDACTED]. The description of what the existing program does takes up only a few paragraphs, but the source code is eight pages of dense C++ that has obviously been optimized up the wazoo (and beyond the point where a mortal like myself can understand what's going on). On one of our servers, it can process 200,000 rows in about three minutes. My Haskell translation is three and a half pages of gorgeous lucid almost-entirely-functional code ... that in its first draft, took about three seconds to process 2,000 rows, eight minutes to process 20,000 rows, and overflowed a 1-MB stack when processing 200,000 rows. Oops. After banging together a version that took input from stdin instead of the database (it was easier to do that then to learn enough about Cabal to get HSQL recompiled with profiling), I profiled the code and observed that the most-called-upon function in the program (200 million entries for those 20,000 rows) was structured like this: type AList = [(Key, [MetaThingies])] myFunction :: AList -> Thingie -> AList myFunction [] x = [(key x, [meta x])] myFunction ((k, v):tail) x | matchKeys k (key x) = case tryJoining v x of Nothing -> (k, v) : (myFunction tail x) Just v' -> (k', v') : tail where v' = bestKey k (key x) | otherwise = (k, v) : (myFunction tail x) I'm wondering if the slowness of the program can be attributed to that case statement in the middle--perhaps unwrapping the Maybe type returned by tryJoining is preventing the function from being properly tail-recursive, or something. (I tried making the list construction strict by replacing "(k, v) : (myFunction tail x)" et al. with "(:) (k, v) $! (myFunction tail x)", and it actually slowed the program down, so either I'm not understanding how to improve things with strictness or laziness isn't the problem here.) Any advice from the gurus? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ghc 6.2.2 seems to ignore -package when there's a -prof option
I have a program using HSQL that I'm trying to profile. When I do ghc program.hs -package hsql -o program it compiles fine, but when I do ghc -prof -auto-all program.hs -package hsql -o program I get error messages saying "failed to load interface for `Database.HSQL'" and so forth, the same way I do if I leave off the -package argument entirely. How can I work around this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: a monad for secret information
David Roundy wrote: Try module Secret (Secret, classify, declassify) where data Secret a = Secret String a classify :: String -> a -> Secret a classify pw x = Secret pw x declassify :: Secret a -> String -> Maybe a declassify (Secret pw x) pw' | pw' == pw = Just x declassify (Secret _ _) _ = Nothing instance Monad Secret where return = classify "" (Secret pw x) >>= f = case f x of Secret _ y -> Secret pw y That's just the sort of thing I was looking for. Thanks! Arie Peterson wrote: What should 'q >>= r' mean, when 'q' and 'r x' are secrets with different passwords? In the code above, the result is a secret with the same password as 'q'. This allows you to declassify any secret without knowing its password: Yeah, but I think that's easy to fix: make classify and declassify take a set of strings rather than a single string, and then make >>= return a secret containing the union of passwords on both sides. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a monad for secret information
> data Secret a = Secret {password :: String, value :: a} > > classify :: String -> a -> Secret a > classify = Secret > > declassify :: String -> Secret a -> Maybe a > declassify guess (Secret pw v) | guess == pw = Just v > | otherwise = Nothing > > Put that in a module, do not export the Secret data type, and you're > good to go. I'm unsure what a Monad is giving you I was just curious if I could do that within a monad. If the answer to my question is "no, you can't", then I'll pick up the shattered pieces of my life and move on. :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a monad for secret information
Cale Gibbard wrote: > Why not just: > > secret :: a -> Classification String a > secret = Classification "xyzzy" > > The password string isn't part of the type, it doesn't even > necessarily exist at compile time. You might have just got confused > between type and data constructors for a moment. > But now I want to be able to process the secret monadically: mySecret = secret "Jimmy Hoffa is buried under the 50-yd line in the Meadowlands" do secretData <- mySecret return (length secretData) How do I define "return" so that it will put the password back, and how do I define "(>>=)" so that the password won't be accessible within the do-block? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] a monad for secret information
I finally (think I) understand monads well enough to make one up: module Secret (Secret, classify, declassify) where data Secret a = Secret a classify :: a -> Secret a classify x = Secret x declassify :: Secret a -> String -> Maybe a declassify (Secret x) "xyzzy" = Just x declassify (Secret x) _ = Nothing instance Monad Secret where return = classify (Secret x) >>= f = f x The nice thing about this is that (correct me if I'm wrong) clients of the module can't sneak information out of the monad without either using the right password or by using one of the unsafe*IO methods. (Or by running the program in a debugger. But you get the idea.) The not-so-nice thing is that the literal text of the password is baked into the data definition. I'd like to have a more general version of Secret that allows someone to pass the password in when constructing a secret, and preserves that password when "return" is used, but doesn't let the second argument of (>>=) see the password. Something like this:... data Classification pw a = Classification pw a declassify (Classification pw a) pw' = case pw' of pw -> Just a _ -> Nothing type Secret = Classification "xyzzy" ...but that doesn't parse. Is it even possible to have a type like this that still observes the monad rules? Is this the sort of thing that I need to understand arrows to pull off? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Greetings
Paul Johnson wrote: I've done some stuff with maybe 50k rows at a time. A few bits and pieces: 1: I've used HSQL (http://sourceforge.net/project/showfiles.php?group_id=65248) to talk to ODBC databases. Works fine, but possibly a bit slowly. I'm not sure where the delay is: it might just be the network I was running it over. One gotcha: the field function takes a field name, but its not random access. Access the fields in query order or it crashes. Thanks; that's certainly the sort of thing I like knowing in advance. 2: For large data sets laziness is your friend. When reading files "getContents" presents an entire file as a list, but its really evaluated lazily. This is implemented using unsafeInterleaveIO. I've never used this, but in theory you should be able to set up a query that returns the entire database as a list and then step through it using lazy evaluation in the same way. I assume that the collectRows function in HSQL can produce this kind of a lazy list...right? 3: You don't say whether these algorithms are just row-by-row algorithms or whether there is something more sophisticated going on. Either way, try to make things into lists and then apply map, fold and filter operations. Its much more declarative and high level when you do it that way. I'm going to need to do some mapping, folding, partitioning... Let us know how you get on. I certainly will. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Greetings...
jeff p wrote: Hello, So before I embark on day 1 of the project, I thought I should check and see if anyone on this list has used Haskell to munge a ten-million-row database table, and if there are any particular gotchas I should watch out for. One immediate thing to be careful about is how you do IO. Haskell is not very good, in my experience, at reading files fast. You'll probably want to skip the standard Haskell IO functions and use the lazy bytestring library (http://www.cse.unsw.edu.au/~dons/fps.html). I'm planning to use HSQL, since it's in Debian stable and the API resembles what I'm already familiar with. Database access is slower than file access (which is one reason I want to move as much logic as I can out of SQL), so if the speed of getting rows out of the database turns out to be the bottleneck in my code, I'll either be happy that all the other code is so efficient or peeved that HSQL is so inefficient. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Greetings...
I've finally gotten enough round tuits to learn Haskell, and now that I've done some of the exercises from _The Haskell School of Expression_ and I finally (think I) understand what a monad is, the language is making a lot more sense to me (although my code is not always making so much sense to the compiler :-). My employer (MetaCarta) makes a search engine that can recognize geographic data. My group within MetaCarta is responsible for building the "Geographic Data Module" within our software. To do this, we slurp a heap of geographic and linguistic data from a variety of sources, normalize it, and then use some algorithms (that I'm not allowed to describe) to generate the module. This seems like the sort of task that cries out for a functional-programming approach, and that's what we use, sorta: a lot of the code that I'm responsible for is SQL, with chains of "CREATE TEMP TABLE X AS [insert very complicated query here]", some C++ for the parts that would be very time-consuming or impossible to implement in SQL, and shell scripts to tie everything together. I told my tech lead that I want to try porting some of this code to Haskell in the hope that it would run faster and/or be easier to read. He said I should spend two work days on the project and then be prepared to convince my co-workers that further research in this vein is (or is not) worth doing. So before I embark on day 1 of the project, I thought I should check and see if anyone on this list has used Haskell to munge a ten-million-row database table, and if there are any particular gotchas I should watch out for. adTHANKSvance ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe