Re: [Haskell-cafe] Learn Prolog...
Peter Verswyvelen wrote: Thanks, this is very useful information! Prolog is indeed on my list as languages I want to learn. I understand the basic principles, but haven't digged deep yet. But first I want to do Haskell, which I'm now totally addicted to! But after reading http://en.wikipedia.org/wiki/Fifth_generation_computer, it seemed to me that Prolog was a dead language, having only pure theoretical purposes. Is this true? Having a rich imperative background (I wrote some simple imperative compilers and a large semi-functional visual programming toolkit currently being used by a game development company), a book I found really useful to understand how the inners of FP and Prolog work is Modern Compiler Design. It provides C code for all the concepts, so an imperative programmer feels right at home. But to me it had the side effect that after reading the last chapters on functional and logical programming, I felt I had to get rid of these imperative languages as quickly as possible (I always felt I was hacking when doing C, C++, or C#... which maybe just meant I'm a bad programmer ;-) PS: A part of the "Prolog for AI" book can be read on Google Books (this Google Books thing looks *very* illegal to me, but since it's google and not some hackers website, I felt free to provide a link here...) Cheers, Peter Verswyvelen [EMAIL PROTECTED] wrote: Yes, I know, this is Haskell list. So, I apologize, but not too much... Johan Grönqvist cites me: Anyway, I believe strongly that ALL people who have problems... should be encouraged to learn Prolog. IN DEPTH, Do you have a recommendation on how to do this? (e.g., books, web-pages, (available) lecture notes, problem sets) First, install a decent Prolog on your machine. There are plenty: http://kti.mff.cuni.cz/~bartak/prolog/implementations.html http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/prolog/prg/part2/faq-doc-2.ht ml You may wish to install the free version of Visual Prolog. My favourite is the SWI Prolog: http://www.swi-prolog.org/ (University of Amsterdam) The documentation is complete, and the reference manual contains references to such standard books as ClocksinMellish, or SterlingShapiro. The last one is very, very instructive. Also, Prolog Programming for Artificial Intelligence, written by Bratko, is very useful. There are on the web collection of examples from this book, don't remember where. Try here: http://promethee.philo.ulg.ac.be/engdep1/download/prolog/bratko/ On-line there are thousands of examples, tutorials, etc. J. Fisher: (There is an example of cut, especially for A. Coppin) http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html others: http://www.coli.uni-saarland.de/~kris/learn-prolog-now/lpnpage.php?pageid=on line http://computing.unn.ac.uk/staff/cgpb4/prologbook/book.html http://www.cs.nuim.ie/~jpower/Courses/PROLOG/ Etc., etc. Really! Examples. For example: http://www.csse.monash.edu.au/~lloyd/tildeLogic/Prolog.toy/Examples/ http://kti.mff.cuni.cz/~bartak/prolog/learning.html http://www.visual-prolog.com/vip/example/ and of course there are discussion lists, FAQs, etc. Ask Google... === Andrew Coppin writes: I did once try to learn Prolog. And failed. Miserably. I just couldn't bend my head around how the Prolog interpreter manages to make seemingly "impossible" leaps of deduction. (It's a *machine*! How can it deduce arbitrarily complex conclusions from any arbitrary set of axioms? That requires *intelligence*!) And yet, in other, seemingly identical cases, it utterly fails to deduce patently *obvious* results... really weird! One of standard exercices in Prolog is the construction of the meta-interpreter of Prolog in Prolog. While this is cheating, I recommend it to you. It opens eyes. Actually, there are three basic items to learn while trying to master Prolog after having dealt with the syntactic essentials term construction, and the like. 1. The unification, which shows the "ultimate" instance of pattern-matching and is useful for recognizing some techniques for the automatic inference of types in functional languages. 2. The usage of unbound "logical variable", which sometimes permits to to do things which require laziness in Haskell. 3. The control backtracking, which is at the heart of the logical non-de- terminism. Now, the non-deterministic algorithms in Haskell are usually implemented using the *data backtracking*, or the List Monad. The control backtrack, via, say success/failure continuations, is more difficult, they are rarely taught, and problematic because of strong typing. Prolog strategies are straightforward, and I simply cannot understand the comments of Andrew Coppin. Which arbitrary set of conclusions?? Which patently obvious results not derivable?? Be kind,
[Haskell-cafe] Extending the idea of a general Num to other types?
I like the fact that Haskel treats numbers in a generic way, so you can lift them to any other datatype by instantiating Num. Can the same be done on other builtin constructs? For example, if I have [a], can this list be lifted to other types? I guess not, because no type class exists for the list type? Does this make sense? I'm still searching for correct terminology... Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: HApps API Documentation?
Martin Lütke wrote: James Britt james at neurogami.com writes: Are there alternative sites for HAppS API docs? There are two links on http://happs.org/#documentation but both give File not found! messages. Thanks, James Just compile your one version from the HAppS source. Use runghc Setup.hs haddock. OK, I can give that a shot. I'm still curious about my original question, though. Are there alternative online API docs for Happs? You do have have haddock installed, havent you? I didn't. I'm grabbing Alex from darcs now. James ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for suggestions to improve my algorithm
I played around with this for a while based on the same sort of algorithm and ended up with a similar solution too. It turns out the operations saved by keeping track of already visited nodes are more than outweighed by the cost of doing so. (As you can see, I still have the hook in my code where amCn returns the visited list that I'm just disregarding. Ii had initially kept a giant array of all values to calculate, but the cost of that was unmanageable. After that, my big roadblock was that I couldn't come up with a good sumDivisors function to save my life. I tried a number of optimized methods that combined trial division with reduction based on prime factorizations, but i had to either reduce the lists by checking divisibility again somewhere along the way, or calling nub, and strictness and memoization still didn't let me produce a factorization in reasonable time. In the end, I ended up lifting yours. The only problem is that I've been staring at it for a bit and am not really sure how it works. I'd love an explanation. In any case, the code of my solution follows: amCn maxval n = amCn' (propDSum n) [] where amCn' cur visitedlist = if cur maxval || cur n then (0,visitedlist) else if elem cur visitedlist then (0,visitedlist) else if (cur == n) then ((length visitedlist) + 1,visitedlist) else (amCn' $! (propDSum cur)) $! (cur:visitedlist) longestAmTo maxval = longestAm' 2 (0,0) where longestAm' n bestFit@(chainLen,minVal) = if n maxval then bestFit else longestAm' (n+1) $! bestFit' where (count, visited) = amCn maxval n bestFit' = if chainLen count then bestFit else (count,n) properDivisorsSum :: UArray Int Int properDivisorsSum = accumArray (+) 1 (0,100) $ (0,-1):[(k,factor)| factor-[2..100 `div` 2] , k-[2*factor,2*factor+factor..100] ] propDSum n = properDivisorsSum ! n --S On Aug 30, 2007, at 11:33 AM, Chaddaï Fouché wrote: 2007/8/30, Chaddaï Fouché [EMAIL PROTECTED]: I managed it in 7 seconds (on 1500 MHz) with an idea close to yours (but I used IntSet, not IntMap), Daniel Fisher gave you some good ideas to achieve it, the real snail in this problem is the sumDivisors function. I put my final solution on the wiki, it get it done in 6s now (on a Pentium M 1.73Mhz). -- Jedaï ___ 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] interaction between OS processes
On Sat, Sep 01, 2007 at 09:12:30PM -0400, Albert Y. C. Lai wrote: Andrea Rossato wrote: loop s = do putStrLn s Most likely, the content of s sits in a local buffer and never leaves this process, following most OS conventions and as others point out. Another process waiting for it will deadlock. Most similar process deadlock problems are not specific to Haskell or even relevant to Haskell; they are misunderstandings of the underneath OS. I recommend every Haskell programmer to take an in-depth Unix course. Yes, I knew it was something related to the underneath OS. I'll have to study Unix seriously Thanks you guys for your kind attention. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
On Sunday 02 September 2007 03:29, Hugh Perkins wrote: A really simple way to track the quality of a package is to display the number of downloads. A posteriorae, this works great in other download sites. We can easily hypothesize about why a download count gives a decent indication of some measure of quality: [...] ... and even more easily hypothesize why this is not always a good indication: High-qualitiy standard libraries which are packaged with GHC/Hugs/... will probably almost never be downloaded separately. Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
On 9/2/07, Sven Panne [EMAIL PROTECTED] wrote: High-qualitiy standard libraries which are packaged with GHC/Hugs/... will probably almost never be downloaded separately. Good point. Note however that if someone is hunting for a library, it's generally because it's not already bundled with their default ghc install ;-) Sucks for hugs users I know ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for suggestions to improve my algorithm
Right, your program is 2 times faster than mine on my machine... I wonder if there is a better structure to do this bookkeeping than IntSet (maybe Sequence slightly remanied ?), anyway it goes to show how sometimes the bookkeeping can be more expensive than the operations it's meant to prevent ! As for my sumOfProperDivisors function it's dead simple, I would even say stupid (but it's faster than anything else I tried for now). An accumArray use the function you give it to update a cell, ok ? Here it's just (+) and all cells began their life as 1 since 1 is a proper divisors of all numbers (except 1, thus the (1,-1) for correctness). The following list just associate each proper divisor of a num with it, so the final value of a cell is the sum of those proper divisors. To achieve that we make factor take the value of all proper divisors possible for numbers from 1 to 100, in other words [2..100 `div` 2] (the `div` 2 is ok since we're speaking about proper divisors here), and then we go on to associate this divisor with all the numbers he divides properly, which are [factor * 2, factor * 3,...100]. Is it clear now ? -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Extending the idea of a general Num to other types?
Chaddaï Fouché wrote: You can indeed already do that, except it won't be a single instance since list have a bucketful of interesting properties. A good starting is looking at what list is an instance of and trying to identify the set of instance which interest us in this case, Foldable and Functor are probably a good start, embodying most of the interesting way to access a data structure as a list (head and tail don't really make sense for most of the alternatives, except other sequence library which currently provide this functionality in an ad-hoc way, see Sequence and ByteString for example of that). An alternative is Traversable. Thanks! But before digging into this, maybe I should rephrase myself by giving a more specific (although useless) example of what I mean. When I write: data Foo = Foo Int Int deriving (Show,Eq) instance Num Foo where fromInteger x = Foo x' x' where x' = fromInteger x _ + _ = error Not relevant for example _ * _ = error Not relevant for example abs _ = error Not relevant for example signum _ = error Not relevant for example x = 42::Foo I don't have to apply the Foo data constructor to lift the number 42 because I guess the compiler has builtin support for calling fromInteger (or fromRational). I even don't have to add the type annotation most of the time when the compiler can infer the type needed, which is very cool, sometimes a bit annoying. However, now I try the same for lists data Bar = Bar [Int] [Int] -- A List type class does not exist, so this cannot work instance List Bar where fromList x = Bar x x -- This does not work y = [1..10]::Bar So the only way to do this, is to create a constructor function like bar x = Bar x x which means the usage of lists in Haskell is not as general as numbers, in the sense one cannot take advantage of the builtin syntactic sugar of lists like [x,y,z] := x : (y : (z : [])) So if I would like to use this compact notation for e.g. creating a Set datatype, I would have to create special constructor functions (fromList or mkSet or whatever) Is this correct? If so, I'm sure a good reason must exist for this :) Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: HApps API Documentation?
Just compile your one version from the HAppS source. Use runghc Setup.hs haddock. OK, I can give that a shot. I'm still curious about my original question, though. Are there alternative online API docs for Happs? I am sorry I dont answer your question directly, but the last online api documentation I found was outdated anyway. I think it was one you mentioned. Someone ask Alex Jacobson? He is maintaining HAppS. I heard he wants to redesign certain aspects. Maybe he doesnt have time to update the older docs? HApps is a flagship of Haskell development, there should be people helping Alex especially with better tutorials and a nice and uptodate website... oh... well that could just be me. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
On Sep 2, 2007, at 2:08 , Peter Verswyvelen wrote: But after reading http://en.wikipedia.org/wiki/ Fifth_generation_computer, it seemed to me that Prolog was a dead language, having only pure theoretical purposes. Is this true? Tell that to the order pricing system I wrote in Prolog for a customer site in the early 90s. (Admittedly, I did eventually rewrite it in C.). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
On 9/2/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: in the early 90s I think I found the flaw in your argument ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
Sven Panne wrote: ... and even more easily hypothesize why this is not always a good indication: High-qualitiy standard libraries which are packaged with GHC/Hugs/... will probably almost never be downloaded separately. Solution: change GHC/Hugs so it submits usage counters of which libraries the user imports to a webservice, stored in a database ;-) Of course this is subject to the user accepting such a feedback, to protect it's privacy. Google does this all the time! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
One of standard exercices in Prolog is the construction of the meta-interpreter of Prolog in Prolog. While this is cheating, I recommend it to you. It opens eyes. Ever tried implementing Haskell in Haskell? ;-) Prolog strategies are straightforward, and I simply cannot understand the comments of Andrew Coppin. Which arbitrary set of conclusions?? Which patently obvious results not derivable?? Be kind, give some examples, otherwise people may suspect that you are issuing vacuous statements... Read my whole message. What I was saying (in essence) is that Prolog seemed to be performing impossible feats of logical deduction - until I saw a unification algorithm implemented in Haskell, and then it all made sense. (They showed an example where you basically program in a list of who is related to who, and then the computer suddenly seems to be able to magically deduce arbitrary family relationships - without any code for doing this being defined. This seemed utterly far-out to me... I'm not used to computers begin able to think for themselves. I'm more used to having them blindly follow whatever broken sequence of commands you feed to them... And yet, given a set of facts, this Prolog interpreter seemed to be able to magically derive arbitrarily complex conclusions from them. Double-impossible! Until I learned how it's implemented...) Having said all that, I still don't get what the purpose of the cut operator is. I also failed to understand the Prolog syntax description. (What the heck is an atom when it's at home? I thought an atom is a unit composed of protons and electrons...) I can certainly see why Prolog would be very useful for certain types of problems. As it happens, not the kind of problems that usually interest me. ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
Sven Panne wrote: ... and even more easily hypothesize why this is not always a good indication: High-qualitiy standard libraries which are packaged with GHC/Hugs/... will probably almost never be downloaded separately. Solution: change GHC/Hugs so it submits (via a webservice, stored in a database) usage counters of which libraries the user imports ;-) Of course this is subject to the user accepting such a feedback, to protect its privacy. Google does this all the time... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
Cut is a means of preventing backtracking beyond that point - it prunes the potential search space saying the answer must be built on the current set of bindings. (Lots of work went into how automatically get cut's into programs to make them efficient but without the programmer having to worry about them). Atoms: think unique symbols that are elements in the set which is the program's universe of discourse - one that is closed (no infinities there please). All its doing is unifying things to see if they fit the rules. It is one large parser that gives you back the bindings it made on the way. I do remember the day when a prologue researcher was fiercely defending that prologue could compute solutions to problems that were not achievable with ordinary turing complete languages - nothing as ugly as a rampaging mob of Computer Scientists! I've even written (late 80's) a program in prologue that performed real-time subtitling for the deaf, which I'm told is still being used out there. Would I use it now? - never - it may give you an answer but rarely does using it give you understanding and you can always code up the searching algorithms if you have to go that brute force. And in the end it is the understanding that is reusable, not the answer. Neil On 02/09/07, Andrew Coppin [EMAIL PROTECTED] wrote: One of standard exercices in Prolog is the construction of the meta-interpreter of Prolog in Prolog. While this is cheating, I recommend it to you. It opens eyes. Ever tried implementing Haskell in Haskell? ;-) Prolog strategies are straightforward, and I simply cannot understand the comments of Andrew Coppin. Which arbitrary set of conclusions?? Which patently obvious results not derivable?? Be kind, give some examples, otherwise people may suspect that you are issuing vacuous statements... Read my whole message. What I was saying (in essence) is that Prolog seemed to be performing impossible feats of logical deduction - until I saw a unification algorithm implemented in Haskell, and then it all made sense. (They showed an example where you basically program in a list of who is related to who, and then the computer suddenly seems to be able to magically deduce arbitrary family relationships - without any code for doing this being defined. This seemed utterly far-out to me... I'm not used to computers begin able to think for themselves. I'm more used to having them blindly follow whatever broken sequence of commands you feed to them... And yet, given a set of facts, this Prolog interpreter seemed to be able to magically derive arbitrarily complex conclusions from them. Double-impossible! Until I learned how it's implemented...) Having said all that, I still don't get what the purpose of the cut operator is. I also failed to understand the Prolog syntax description. (What the heck is an atom when it's at home? I thought an atom is a unit composed of protons and electrons...) I can certainly see why Prolog would be very useful for certain types of problems. As it happens, not the kind of problems that usually interest me. ;-) ___ 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] Learn Prolog...
Andrew Coppin writes: Ever tried implementing Haskell in Haskell? ;-) Seriously: Haskell is a *complicated* language, needing a parser, which by itself is a non-trivial exercice. Moreover, it has a type-inference engine, which may be simulated, sure, but Haskell in Haskell is a tough job. However, typing Haskell in Haskell is doable, see: http://citeseer.ist.psu.edu/424440.html The point is that Mark Jones is a well known Haskell guru, the creator of Gofer/Hugs, not an average student... Lisp/Scheme in Scheme is simpler, and is also a pretty standard exercice. Prolog is also from this perspective, very simple. Terms and clauses have the same syntax, the program, i.e., the database of assertions can be dynamically extended, etc. A real fun. Prolog strategies are straightforward, and I simply cannot understand the comments of Andrew Coppin. Which arbitrary set of conclusions?? Which patently obvious results not derivable?? Be kind, give some examples, otherwise people may suspect that you are issuing vacuous statements... Read my whole message. What I was saying (in essence) is that Prolog seemed to be performing impossible feats of logical deduction - until I saw a unification algorithm implemented in Haskell, and then it all made sense. (They showed an example where you basically program in a list of who is related to who, and then the computer suddenly seems to be able to magically deduce arbitrary family relationships - without any code for doing this being defined. This seemed utterly far-out to me... I'm not used to computers begin able to think for themselves. I'm more used to having them blindly follow whatever broken sequence of commands you feed to them... And yet, given a set of facts, this Prolog interpreter seemed to be able to magically derive arbitrarily complex conclusions from them. Double-impossible! Until I learned how it's implemented...) My deepest congratulations. It seems that you are the first person in my pedagogical life, who got acquainted with the unification through its implementation in Haskell. Gosh, why I gave to my students the assignment to construct an unifier in a functional language, when I was absolutely sure that they understood well the unification itself?... Actually, perhaps if you tried to do it otherwise, you *would* recognize that programs in Prolog do not think, but just constitute a database of clauses/terms, which undergo a sufficiently powerful pattern-matching. It is the only intelligence inside, helped by the logic protocol, different from the functional one, which ensures that a predicate in Prolog may treat *all* its parameters either as input or an output, while in Haskell this is fixed. Having said all that, I still don't get what the purpose of the cut operator is. Imagine that your life is a path through a tree. Depth first. At every branching you choose a branch, and you continue. When you are stuck, you remember that you have left a trail behind you, and you backtrack until the last choice point. Then you choose another path, the previous being marked as 'seen'. Well, the cut is a commitment. You cut your way back, Now, you must succeed, i.e., find a terminal node which gives you what you want, or your failure is definitive, you jump out of the system. There are hundreds of easy examples of cuts, e.g., when descending the tree consumes the ressources which cannot be restored. The cut is criticized sometimes as something not logical, a pragmatic device. OK. I also failed to understand the Prolog syntax description. (What the heck is an atom when it's at home? I thought an atom is a unit composed of protons and electrons...) Now, you are pulling my leg. An atom means that you cannot split it in constituents, this name came from Lisp into other languages, but the meaning comes from Democritus, who didn't know protons. I won't say more, just that if you want to be really funny, you should not forget neutrons. http://en.wikipedia.org/wiki/Atom also: http://en.wikipedia.org/wiki/Atom_%28standard%29 http://en.wikipedia.org/wiki/Prolog also: http://en.wikipedia.org/wiki/Democritus I can certainly see why Prolog would be very useful for certain types of problems. As it happens, not the kind of problems that usually interest me. ;-) Well, who am I or other readers to contradict it?... My point was that learning more than one language (and moreover, not so well) gives you a better perspective to learn the ESSENCE. Let's terminate by two citations from Democritus, who invented atoms: # Nature and instruction are similar; for instruction transforms the man.(DK 68 B 33) # If any man listens to my opinions, here recorded, with intelligence, he will achieve many things worthy of a good man, and avoid doing many unworthy things.(DK 68 B 35) == Jerzy Karczmarczuk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org
[Haskell-cafe] Array.Diff, strange oversight or myopia ?
Data.Array.Diff don't have an instance for DiffUArray Bool, which is strange by itself since IOUArray Bool exists and it's the only IOUArray that is not mirrored in Diff. But ok, why not, I guess it might be a small oversight, so I go on to create the missing instance IArray (IOToDiffArray IOUArray) Bool on the model of the instances in the source of Array.Diff. Ok, Diff exports readDiffArray, newDiffArray and replaceDiffArray for this exact purpose, seems it will be straightforward... except that boundsDiffArray is not exported and you can't rewrite it since it needs to take apart the DiffArrayData type which is not exported either ! So how can I do this (short of copying and renaming an alternative Array.Diff or changing the library in my installation of GHC) ? And is there something obvious I missed due to a sudden case of myopia ? -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
As to whether Prolog is dead or not, it depends on your definition of dead. Three years ago (not ten!) I made my living maintaining and developing a large application written in Prolog. That was actually an interesting experience, since one of the performance drivers was speed. As a result code was being perpetually tuned toward less non-determinism. You know what the limit is? Functional programming! At the time I did a little research looking for an FP language that was ready for prime time and for which the pain of the move for a large organization would have been acceptably low. Sadly, nothing came of it. I still think the application could have been profitably ported to a functional language. Recently I have been experimenting with ECLiPSe, a Constraint Logic Programming system embedded within standard Prolog. I found several of the problems in the Euler Project were perfect candidates for attack by constraint programming. Yes, I could have written solutions that implemented some sort of search strategy, but there is a legitimate question of leverage. For example, Sudoku puzzles are very naturally viewed as constraint programming problems. But why should I write my own solution when the Sudoku solver provided as a demo could solve 50 problems in 0.10 seconds! By the way, I could get a fairly good idea of the how and why of the problem nd its solution from the form of the demo code, and oh yes I had already written my own Sudoku solver on OCaml a year or so ago. To Jerzy's point -- I strongly believe that learning a language like Prolog is a good idea for two reasons -- first, it adds another tool to the programmer's toolkit, and second, it enlarges the programmer's view of ways to think about solving problems. -- Bill Wood ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] interaction between OS processes
Andrea Rossato wrote: Most likely, the content of s sits in a local buffer and never leaves this process, following most OS conventions and as others point out. Another process waiting for it will deadlock. Yes, I knew it was something related to the underneath OS. I'll have to study Unix seriously Your problem may be buffering-related (I haven't read your code to check), but if so, there's a fair likelihood that it has nothing to do with the OS. GHC's runtime does its own buffer management on Handles. It's quite possible that your deadlock lies at that level, rather than anything lower. Are you calling hFlush after writing to your pipe? b ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
[EMAIL PROTECTED] wrote: Andrew Coppin writes: Ever tried implementing Haskell in Haskell? ;-) Seriously: Haskell is a *complicated* language, needing a parser, which by itself is a non-trivial exercice. It looks so simple on the surface... [Actually, so does cold fusion.] Read my whole message. What I was saying (in essence) is that Prolog seemed to be performing impossible feats of logical deduction - until I saw a unification algorithm implemented in Haskell, and then it all made sense. My deepest congratulations. It seems that you are the first person in my pedagogical life, who got acquainted with the unification through its implementation in Haskell. Heh. Well. It took a *long* time, mind you... (BTW, that's a really rather good book, that.) Having said all that, I still don't get what the purpose of the cut operator is. Imagine that your life is a path through a tree. Depth first. At every branching you choose a branch, and you continue. When you are stuck, you remember that you have left a trail behind you, and you backtrack until the last choice point. Then you choose another path, the previous being marked as 'seen'. Well, the cut is a commitment. You cut your way back, Now, you must succeed, i.e., find a terminal node which gives you what you want, or your failure is definitive, you jump out of the system. There are hundreds of easy examples of cuts, e.g., when descending the tree consumes the ressources which cannot be restored. So... it's the opposite of Parsec's try combinator? I also failed to understand the Prolog syntax description. (What the heck is an atom when it's at home? I thought an atom is a unit composed of protons and electrons...) Now, you are pulling my leg. An atom means that you cannot split it in constituents, this name came from Lisp into other languages, but the meaning comes from Democritus, who didn't know protons. I won't say more, just that if you want to be really funny, you should not forget neutrons. Well, true. But they're so neutral! They don't even affect the chemical properties of the atom, only its physical ones. ;-) [Actually, I'm told this isn't *quite* true. For example, heavy water is mildly toxic due to the atom radius being slightly different or something which means that some enzyme somewhere doesn't quite work properly any more, or similar...] But anyway, I usually find that language syntax descriptions are written for maximum crypticness... This is presumably to enhance the idea that only extremely intelligent people can understand it or something. I can certainly see why Prolog would be very useful for certain types of problems. As it happens, not the kind of problems that usually interest me. ;-) Well, who am I or other readers to contradict it?... My point was that learning more than one language Do you have Any Idea how many programming languages I've learned and used in my life so far? (Hint: lots.) ;-) [Hell, I was bored one day so I learned PostScript in my lunch break... Most normal people don't do that.] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC-API: a few questions
Hi, I'm trying to acquire some confidence with the GHC-API and I'm having some problems, related to error handling, I seem not be able to solve. Basically there are 3 functions to (interactively) compile/run Haskell expressions: compileExpr, dyCompileExpr and runStmt. The first 2 will return the value of the compiled expression, as a Maybe HValue the first, and a Maybe Dynamic the second, while the third can bind names and report them, or report exceptions. But my problem is related to the first two. I run expressions (string_expression) wrapped around some let x = string_expression in take 2048 (show x) to avoid infinite list or loops. According to the documentation one should be able to control how error messages are dealt with, by manipulation the GHC session's state. One component of the session state, indeed, is the log_action which, by default, prints errors and warnings to the standard error (compiler/main/DynFlags.hs). Now, no matter what I do, I seem not to be able to change the log_action to collect error messages and warnings. In any case everything seem to be printed to standard error. This way I can only collect exceptions raised by the compiler. For instance: Prelude.last: empty list for string_expression = last [] But if my expression raises a type error, this is printed to stderr. Like in the case of string_expression = last which would produce a No instance for (Show ([a] - a)) What am I doing wrong? Thanks for your kind attentions. Andrea ps: there are quite a lot of other questions I'd like to ask about some programming techniques I've seen applied in GHC. For instance, sometime a list of actions is given as a string, to be compiled to a HValue which is written to a IORef. Running those actions is just a matter of reading the IORef (you can see this in compiler/ghci/InteractiveUIhs, when it comes to buffer management. For instance: flushInterpBuffers). I ask to myself: Why? Just to amaze the reader? ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
Sooo.. what is the modern equivalent of Prolog? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
Hugh Perkins writes: Sooo.. what is the modern equivalent of Prolog? Well, first, I wouldn't agree entirely that Prolog is not modern. Anyway... If you want something wih more bells and whistles, modularity, coroutining, more security (less power, e.g. no program auto-modification), etc., - see Mercury. http://www.cs.mu.oz.au/research/mercury/information/features.html http://en.wikipedia.org/wiki/Mercury_(programming_language) http://www.cs.kuleuven.ac.be/~dtai/projects/ALP/newsletter/archive_93_96/net /systems/mercury1.html and also: http://lambda-the-ultimate.org/node/890 Perhaps somebody can say more about constraint languages which replaced Prolog in some contexts as well. Have fun. Jerzy Karczmarczuk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Extending the idea of a general Num to other types?
You're right. The list syntax is only for lists in Haskell. It would be nice if the list syntax was overloaded too. You can overload numeric literals (by defining fromInteger) and string literals (by defining fromString, in 6.7). BTW, the [1..10] syntax is overloaded, you need an Enum instance. -- Lennart On 9/2/07, Peter Verswyvelen [EMAIL PROTECTED] wrote: Chaddaï Fouché wrote: You can indeed already do that, except it won't be a single instance since list have a bucketful of interesting properties. A good starting is looking at what list is an instance of and trying to identify the set of instance which interest us in this case, Foldable and Functor are probably a good start, embodying most of the interesting way to access a data structure as a list (head and tail don't really make sense for most of the alternatives, except other sequence library which currently provide this functionality in an ad-hoc way, see Sequence and ByteString for example of that). An alternative is Traversable. Thanks! But before digging into this, maybe I should rephrase myself by giving a more specific (although useless) example of what I mean. When I write: data Foo = Foo Int Int deriving (Show,Eq) instance Num Foo where fromInteger x = Foo x' x' where x' = fromInteger x _ + _ = error Not relevant for example _ * _ = error Not relevant for example abs _ = error Not relevant for example signum _ = error Not relevant for example x = 42::Foo I don't have to apply the Foo data constructor to lift the number 42 because I guess the compiler has builtin support for calling fromInteger (or fromRational). I even don't have to add the type annotation most of the time when the compiler can infer the type needed, which is very cool, sometimes a bit annoying. However, now I try the same for lists data Bar = Bar [Int] [Int] -- A List type class does not exist, so this cannot work instance List Bar where fromList x = Bar x x -- This does not work y = [1..10]::Bar So the only way to do this, is to create a constructor function like bar x = Bar x x which means the usage of lists in Haskell is not as general as numbers, in the sense one cannot take advantage of the builtin syntactic sugar of lists like [x,y,z] := x : (y : (z : [])) So if I would like to use this compact notation for e.g. creating a Set datatype, I would have to create special constructor functions (fromList or mkSet or whatever) Is this correct? If so, I'm sure a good reason must exist for this :) Thanks, Peter ___ 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] Ideas
On Saturday 25 August 2007 20:49, Andrew Coppin wrote: [...] Would be nice if I could build something in Haskell that overcomes these. OTOH, does Haskell have any way to talk to the audio hardware? Depending on what you are exactly trying to do, the OpenAL/ALUT packages might be of interest. Slighty dated online docs are here: http://haskell.org/HOpenGL/newAPI/OpenAL/Sound-OpenAL.html http://haskell.org/HOpenGL/newAPI/ALUT/Sound-ALUT.html Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] interaction between OS processes
Bryan O'Sullivan wrote: Your problem may be buffering-related (I haven't read your code to check), but if so, there's a fair likelihood that it has nothing to do with the OS. GHC's runtime does its own buffer management on Handles. It's quite possible that your deadlock lies at that level, rather than anything lower. Although GHC's runtime kind of re-invents buffering, it still follows the Unix convention, i.e., if stdio is determined to be attached to a tty, then default to line buffering, else default to block buffering. Indeed, I wager that it bothers to re-invent buffering because of some other technical necessity (green-threading comes to mind), and if it goes out of its way to re-invent buffering, why, of all conceivable conventions, the Unix convention again? E.g., why not take this opportunity to spare beginners a nasty surprise and default to line buffering across the board? It seems to me clearly that the answer is precisely to spare the Unix-informed programmers a nasty surprise. Therefore although GHC's runtime does its own buffering, a Unix education still informs you of what it does. The problem is the same and the solution is the same. Even taking a step back, even if GHC or some other Haskell runtimes or some other language runtimes or even other VMs and OSes do not follow the Unix convention, a Unix course still serves to alert you of buffering issues, that buffering can be weird, that the OS does its weird buffering, that a language runtime may or may not add yet its weird buffering... You will develop a habit of double-checking with the docs and testing, not a habit of just assuming that what you see on a tty is what you get on a pipeline. Along the way, you will also see why getChar waits for a newline (and why sometimes even a newline doesn't suffice)... It is similar to saying, if you use a high-level language on x86, you don't have to learn low-level 680x0. Ah, but knowing low-level 680x0 informs you of certain issues of the high-level language (e.g., performance) and how to use it more successfully. This is despite 680x0 is not the x86 you use. It is similar to saying, if you use Haskell, you don't have to learn dependent typing. Ah, but knowing dependent typing informs you of certain typing issues and how to use the Haskell type system more successfully. This is despite tutorials on dependent typing talk about Clean or Coq rather than the Haskell you use. It is similar to saying, if you use Java and C#, you don't have to learn Haskell. Ah, but knowing Haskell informs you of certain programming issues and how to use Java and C# more successfully. This is despite Haskell does not talk about objects. It is education and personal growth. It is not just vocational training. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] interaction between OS processes
Albert Y. C. Lai wrote: It is similar to saying, if you use Haskell, you don't have to learn dependent typing. Ah, but knowing dependent typing informs you of certain typing issues and how to use the Haskell type system more successfully. This is despite tutorials on dependent typing talk about Clean or Coq rather than the Haskell you use. s/Clean/Cayenne/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.6.1 and SELinux issues
On Wed, Aug 29, 2007 at 01:03:56PM -0700, Stefan O'Rear wrote: So it is not clear if GHC does really need this PROT_EXEC. Can someone familiar with GHC internals answer why PROT_EXEC is used in getMBlocks? It's not possible to correctly implement 'foreign import ccall wrapper' without self-modifying code on any mainstream computer architecture. Does this program work on your no-PROT_EXEC ghc? : {-# OPTIONS_GHC -ffi #-} import Foreign foreign import ccall wrapper wrap :: IO () - IO (FunPtr (IO ())) foreign import ccall dynamic call :: FunPtr (IO ()) - IO () main = call = wrap (print hi!) Thanks, that is exactly what I asked for. This program compiles with my no-PROT_EXEC ghc, but doesn't work: $ ghc -o 1 1.hs $ ./1 1: internal error: makeExecutable: failed to protect 0x0x2b115597e000 (GHC version 6.6.1 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted $ The errors comes from rts/posix/OSMem.c, function setExecutable which tries to mprotect block of memory with PROT_EXEC and PROT_WRITE. What is so special about wrapper and dynamic functions? I've never used Haskell FFI, but I've heavily used Python-C interface and Ocaml-C interface, calling both C from Ocaml and Ocaml from C and even Ocaml from Python via C and etc. It all worked fine without any runtime code generation or self-modifying code. Can you please give some ideas how self-modifying code can be used in FFI implementation? With best regards, Alexander. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
Hugh Perkins wrote: A really simple way to track the quality of a package is to display the number of downloads. A posteriorae, this works great in other download sites. We can easily hypothesize about why a download count gives a decent indication of some measure of quality: - more people downloading it means more people specifically wanted that package - more people downloading it means more people trying it, giving feedback, maybe giving patches - and, of course, it's an objective measure, easy to do I don't agree. The idea that any arbitrary objective measure provides any indication quality seems quite wrong to me, especially this one. The problem is the effect of positive feedback. The popularity of MS Winders or Office Suite are the obvious examples. We all know why these are used on 95% or whatever of the worlds PCs, and it has nothing whatever to do with quality. Or a little closer to home, the popularity of Haskell vs. Clean. Other meaningless measures that have been suggested are the rate of patch submissions of the number of developers involved. I seem to remember someone recently suggesting that libraries that score highly in on this regard should be elevated to blessed status. I cynic like me could just as well regard this as an indication of the complete opposite, that the library was being developed by an uncoordinated troop of barely competent code monkeys desperately trying to produce something that works reliably by a process of trial and error :-) Personally the first things I tend to look at are things like the quality of documentation and the presence of of some kind of test suite. Both these are IMO opinion pretty reliable indications that the author(s) have actually devoted some time and effort into deciding what it is that the library aims to achieve and have designed a coherent API (and have made reasonable effort to ensure that it actually works). I tend lose interest pretty fast if even basic Haddock API documentation is either non-existant, or consists of nothing but type signatures, or that plus broken link to some ancient postscript paper. Regards -- Adrian Hey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Extending the idea of a general Num to other types?
Snif, this is sad... :-( Oh well, maybe this gets improved in Haskell Prime ;-) Lennart Augustsson wrote: You're right. The list syntax is only for lists in Haskell. It would be nice if the list syntax was overloaded too. You can overload numeric literals (by defining fromInteger) and string literals (by defining fromString, in 6.7). BTW, the [1..10] syntax is overloaded, you need an Enum instance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
Jerzy Karczmarczuk wrote Perhaps somebody can say more about constraint languages which replaced Yes please! Of example, how correct is http://en.wikipedia.org/wiki/Constraint_programming? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
2007/9/2, Adrian Hey [EMAIL PROTECTED]: Other meaningless measures that have been suggested are the rate of patch submissions of the number of developers involved. I seem to remember someone recently suggesting that libraries that score highly in on this regard should be elevated to blessed status. I don't see them as completely meaningless, such a library is more likely to be corrected if you report a bug, and if a library lacks certain features but seems interesting, I'm less inclined to give it a chance if nobody worked on it for years than if there's an active community, frequent update and a roadmap. Still it's not sufficient, I agree with you. Personally the first things I tend to look at are things like the quality of documentation and the presence of of some kind of test suite. Both these are IMO opinion pretty reliable indications that the author(s) have actually devoted some time and effort into deciding what it is that the library aims to achieve and have designed a coherent API (and have made reasonable effort to ensure that it actually works). I tend lose interest pretty fast if even basic Haddock API documentation is either non-existant, or consists of nothing but type signatures, or that plus broken link to some ancient postscript paper. Yes, those are some of the more interesting metrics, the CPAN try to take them into account with the recent Kwalitee metric. Thing is we probably won't find _the best_ metric (if such a thing existed, I think it will already have been found) but we can try to give some useful indications. -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Learn Prolog...
Hugh Perkins wrote: Sooo.. what is the modern equivalent of Prolog? I once learned about LIFE (Logic, Inheritance, Functions, and Equations) and was deeply fascinated. However, it died the quick death of most research languages. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell as an extension language
Off-topic, so stop reading now if you want ;-) , but reminds me of my experience using Python and C++. Python and C++ are both great languages, with their own strengths, and one might think that combining thing gets the best of both. However, using Swig etc to join Python to C++ takes a significant amount of time, and one needs project members now to learn two languages. Then I discovered a different language (not Haskell) that combined the ease of Python with the speed of C++. It's really a big advantage. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
On Sun, 2007-09-02 at 22:52 +0800, Hugh Perkins wrote: Sooo.. what is the modern equivalent of Prolog? Because no one has said it quite this way: The modern equivalent of Prolog is Prolog. Most of the advancement in logic programming has either been folded back into Prolog or has been advanced within Prolog. There are, for example, constraint systems as add-ons to various Prolog implementations. The theory of logic programming, however, has massively advanced beyond Prolog producing languages much, much more beautiful than Prolog (not hard...). Unfortunately, they have not been made into practical languages, at least not successfully. I'm not aware of any real competitors to Prolog in the logic programming languages space. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Definition of the Haskell standard library
On 9/3/07, Adrian Hey [EMAIL PROTECTED] wrote: The popularity of MS Winders or Office Suite are the obvious examples. We all know why these are used on 95% or whatever of the worlds PCs, and it has nothing whatever to do with quality. Oh come on. You've been reading waaayyy too much Slashdot... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
On 9/3/07, Derek Elkins [EMAIL PROTECTED] wrote: Because no one has said it quite this way: The modern equivalent of Prolog is Prolog. Ok, thanks. Just wanted to check that. (btw, just thought, when I was talking about FFI, probably meant Forth, not Prolog. FFI for Prolog probably isnt that important.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
On Mon, 2007-09-03 at 07:43 +0800, Hugh Perkins wrote: On 9/3/07, Derek Elkins [EMAIL PROTECTED] wrote: Because no one has said it quite this way: The modern equivalent of Prolog is Prolog. I was just about to say the same thing :-); thanks, Derek. . . . (btw, just thought, when I was talking about FFI, probably meant Forth, not Prolog. FFI for Prolog probably isnt that important.) No, Foreign Function Interfaces are as useful with Prolog as with any other high-level language. (BTW I thought the FFI for Forth was the Forth assembler; have things changed since FIG/F83?) I just did a fast scan and found that XSB and SWI Prolog seem to be still quite active. If you have a few bucks (or euros) sicstus is also available. I was quite satisfied with XSB, though my experience is somewhat dated now. It is somewhat idiosyncratic (they're talking about getting closer to ISO Prolog with their latest release). I have also had good results with SWI. Both of them support some CLP libraries. GNU Prolog is also out there, but I don't know how active development is (please, I said I don't know, not that I thought it was becoming moribund). I've used it a little. It also comes with something of a CLP library. It looks like you can get an individual license for sicstus for ca. 155 euros. I used it a lot about three years ago and it seemed to be quite stable, had good performance, and we received good support. Of course we were a big corporate customer. Prolog seems to be quite alive and kicking. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn Prolog...
(BTW I thought the FFI for Forth was the Forth assembler; have things changed since FIG/F83?) I didnt have a real PC, just a ZX Spectrum. It wasnt real Forth, just Spectrum Forth. It was kindof fun, but a little disappointing not to be able to do anything useful with it. Well, I wanted to write space invaders on it, but not being able to write characters to arbitrary points on the screen was a bit of a show-stopper for that ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.6.1 and SELinux issues
Alexander Vodomerov wrote: On Wed, Aug 29, 2007 at 01:03:56PM -0700, Stefan O'Rear wrote: [snip] What is so special about wrapper and dynamic functions? Can you please give some ideas how self-modifying code can be used in FFI implementation? It's not self-modifying code really, it's dynamically generated code. Here is a small complete example for illustration: V.hs import Foreign import Foreign.C foreign import ccall wrapper mkCallback :: (CInt - CInt) - IO (FunPtr (CInt - CInt)) foreign import ccall v.h foo c_foo :: FunPtr (CInt - CInt) - IO CInt main = do add_21 - mkCallback (+21) c_foo add_21 = print v.c #include v.h int foo(callback_t fun) { return fun(fun(0)); } v.h typedef int (* callback_t)(int); int foo(callback_t fun); (compile with ghc -ffi V.hs v.c) This program takes a function that adds 21 to a CInt, wraps it into a C function pointer of type callback_t, and then calls this function from the C side two times; it prints 42. In particular, the wrapper mkCallback takes any *Haskell* function of type CInt - CInt and returns a *C* function pointer that represents the same function. Note that this function receives no additional context in its arguments. This is convenient but it means that each call to mkCallback has to return a different function pointer, so it is necessary to generate a small piece of code dynamically to implement it. HTH, Bertram ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Bi-directional Maps
Just noticed, erlang has the second kind of bimap (a bijection?) built into each process: From http://www.erlang.org/doc/reference_manual/processes.html : 10.9 Process Dictionary Each process has its own process dictionary, accessed by calling the following BIFs: put(Key, Value) get(Key) get() get_keys(Value) erase(Key) erase() That's interesting. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] APLAS07 - Call for Participation
Call for Participation The Fifth Asian Symposium on Programming Languages and Systems November 29 - December 1, 2007 Singapore http://www.comp.nus.edu.sg/~aplas07/ http://flint.cs.yale.edu/aplas2007/ Scope of the Conference --- APLAS aims at stimulating programming language research by providing a forum for the presentation of recent results and the exchange of ideas and experience in topics concerned with programming languages and systems. APLAS is based in Asia, but is an international forum that serves the worldwide programming languages community. The APLAS series is sponsored by the Asian Association for Foundation of Software (AAFS), which has recently been founded by Asian researchers in cooperation with many researchers from Europe and the USA. The past formal APLAS symposiums were successfully held in Sydney (2006, Australia), Tsukuba (2005, Japan), Taipei (2004, Taiwan) and Beijing (2003, China) after three informal workshops held in Shanghai (2002, China), Daejeon (2001, Korea) and Singapore (2000). Proceedings of the past symposiums were published in Springer-Verlag's LNCS 2895, 3302, 3780, and 4279. Conference Location --- APLAS'07 will be held at Kent Ridge Guild House, National University of Singapore. Singapore is a dynamic city rich in contrast and color where you'll find a harmonious blend of culture, cuisine, arts and architecture. A bridge between the East and the West for centuries, Singapore, located in the heart of fascinating Southeast Asia, continues to embrace tradition and modernity today. Brimming with unbridled energy and bursting with exciting events, the city offers countless unique, memorable experiences waiting to be discovered. Registration The early registration deadline is set on 28Sept07. The registration fees will cover conference proceeding, banquet dinner, and lunches/teas. Deadline Full Fees Student Fees early28Sep07 S$600 S$400 online 23Nov07 S$650 S$425 on-site 29Nov07 S$700 S$450 Payment can be made with credit cards. Exchange rate (subject to fluctuation) is approx. US$1 = S$1.53 Online registration can be made at: http://www.comp.nus.edu.sg/~aplas07/local.html#registration Accommodation - A special rate S$155 per nite (excluding taxes but inclusive of daily breakfast) is applicable to attendees of APLAS 2007 at Rendezvous Hotel Singapore: http://www.rendezvoushotels.com/singapore/ The hotel is located in city center. A free daily shuttle bus will be provided between this hotel and the conference site (at NUS) during the conference period. Our block of rooms is guaranteed till 28Sept07, so advanced booking is encouraged as some rooms may be released after this date. For reservation, please use a special form that can be found at: http://www.comp.nus.edu.sg/~aplas07/Hotel.APLAS07.pdf We have also reserved a limited number of cheaper twin/double shared rooms (S$280 for 4-nights) on NUS campus. Priority will be given to students and poster participants. Deadline for application is 20Sep07. Details will be given on our web in early Sept. Poster Session -- APLAS07 will include a poster session. Submission deadline is 14 Sept 2007. For details, please see: http://www.comp.nus.edu.sg/~aplas07/posters.html Conference Program -- 29 Nov (Thu) 915- 930 Opening note 930-1030 Invited Talk X10: Programming Parallel Machines, Productively Vijay Saraswat (IBM TJ Watson Research Lab) 1100-1230 Session 1 The Nuggetizer: Abstracting Away Higher-Orderness for Program Verification Paritosh Shroff (Johns Hopkins University), Christian Skalka (University of Vermont) and Scott F. Smith (Johns Hopkins University) Local Reasoning for Storable Locks and Threads Alexey Gotsman (University of Cambridge), Josh Berdine (Microsoft Research), Byron Cook (Microsoft Research), Noam Rinetzky (Tel Aviv University) and Mooly Sagiv (Tel Aviv University) Monadic, Prompt Lazy Assertions in Haskell Frank Huch (CAU Kiel) and Olaf Chitil (University of Kent) 1345-1515 Session 2 Translation Correctness for First-Order Object-Oriented Pattern Matching Burak Emir (EPFL Lausanne), Qin Ma (OFFIS) and Martin Odersky (EPFL Lausanne) Persistent Oberon: A Programming Language with Integrated Persistence Luc Blaser (ETH Zurich) More Typed Assembly Languages for Confidentiality Dachuan Yu (DoCoMo Communication Laboratories USA) 1515-1630 Poster Session 1630-1730 Session 3 A Novel Test Case Generation