Re: [Haskell-cafe] Question about kinds
On Fri, 2008-06-06 at 15:41 -0700, Klaus Ostermann wrote: Why does the code below not pass the type checker? If I could explictly parameterize y with the type constructor Id (as e.g. in System F), then 'y Id' should have the type Int - Int and hence y Id x should be OK, but with Haskell's implicit type parameters it does not work. So, how can I make this work? Klaus type Id a = a x :: Id Int x = undefined y :: (a Int) - (a Int) y = undefined test = y x Error: Couldn't match expected type `a Int' against inferred type `Id Int' In the first argument of `y', namely `x' In the expression: y x In the definition of `test': test = y x Down this path is higher-order unification which is undecidable. You can use a newtype. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Teaching Monads
Monads in Haskell are a topic that I, like most beginners, find difficult and mind-twisting. Now that I think I understand monads, they seem to be very simple; I've read that this is a common experience. So I wonder, what would it take to help beginners catch on with a minimum of fuss or frustration? The plethora of monad tutorials out there is clear evidence that plenty of others have wondered the same thing. What made monads click for me is when I understood the following things: 1. When monads are being used, closures are almost always involved. 2. These closures naturally arise when desugaring do-syntax. do x1 - m1 m1 = (\x1 - x2 - m2 m2 = (\x2 - [Eq1] x3 - m3 m3 = (\x3 - return (f x1 x2 x3)return (f x1 x2 x3 3. These closures are extremely similar to the closures that arise when desugaring let-syntax. let x1 = f1 inf1 -$ (\x1 - Where: let x2 = f2 in f2 -$ (\x2 - (-$) :: a - (a - b) - b let x3 = f3 inf3 -$ (\x3 - x -$ f = f x f x1 x2 x3 f x1 x2 x3))) 4. While I can think of a monad as a fancy container that holds an element of type t, it might be more accurate to think of a monad as a container that merely displays the type t as a label for its contents. The container might hold one object of type t, or it might hold several. It might not be holding any at all. Perhaps the container /never/ holds an object of type t, but instead it holds a set of instructions to produce such an object. (e.g. Reader, State). Naturally, it's hard to illustrate nested closures, higher-order functions, and objects that aren't really there. It's easy to illustrate a sequential scheme where a single thing passes through a series of operations, while some related data travels in parallel. m1 = f1 = f2 = f3[Eq2] In any case, the extreme similarity between desugared do and desugared let leads me to think of the concepts of a manual plumbing system and a monadic plumbing system. Basically, a manual plumbing system is what I have if I'm threading information down through a series of nested function calls in a certain stereotypical way. A monadic plumbing system is what I get when I introduce the appropriate monad to encapsulate my threading. In fact, if I look at Wadler [*], there are three examples of an evaluator that use what I'm calling manual plumbing. In section 2.5, the operations required of a monad (return, bind) pretty much just drop right out. Wadler even points out the similarity between bind and let. Now that I finally get it, I feel that the Wadler paper, section 2.5 in particular, is probably a better introduction than many of the monad tutorials out there. Moreover, I feel that for /some/ of the tutorials out there, they spend too much time and too many illustrations explaining things like [Eq2], and then they quickly present do-notation and gloss over [Eq1]. For me, I found that that the concepts of manual plumbing and monadic plumbing were key to actually grasping the Wadler paper and understanding what monads are. In particular, I feel that these two concepts might be a way to help other beginners catch on as well. OK, so before I attempt to write a monad tutorial based on manual plumbing and monadic plumbing, I would like to know, does anyone else think this is a good idea? [*] Monads for Functional Programming. (http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Vancouver Haskell users meeting
I'll try to keep this going. I think it's a good idea. See you in the fall! Jon Asumu Takikawa wrote: Hi. I'd be interested in a meeting like this, but unfortunately since UBC is done for winter term I'm out of Canada for the summer. If anyone organizes a meet-up come fall I'd happily attend. Cheers, AT On 12:48 Mon 02 Jun , Jon Strait wrote: Anyone else here from Vancouver (Canada)? I thought it would be great to have a little informal get-together at a local cafe and share how we're currently using Haskell, or really anything (problems, comparisons, useful software tools, etc.) in relation to Haskell. I'm scheduling a meeting for this Thursday, June 5th. for 7PM at [1]Waazubee Cafe. (At Commercial Dr. and 1st Ave.) They have wireless internet access. I'll get a table near the back, bring my laptop, and will have a copy of Hudak's SOE book (the front cover is impossible to miss) out on the table. If anyone wants to meet, but this Thursday is not a good day for you, let me know what days are better and we'll move the meeting. If anyone is sure that they will come this Thursday, you might let me know, so I can have an idea about the resistance in changing the day, if needed. Thanks, Jon References 1. http://www.waazubee.com/content/directions.php ___ 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] Question about kinds
On Fri, Jun 6, 2008 at 4:41 PM, Klaus Ostermann [EMAIL PROTECTED] wrote: type Id a = a x :: Id Int x = undefined y :: (a Int) - (a Int) y = undefined In a Int, a refers to any type constructor, not any type function. So the best you can do is: newtype Id a = Id a -- rest as before Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about kinds
On Fri, Jun 06, 2008 at 03:41:07PM -0700, Klaus Ostermann wrote: Why does the code below not pass the type checker? If I could explictly parameterize y with the type constructor Id (as e.g. in System F), then 'y Id' should have the type Int - Int and hence y Id x should be OK, but with Haskell's implicit type parameters it does not work. The type of 'Id' is expanded to simply 'Int', and 'Int' does not unify with 'm a' for any type constructor 'm': Haskell's type level functions are always unevaluated (type synonyms don't count: they are always expanded). So, if you wanted to to this, you'd need to do newtype Id a = Id a Of course, now your values need to be tagged as well. Edsko ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about kinds
type declarations are not first-class; treat them more like macro expansions. In particular, you cannot make a function polymorphic over a type declaration. You can make this typecheck using a data or newtype declaration for Id: newtype Id x = Identity x (or) data Id x = Identity x You do need to wrap/unwrap the Identity constructor then. -- ryan On Fri, Jun 6, 2008 at 3:41 PM, Klaus Ostermann [EMAIL PROTECTED] wrote: Why does the code below not pass the type checker? If I could explictly parameterize y with the type constructor Id (as e.g. in System F), then 'y Id' should have the type Int - Int and hence y Id x should be OK, but with Haskell's implicit type parameters it does not work. So, how can I make this work? Klaus type Id a = a x :: Id Int x = undefined y :: (a Int) - (a Int) y = undefined test = y x Error: Couldn't match expected type `a Int' against inferred type `Id Int' In the first argument of `y', namely `x' In the expression: y x In the definition of `test': test = y x ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-Cafe] Quick question for a slow program
Hello, I was just brushing my haskell-fu skills writing a solution for Google Treasure Hunt Problem 4. Hers is what it looks like: primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] sumOf n l = sum (take n l) : sumOf n (tail l) find l = foldl1 aux l where aux (x:xs) (y:ys) | x == y = x : aux xs ys | x y = aux xs (y:ys) | x y = aux (x:xs) ys puzzle = find (reverse [primes, p7, p17, p41, p541]) where p7 = sumOf 7 primes p17 = sumOf 17 primes p41 = sumOf 41 primes p541 = sumOf 541 primes main = do mapM (\x - putStrLn $ show x) puzzle While the code is quite readable and straight forward it is as slow as tortoise with four legs broken. What optimizations would you suggest, while still keeping the code clear and highlevel? Thank you in advance. Cheers. -- Slavomir Kaslev ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about kinds
short answer: use newtype instead of type (and check the language spec for the difference between the two). Why does the code below not pass the type checker? because of the type error?-) seriously, though, it is useful to accompany such questions with some indication of what you're trying to do, to put a cap on the wide variety of possible answers (depending on what it is you're trying to achieve, there are many different techniques or tricks that might apply), and to have something to compare the non-working code against (also in case the intention needs to be edited before working code can be suggested). If I could explictly parameterize y with the type constructor Id (as e.g. in System F), then 'y Id' should have the type Int - Int and hence y Id x should be OK, but with Haskell's implicit type parameters it does not work. schemes that rely on implicit 'Id' tend to be doomed to failure in haskell and often suggest a need to get better acquainted with the limitations of haskell's type system (such schemes often arise from invalid generalisations of promising features, and many of us, myself included, have fallen into that trap at one point or other, often while working with type constructor classes): - type synonyms are syntactic macros, not part of the type system proper; the error message is a bit confusing by trying to be helpful (giving type synonym applications instead of their expansion: the type system has seen 'Int', not 'Id Int') - things of kind (* - *) are type _constructors_, not arbitrary type functions - type families are a restricted kind of type function, but can only be applied forwards (F t1 ~ t2), not be inferred or abstracted over simplified, if the type system had to _infer_ 'Id' (or the composition of type constructors, a related favourite;-), it could do so anywhere, any number of times. in haskell's approach to this, programmers have to indicate where such things are meant to occur (eg, by using newtypes). hth, claus So, how can I make this work? Klaus type Id a = a x :: Id Int x = undefined y :: (a Int) - (a Int) y = undefined test = y x Error: Couldn't match expected type `a Int' against inferred type `Id Int' In the first argument of `y', namely `x' In the expression: y x In the definition of `test': test = y x -- View this message in context: http://www.nabble.com/Question-about-kinds-tp17701553p17701553.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Patrick Perry's BLAS package
Patrick Perry wrote: Xiao-Yong Jin wrote: Apart from some warnings, the library compiles fine in my system. But there is a minor issue about the library it links against when `./Setup test'. I need to use `-lcblas' instead of `-lblas' to get it to link to correct libraries. I don't know other people's system. But in my system, Gentoo Linux, I use blas library provided by atlas, and libblas.so is a fortran library and libcblas.so is for C. I don't know of a good way to get around this. It seems like every system has a different convention for the location and name of the cblas libraries. So, everyone has to edit the extra-libraries and the extra-lib-dirs field in the blas.cabal file. Does anyone know of a better way of doing this? A possible solution is using flags in the cabal configuration file. For instance, I have this in hmatrix.cabal: if flag(mkl) if arch(x86_64) extra-libraries: gsl mkl_lapack mkl_intel_lp64 mkl_sequential mkl_core else extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core else extra-libraries: gsl blas lapack so if I want to link with Intel's MKL optimized blas/lapack instead of ATLAS I simply add the -fmkl flag: runhaskell Setup.lhs configure -fmkl etc. or even cabal install hmatrix -fmkl Other flags can be added to support different distributions. We could have something like cabal install package -ffedora or cabal install package -fcblas etc. Alberto ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Fri, Jun 6, 2008 at 8:35 PM, Andrew Coppin [EMAIL PROTECTED] wrote: import Text.ParserCombinators.Parsec as P Now I only have to write P.runPaser, which is much shorter. Or maybe even import Text.ParserCombinators.Parsec as Parser and then `Parser.run'. Having the module hierarchy be shallower so you don't have to add a `as' to every import might also help. I think Python does this better for common modules which have short and sweet name lite `system'. Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Mersenne Build Problem
I'm getting errors (see below) trying to build the tests in http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mersenne-random-0.1.1 I built the package itself using ./Setup configure -f use_sse2 I thought I had an intel core duo (also see below). I think I may be missing a library but I'm not sure which one. Thanks, Dominic. [EMAIL PROTECTED]:~/mersenne-random-0.1.1 cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : Intel(R) Core(TM)2 Duo CPU E4500 @ 2.20GHz stepping: 13 cpu MHz : 1200.000 cache size : 2048 KB physical id : 0 siblings: 2 core id : 0 cpu cores : 2 fdiv_bug: no hlt_bug : no f00f_bug: no coma_bug: no fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est tm2 ssse3 cx16 xtpr lahf_lm bogomips: 4392.14 clflush size: 64 processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : Intel(R) Core(TM)2 Duo CPU E4500 @ 2.20GHz stepping: 13 cpu MHz : 1200.000 cache size : 2048 KB physical id : 0 siblings: 2 core id : 1 cpu cores : 2 fdiv_bug: no hlt_bug : no f00f_bug: no coma_bug: no fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est tm2 ssse3 cx16 xtpr lahf_lm bogomips: 4388.99 clflush size: 64 [EMAIL PROTECTED]:~/mersenne-random-0.1.1/tests make ghc -O2 -ddump-simpl-stats -no-recomp Unit.hs --make [1 of 1] Compiling Main ( Unit.hs, Unit.o ) FloatOut stats: 154 Lets floated to top level; 35 Lets floated elsewhere; from 40 Lambda groups FloatOut stats: 133 Lets floated to top level; 14 Lets floated elsewhere; from 34 Lambda groups Grand total simplifier statistics Total ticks: 8378 2022 PreInlineUnconditionally 1760 PostInlineUnconditionally 991 UnfoldingDone 132 RuleFired 1 *# 15 +# 25 ++ 1 # 3 ==#-case 2 SC:a0 1 SC:a_s2sW0 1 SPEC GHC.Num.- 2 SPEC GHC.Real.$p1Integral 2 SPEC GHC.Real.$p1Real 2 SPEC GHC.Real.$p2Real 3 SPEC Main.speed 3 SPEC System.Random.random 1 eftInt 9 fold/build 14 foldr/app 1 fromIntegral/Word-Int 1 int2Double# 1 int2Word# 3 map 2 mapList 1 minimumInt 2 remInt# 2 take 2 takeList 17 unpack 6 unpack-append 9 unpack-list 212 LetFloatFromLet 1 EtaReduction 2874 BetaReduction 27 CaseOfCase 341 KnownBranch 3 CaseElim 2 CaseIdentity 13 FillInCaseDefault 22 SimplifierDone Linking Unit ... Unit.o: In function `s4Da_info': (.text+0x1b21): undefined reference to `genrand_real2' Unit.o: In function `s4RA_info': (.text+0x3e75): undefined reference to `genrand_real2' Unit.o: In function `s4S4_info': (.text+0x3f61): undefined reference to `genrand_real2' Unit.o: In function `s5su_info': (.text+0x40bc): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `mersennezmrandomzm0zi1zi1_SystemziRandomziMersenne_zdwa2_info': ghc13223_0.hc:(.text+0x1a3): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2J1_info': ghc13223_0.hc:(.text+0x91d): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2JZ_info': ghc13223_0.hc:(.text+0xb3d): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2LJ_info': ghc13223_0.hc:(.text+0xf8d): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s35i_info': ghc13223_0.hc:(.text+0x1397): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s36A_info': ghc13223_0.hc:(.text+0x1517): undefined reference to `gen_rand64_mix' collect2: ld returned 1 exit status make: *** [all] Error 1 ___ Haskell-Cafe mailing
[Haskell-cafe] Re: appending an element to a list
Ronald Guida wrote: Thank you, apfelmus. That was a wonderful explanation; the debit method in [1] finally makes sense. A diagram says more than a thousand words :) My explanation is not entirely faithful to Okasaki, let me elaborate. In his book, Okasaki calls the process of transferring the debits from the input xs = x1 : x2 : x3 : ... : xn : [] 111 ... 11 0 ys = y1 : y2 : y3 : ... : ym : [] 111 ... 11 0 to the output xs ++ ys = x1 : x2 : x3 : ... : xn : y1 : y2 : y3 : ... : ym : [] 222 ... 22111 ... 11 0 debit inheritance. In other words, the debits of xs and ys (here 1 at each node) are carried over to xs ++ ys (in addition to the debits created by ++ itself). In the thesis, he doesn't give it an explicit name, but discusses this phenomenon in the very last paragraphs of chapter 3.4 . The act of relocating debits from child to parent nodes as exemplified with xs ++ reverse ys = x1 : x2 : x3 : ... : xn : yn : y{n-1} : ... : y1 : [] 111 ... 11n0 ... 00 0 xs ++ reverse ys = x1 : x2 : x3 : ... : xn : yn : y{n-1} : ... : y1 : [] 222 ... 2200 ... 00 0 is called debit passing, but Okasaki doesn't use it earlier than in the chapter Implicit recursive slowdown. But the example I gave here is useful for understand the scheduled implementation of real time queues. The trick there is to not create a big suspension with n debits but to really physically distribute them across the data structure x1 : x2 : x3 : ... : xn : yn : y{n-1} : ... : y1 : [] 222 ... 2222 ... 22 2 and discharge them by forcing a node with every call to snoc . I say physically because this forcing performs actual work, it does not simply mentally discharge a debit to amortize work that will be done later. Note that the 2 debits added to each yi are an overestimation here, but the real time queue implementation pays for them nonetheless. My focus on debit passing in the original explanation might suggest that debits can only be discharged when actually evaluating the node to which the debit was assigned. This is not the case, an operation may discharge any debits, even in parts of the data structure that it doesn't touch. Of course, it must discharge debits of nodes it does touch. For instance, in the proof of theorem 3.1 (thesis) for queues, Okasaki writes We can restore the invariant by discharging the first (two) debit(s) in the queue without bothering to analyze which node this will be. So, the front queue might look like f1 : f2 : f3 : ... : fn : f{n+1} : f{n+2} : ... : fm : [] 001 ... 11n0 ... 00 0 and it's one of the nodes that carries one debit, or it could look like f2 : f3 : ... : fn : f{n+1} : f{n+2} : ... : fm : [] 00 ... 00 n-3 0 ... 00 0 and it's the node with the large amount of debits. In fact, it's not even immediate that these two are the only possibilities. However, with the debit passing from my previous post, it's easier to say which node will be discharged. But even then, only tail discharges exactly the debits of nodes it inspects while the snoc operation discharges debits in the untouched front list. Of course, as soon as identifying the nodes becomes tractable, chances are that you can turn it into a real-time data structure. Another good example are skew heaps from [2]: Chris Okasaki. Fun with binary heap trees. in J. Gibbons, O. de Moor. The Fun of Programming. http://www.palgrave.com/PDFs/0333992857.Pdf Here, the good nodes are annotated with one debit. Every join operation discharges O(log n) of them and allocates new ones while walking down the tree, but the time to actually walk down the tree is not counted immediately. This is just like (++) walks down the first list and allocates debits without immediately using O(n) time to do that. Regards, apfelmus PS: In a sense, discharging arbitrary debits can still be explained with debit passing: first pass those debits to the top and the discharge them because any operation has to inspect the top. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Friday 06 June 2008, Andrew Coppin wrote: It's really quite frustrating that it is 100% impossible to write a single function that will process lists, arrays, sets, maps, byte strings, etc. You have to write several different versions. OK, so some functions really don't make sense for a set because it's unordered, and some functions don't make sense for a map, and so forth. But for example, if I write some complicated algorithm that uses a list to store data and I change that to a set instead, I now have to wade through the function changing every operation from a list-op into a set-op. It's really very annoying! It's not 100% impossible, depending on what exactly you're doing. For instance... Set a, ByteStrings, Seq a, Map k a and [a] are Monoids Set, Array i, Map k, Tree, Seq and [] are Foldable functors Array i, Map k, Tree, Seq, Tree and [] are Traversable functors Those can get you lots of operations (folds, maps, unions...) although there may be gaps that could be filled (Foldable is sufficient to define null, for instance, but it isn't in Data.Foldable). There's also the collections library (or Edison, if that's more your style) on hackage that takes such things a lot further. It seems it needs to be tweaked a bit to run on 6.8 according to the log, though. And there's also the issue of whether you can make all such generic operations perform well enough for every instance without making gigantic type classes that allow you to override every single operation (or if you can't, which way do you sacrifice). Of course, the prelude isn't a very good example of this sort of thing, so if that's the only place one looks (or in any module specific to one particular data structure), there's not much to find. -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Design your modules for qualified import
Andrew Coppin wrote: Until very recently, it was not at all clear to me that there is actually a very simple solution to this problem: import Text.ParserCombinators.Parsec as P Now I only have to write P.runPaser, which is much shorter. This fact probably needs to be mentioned more loudly - I'm sure I'm not the only person to have overlooked it... I have one efficient way to find all the needed language features without reading the specification from the start to the end or waiting till my questions get answered. The point is that common sense will indicate you where the required features should be logically located in the language grammar. E.g. if you want something related to imported modules it is logical to check all the alternatives available in import declaration. Then I check the grammar how the production for import declaration (impdelc) looks like (where it can be used etc.). Mostly it is enough sometimes I need to check the language specification since it is not obvious from the grammar. The result is that when I learn a new language the first thing I'm looking for is the formal grammar. Luckily most languages have it available. Some languages (like Haskell) are obsessed with shortcuts and the result is that their grammar is a bit cryptic; others (like VHDL) have it just great - production names clearly indicate what they actually do. On the other side haskell has nice online report :-) Peter. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Map traversal.
I found that I often need predecessor and successor of some key in Data.Map.Map. Just like that: predKey, succKey :: Ord k = Data.Map.Map k a - k - Maybe k predKeyElem, succKeyElem :: Ord k = Data.Map.Map k a - k - Maybe (k,a) Data.Map has operations like that on key indexes, but it is slightly unnatural to work with three entities (index, key and element) where two suffices. So I propose to include those operations into next version of Data.Map. If anyone could point me in the right direction I could do any necessary modifications myself (just because I need it). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Teaching Monads
On 7 Jun 2008, at 08:05, Ronald Guida wrote: What made monads click for me is when I understood the following things: Well, in case anybody's interested, I didn't know anything about monads before I tried to read the book Toposes theory (not sure about the exact name, I've read it in Russian) by P.T. Johnstone. It's Chapter 0 contained some facts about monads without proofs or even definitions. I've looked for some definitions in Mathematical Encyclopedia, asked one of my professors about other ones, tried to prove all results in this chapter by myself (successfully), and, suddenly, found out that I understand what monads are. Then, while reading YAHT, I've thought a bit, then realized, that Haskell monads are the same beast I already know (I didn't know about Kleisli triples before), and everything was clear. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Teaching Monads
On Saturday 07 June 2008, Ronald Guida wrote: 3. These closures are extremely similar to the closures that arise when desugaring let-syntax. let x1 = f1 inf1 -$ (\x1 - Where: let x2 = f2 in f2 -$ (\x2 - (-$) :: a - (a - b) - b let x3 = f3 inf3 -$ (\x3 - x -$ f = f x f x1 x2 x3 f x1 x2 x3))) In fact, this is the identity monad (this is not valid Haskell, but we'll let that slide): type Id a = a instance Monad Id where return a = a a = f = f a do x1 - f1 f1 = \x1 (\x1 - x2 - f2 f2 = \x2(\x2 - x3 - f3 f3 = \x3 (\x3 - f x1 x2 x3) f3) return (f x1 x2 x3) return (f x1 x2 x3)f2) f1 Which is the same as the lets modulo let-polymorphism and recursive bindings. (In Haskell, you need a newtype wrapper but it's otherwise the same.) OK, so before I attempt to write a monad tutorial based on manual plumbing and monadic plumbing, I would like to know, does anyone else think this is a good idea? I think the general consensus is don't write yet more monad tutorials. If you think Wadler's original paper is good, then it doesn't hurt to recommend it (you could instead write a don't be afraid of reading academic papers tutorial :)). But don't let me stop you, of course. :) -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Issues of the mailto link on the list archive page
Hi, I had private conversation with Andrzej Jaworski about the fact that his reply to Alberto Ruiz's post is off thread. What he did was clicking on the mailto link beside the author's name on the list archive web page [1]. [1] http://www.haskell.org/pipermail/haskell-cafe/2008-June/044023.html I am not quite sure about what this link is supposed to do. But, if it is meant for people to click and reply to the thread, it is not doing this correctly, as the Subject and In-Reply-To fields in the link are obtained from these fields in the head of current email. It would be useful if the link shows Subject with an added Re: if there is not already one, and fill in the in-Reply-To field with the value from the Message-Id field of current email head. An optional Reference field is informative for most of the email client, too. Sorry if this topic has the least connection to the glorious Haskell. Best, Xiao-Yong -- c/*__o/* \ * (__ */\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Fri, Jun 6, 2008 at 2:35 PM, Andrew Coppin [EMAIL PROTECTED] wrote: Johan Tibell wrote: 3. Lack of common interfaces. Yes. It's really quite frustrating that it is 100% impossible to write a single function that will process lists, arrays, sets, maps, byte strings, etc. You have to write several different versions. OK, so some functions really don't make sense for a set because it's unordered, and some functions don't make sense for a map, and so forth. But for example, if I write some complicated algorithm that uses a list to store data and I change that to a set instead, I now have to wade through the function changing every operation from a list-op into a set-op. It's really very annoying! I can think of at least two ways I have been able to keep generic code generic, in the way you describe: 1. Use the Data.Foldable interface. Lists, Sets, Sequences and Trees are all foldable. This doesn't help with your complaint about arrays and bytestrings, but it's something. You can do a lot with Foldable. 2. Factor out the operations *your app uses* into a typeclass. For some code I was writing I wrote the following interface -- | Represents a container of type @t@ storing elements of type @a@ that -- support membership, insertion, and deletion. class Ord a = Setlike t a where -- | The set-like object with an element removed. without :: t - a - t -- | The set-like object with an element included. with :: t - a - t -- | Whether the set-like object contains a certain element. contains :: t - a - Bool [Aside: This could be made H98 easily, but I didn't need it to be.] By implementing this class for various types (sets and lists, as well as a few others I used) I achieved the implementation-agnosticism you described at fairly low cost. If I needed to change out a list for an array, I only changed the code that creates the initial data structure, or the signature in the actual record containing the type --- in other words, I only changed what needed to be changed, and the rest was inferred. The reason I think it makes sense for *me* to have created and implemented this interface, instead of a library writer, is that for each task that is data-structure agnostic in some respect, you will need a *different* set of operations. I know which ones I need, so I should make only those generic. The library writer, to be generic, would have to write interfaces for all combinations of operations one might care about (too many for this not to be a waste of time) and that *still* wouldn't be good enough, because certain operations have slightly differing semantics (or signatures) that make genericity inadvisable (e.g. Set.map does not preserve the length of the input list, but List.map does. If your code relies on this rule about map, it is bad to use an interface with a generic map). Perhaps there are certain, small, common interfaces --- like Setlike --- that could be agreed upon. But some people will always clamor that it doesn't fit their application, or doesn't have the right methods. Which I think is okay, if we don't ask too much of standard libs. -- Denis ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
2008/6/6 Andrew Coppin [EMAIL PROTECTED]: Until very recently, it was not at all clear to me that there is actually a very simple solution to this problem: import Text.ParserCombinators.Parsec as P Now I only have to write P.runPaser, which is much shorter. Err, I have a beginner question, then: Is there any difference between: import Very.Long.Module.Name as M and: import qualified Very.Long.Module.Name as M ? Loup ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] installing happy 1.17
I had a problem installing happy 1.17 (same result with happy head). This appears to be required for installing happs-hsp-template via cabal install. thanks for any advice! Thomas. * [EMAIL PROTECTED]:~/haskellInstalls/smallInstallsdarcs get --partial http://darcs.haskell.org/happy/ ** Copying patch 87 of 87... done. Applying patch 86 of 86... done. Finished getting. [EMAIL PROTECTED]:~/haskellInstalls/smallInstallscd happy [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happyrunghc Setup.lhs configure Setup.lhs:30:43: Not in scope: `buildVerbose' [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happycabal --version cabal-install version 0.4.9 using version 1.3.12 of the Cabal library [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happyghc-pkg list | grep -i cabal Cabal-1.2.3.0, Cabal-1.3.11, Cabal-1.3.12, Cabal-1.5.2, ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Cabal-1.4 release candidate
as promised, sudo cabal install plugins works out of the box now. that's nice :) thomas. 2008/6/6 Duncan Coutts [EMAIL PROTECTED]: Hi everyone, == Cabal-1.4 release candidate == The second release candidate of Cabal-1.4 is out: http://haskell.org/cabal/download.html Please test and report bugs: http://hackage.haskell.org/trac/hackage/ The aim for the Cabal-1.4 release is to get various fixes and improvements into the hands of developers and to support a release of cabal-install. == cabal-install == A snapshot of cabal-install is also available: http://haskell.org/cabal/download.html It requires the zlib and HTTP packages (both are available from hackage). Bug reports should go in the same trac as above. cabal-install is intended to be the standard command line interface to the whole Cabal/Hackage system. It replaces the runhaskell Setup.hs interface and a few other tools you may or may not have heard of (cabal-setup, cabal-upload, cabal-get). cabal-install is usable now and we will be making a proper release some time after the Cabal-1.4 release. == Testing == We are particularly interested in finding regressions from Cabal-1.2.x or any important fixes that will require API changes since once we release 1.4 we have to maintain API compatibility for the rest of the 1.4.x series. This is also an excellent opportunity to make sure your favourite bug or feature request is properly described in our bug tracker: http://hackage.haskell.org/trac/hackage/ To help us guide development priorities please add yourself to the ticket's cc list and describe why that bug or feature is important to you. == Compatibility == We have tried to preserve compatibility with all packages that worked with the Cabal-1.2.x series. That is, packages that can be built using Cabal (including custom Setup.hs scripts) but not packages that directly import and use the Cabal API. Packages that directly import and use the Cabal api will need updating. This affects packages that build distro packages for example, rpm debs etc. Currently we know of only one package on hackage which has a Setup.hs script that compiles with 1.2 but fail to compile with 1.4. Takusen, will require an update to be able to work with both Cabal-1.2.x and 1.4.x. A patch has been sent to the maintainers of Takusen. == Credits == On behalf of the Cabal hackers and the community generally I'd like to thank the large number of people who have contributed patches during this development series. Previously I was rather worried that we were not getting enough contributors to fix bugs and do new feature development, but now I'm very pleased. :-) == Get involved == Of course there's still a lot to do! We have big plans for Cabal-2.0, cabal-install and the Hackage website. So if you're interested in helping out with this core infrastructure project then: * subscribe to the cabal-devel mailing list: http://www.haskell.org/mailman/listinfo/cabal-devel * grab the source: http://haskell.org/cabal/code.html * read the guide to the source code: http://hackage.haskell.org/trac/hackage/wiki/SourceGuide * take a look at our list of bugs and feature requests: http://hackage.haskell.org/trac/hackage/report/12 especially the easy tickets: http://hackage.haskell.org/trac/hackage/report/13 Duncan (wearing his Cabal release manager hat) ___ 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] Newbie Q: Overloading and type classes
{-- I try to define class Store that will group types implmenting different storage mechanisms . All types should support two functions: 1) put (key, value) pair into storage 2) get value from storage corresponding to the given key As an example I start with the following storage types: --} -- simple memory cell data OneCell k v = Cell(k, v) -- list of cells data CellList k v = CLst [(k, v)] {-- First, without grouping these types into any class, just to illustrate what these types should do, I define the following functions: --} {-- put::(k, v) - OneCell k v - OneCell k v put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get :: Eq k = k - OneCell k v - Maybe v get k (Cell (_, v)) = Just v c1 ::OneCell String Int c1 = Cell(one, 1) putLst :: (k,v) - CellList k v - CellList k v putLst (k,v) (CLst xs) = CLst ((k,v) : xs) getLst :: Eq k = k - CellList k v - Maybe v getLst k (CLst xs) = lookup k xs cl1 = CLst [(one,1),(two,2),(three,3)] --} {-- These work as expected. Now I try to define Store class that should allow me to overload put get functions: --} class Store s where put :: Eq k = (k, v) - s - s get :: k s - Maybe v {-- instance Store OneCell where put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get k (Cell (_, v)) = Just v --} {-- I get the following error: `OneCell' is not applied to enough type arguments Expected kind `*', but `OneCell' has kind `* - * - *' In the instance declaration for `Store OneCell' --} instance Store CellList where put (k,v) (CLst xs) = CLst ((k,v) : xs) get k (CLst xs) = lookup k xs {-- I get the following error: `CellList' is not applied to enough type arguments Expected kind `*', but `CellList' has kind `* - * - *' In the instance declaration for `Store CellList' --} What should I do to create Store class? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Teaching Monads
On Sat, 2008-06-07 at 00:05 -0400, Ronald Guida wrote: Monads in Haskell are a topic that I, like most beginners, find difficult and mind-twisting. Now that I think I understand monads, they seem to be very simple; I've read that this is a common experience. So I wonder, what would it take to help beginners catch on with a minimum of fuss or frustration? The plethora of monad tutorials out there is clear evidence that plenty of others have wondered the same thing. What made monads click for me is when I understood the following things: 1. When monads are being used, closures are almost always involved. 2. These closures naturally arise when desugaring do-syntax. do x1 - m1 m1 = (\x1 - x2 - m2 m2 = (\x2 - [Eq1] x3 - m3 m3 = (\x3 - return (f x1 x2 x3)return (f x1 x2 x3 3. These closures are extremely similar to the closures that arise when desugaring let-syntax. let x1 = f1 inf1 -$ (\x1 - Where: let x2 = f2 in f2 -$ (\x2 - (-$) :: a - (a - b) - b let x3 = f3 inf3 -$ (\x3 - x -$ f = f x f x1 x2 x3 f x1 x2 x3))) 4. While I can think of a monad as a fancy container that holds an element of type t, it might be more accurate to think of a monad as a container that merely displays the type t as a label for its contents. The container might hold one object of type t, or it might hold several. It might not be holding any at all. Perhaps the container /never/ holds an object of type t, but instead it holds a set of instructions to produce such an object. (e.g. Reader, State). Naturally, it's hard to illustrate nested closures, higher-order functions, and objects that aren't really there. It's easy to illustrate a sequential scheme where a single thing passes through a series of operations, while some related data travels in parallel. m1 = f1 = f2 = f3[Eq2] In any case, the extreme similarity between desugared do and desugared let leads me to think of the concepts of a manual plumbing system and a monadic plumbing system. Basically, a manual plumbing system is what I have if I'm threading information down through a series of nested function calls in a certain stereotypical way. A monadic plumbing system is what I get when I introduce the appropriate monad to encapsulate my threading. In fact, if I look at Wadler [*], there are three examples of an evaluator that use what I'm calling manual plumbing. In section 2.5, the operations required of a monad (return, bind) pretty much just drop right out. Wadler even points out the similarity between bind and let. Now that I finally get it, I feel that the Wadler paper, section 2.5 in particular, is probably a better introduction than many of the monad tutorials out there. Moreover, I feel that for /some/ of the tutorials out there, they spend too much time and too many illustrations explaining things like [Eq2], and then they quickly present do-notation and gloss over [Eq1]. For me, I found that that the concepts of manual plumbing and monadic plumbing were key to actually grasping the Wadler paper and understanding what monads are. In particular, I feel that these two concepts might be a way to help other beginners catch on as well. OK, so before I attempt to write a monad tutorial based on manual plumbing and monadic plumbing, I would like to know, does anyone else think this is a good idea? Why should I recommend a beginner to this tutorial rather than one of the dozens of others online or, better yet, to Wadler's papers directly (which is what I do)? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-Cafe] Quick question for a slow program
On Sat, Jun 7, 2008 at 10:26 AM, Slavomir Kaslev [EMAIL PROTECTED] wrote: Hello, I was just brushing my haskell-fu skills writing a solution for Google Treasure Hunt Problem 4. Hers is what it looks like: primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] Read this: www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf This is probably the biggest culprit in your code. :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Patrick Perry's BLAS package
Xiao-Yong Jin wrote: Salute! Excellent! Patrick Perry [EMAIL PROTECTED] writes: * Support for both immutable and mutable types. Haskell tries to make you use immutable types as much as possible, and indeed there is a very good reason for this, but sometimes you have a 100MB matrix, and it just isn’t very practical to make a copy of it every time you modify it. hmatrix only supports immutable types, and HBlas only supports mutable ones. I wanted both. I didn't use hmatrix a lot, because I wrote some STUArray things and I wasn't sure what to do with that. However, I just noticed that there is a bunch of ST growing under Data.Packed in hmatrix. Guess things is going to change, soon. And perhaps with your work, Alberto doesn't need to reinvent the wheel anymore. Sure, in the future the internal modules of hmatrix (if not all of them) can be replaced by Patrick's blas and the future lapack. And several alternative high level interfaces may coexist as thin layers on the underlying computational engine with different goals: from very simple interfaces for causal usage to advanced ones for more complex applications. a function like foo :: (BLAS1 e) = Matrix (m,n) e - Matrix (n,k) e - Int - Vector m e foo a b i = let x = row b i in a * x will not type-check. (”*” is the function to multiply a matrix by a vector. Everything is ok if you replace “row” by “col”.) This feature has caught a few bugs in my code. If I understand this correctly, the compiler can catch dimension mismatches so that using `col' will result in a compilation error when m and k are different, is it so? Yes, the compiler infers the type of expression to be Matrix(m,n) e - Matrix (l,m) e - Int - Vector n e which is different from the declared type. The error will be something like Expected type Vector m e, but got type Vector a1 e instead. And if I understand it correctly, usage is also very practical. You can define something like listVector 3 [1,2,3::Double] and the dimension type is free. But if you give a signature you get static dimension checking: listVector 3 [1,2,3] Vector TypeDim3 Double I like this approach very much. Which types do you recommend for the dimensions? User friendly static dimension checking must be available in any serious Haskell linear algebra library. Frederik Eaton also made very interesting work on this in his index aware library. I haven't look through the code, yet. But it looks like there are certain levels of similarities between blas and hmatrix. Is it possible for these two libraries to cooperate well with each other? (I didn't look at HBlas, so can't say much about that.) This is more work than you might think. The data structures are different, many of the function names are different, and the module namespaces overlap. I wouldn't recommend any switch from hmatrix to blas right now unless you really need mutable types-- hmatrix has a lot more linear algebra functionality. Apart from some warnings, the library compiles fine in my system. But there is a minor issue about the library it links against when `./Setup test'. I need to use `-lcblas' instead of `-lblas' to get it to link to correct libraries. I don't know other people's system. But in my system, Gentoo Linux, I use blas library provided by atlas, and libblas.so is a fortran library and libcblas.so is for C. I don't know of a good way to get around this. It seems like every system has a different convention for the location and name of the cblas libraries. So, everyone has to edit the extra-libraries and the extra-lib-dirs field in the blas.cabal file. Does anyone know of a better way of doing this? (sorry if you receive this again, a previous message seems to be lost) A possible solution is using flags in the cabal configuration file. For instance, I have this in hmatrix.cabal: if flag(mkl) if arch(x86_64) extra-libraries: gsl mkl_lapack mkl_intel_lp64 mkl_sequential mkl_core else extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core else extra-libraries: gsl blas lapack so if I want to link with Intel's MKL optimized blas/lapack instead of ATLAS I simply add the -fmkl flag: runhaskell Setup.lhs configure -fmkl etc. or even cabal install hmatrix -fmkl Other flags can be added to support different distributions. We could have something like cabal install package -ffedora or cabal install package -fcblas etc. Alberto ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Fwd: installing happy 1.17
On Sat, 2008-06-07 at 09:36 -0700, Thomas Hartman wrote: cabal issue? Yes and no. What is happening is that there are several versions of the Cabal library installed. In particular Cabal-1.3.12 and Cabal-1.5.2. The happy package uses build-type Custom so cabal-install compiles the Setup.lhs script. The question is what version of the Cabal library should it use? The happy.cabal file specifies cabal-version: = 1.2 so we'd better respect that. But even then we have several choices. Currently it just picks the highest one of the remaining choices. In this case that meant Cabal-1.5.2 -- the latest development version. This version turns out to have API changes that means that we get a type error when compiling Setup.lhs. As it happens, if cabal-install had picked one of the other choices then it would have compiled ok because the 1.2.x and upcoming 1.4.x series do not have those api changes. The immediate workarounds are: * unregister Cabal-1.5.2 * cabal install happy --cabal-lib-version 1.3.12 Perhaps a better solution is for cabal-install to choose the version of the Cabal library differently. Of course it has to be within the hard constraints specified in the .cabal file and on the command line. But after that perhaps it should prefer the version of the Cabal library that it itself was built with and at second preference the latest version in the same major series. The last preference would be as now, the latest version available. Sound sensible? Duncan -- Forwarded message -- From: Thomas Hartman [EMAIL PROTECTED] Date: 2008/6/7 Subject: installing happy 1.17 To: haskell haskell-cafe@haskell.org I had a problem installing happy 1.17 (same result with happy head). This appears to be required for installing happs-hsp-template via cabal install. thanks for any advice! Thomas. * [EMAIL PROTECTED]:~/haskellInstalls/smallInstallsdarcs get --partial http://darcs.haskell.org/happy/ ** Copying patch 87 of 87... done. Applying patch 86 of 86... done. Finished getting. [EMAIL PROTECTED]:~/haskellInstalls/smallInstallscd happy [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happyrunghc Setup.lhs configure Setup.lhs:30:43: Not in scope: `buildVerbose' [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happycabal --version cabal-install version 0.4.9 using version 1.3.12 of the Cabal library [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happyghc-pkg list | grep -i cabal Cabal-1.2.3.0, Cabal-1.3.11, Cabal-1.3.12, Cabal-1.5.2, ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-Cafe] Quick question for a slow program
On Sat, 7 Jun 2008 12:26:17 +0300 Slavomir Kaslev [EMAIL PROTECTED] wrote: I was just brushing my haskell-fu skills writing a solution for Google Treasure Hunt Problem 4. Hers is what it looks like: primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] sumOf n l = sum (take n l) : sumOf n (tail l) find l = foldl1 aux l where aux (x:xs) (y:ys) | x == y = x : aux xs ys | x y = aux xs (y:ys) | x y = aux (x:xs) ys puzzle = find (reverse [primes, p7, p17, p41, p541]) where p7 = sumOf 7 primes p17 = sumOf 17 primes p41 = sumOf 41 primes p541 = sumOf 541 primes main = do mapM (\x - putStrLn $ show x) puzzle While the code is quite readable and straight forward it is as slow as tortoise with four legs broken. What optimizations would you suggest, while still keeping the code clear and highlevel? While I can't quite prove it, I surmise find is wasting a lot of time tracking down numbers which are sums of three or four of those lists before continuing. Here's mine: sliding n = map (sum . take n) $ tails primes merge (x:xs) (y:ys) | x y = x:merge xs (y:ys) | otherwise = y:merge (x:xs) ys four = filter (\l - length l == 5) $ group $ foldr1 merge $ map sliding [1,5,43,107,689] In my original implementation I used an isPrime test at the end, but I like your approach better (hence the 1 in map sliding). Does this still count as clear and highlevel? :) Dries Harnie signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mersenne Build Problem
dominic.steinitz: I'm getting errors (see below) trying to build the tests in http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mersenne-random-0.1.1 I built the package itself using ./Setup configure -f use_sse2 I thought I had an intel core duo (also see below). I think I may be missing a library but I'm not sure which one. Unit.o: In function `s4Da_info': (.text+0x1b21): undefined reference to `genrand_real2' Unit.o: In function `s4RA_info': (.text+0x3e75): undefined reference to `genrand_real2' Unit.o: In function `s4S4_info': (.text+0x3f61): undefined reference to `genrand_real2' Unit.o: In function `s5su_info': (.text+0x40bc): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `mersennezmrandomzm0zi1zi1_SystemziRandomziMersenne_zdwa2_info': ghc13223_0.hc:(.text+0x1a3): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2J1_info': ghc13223_0.hc:(.text+0x91d): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2JZ_info': ghc13223_0.hc:(.text+0xb3d): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s2LJ_info': ghc13223_0.hc:(.text+0xf8d): undefined reference to `gen_rand64_mix' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s35i_info': ghc13223_0.hc:(.text+0x1397): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/libHSmersenne-random-0.1.1.a(Mersenne.o): In function `s36A_info': ghc13223_0.hc:(.text+0x1517): undefined reference to `gen_rand64_mix' collect2: ld returned 1 exit status make: *** [all] Error 1 Lookks like the C bits didn't install properly? Possibly your cabal is very old? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Patrick Perry's BLAS package
On Jun 7, 11:21 am, Don Stewart [EMAIL PROTECTED] wrote: The best thing anyone here can do for haskell is contribute a library. The more areas we cover with Haskell code, the easier the path is to ongoing development, and a viable, sustainable Haskell world. Hi Don, I cannot agree more but: (1) I doubt that your consistant contribution and sense of responsibility can be replaced by independent volunteers. (2) More important than the number of libraries is their maintenance and accessibility by which I mean not just sufficient documentation but also reviews with pragmatic suggestions and shared experience formated into some knoledge base. (3) Haskell attracts guys that like originality [ like me;-) ] which is dengerous since building viable programming environment should be a top down affair. Regular coders are easier to cooperate. Conclusion: Some coordination effort is inevitable. Complementary librairs should be chained and updated together like toolboxes in Matlab, which might encourage writers to dedicate domain specific articles or a book around them. Cheers, -Andrzej Jaworski ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mersenne Build Problem
Dominic Steinitz wrote: I'm getting errors (see below) trying to build the tests in http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mersenne-random-0.1.1 [snip] Linking Unit ... Unit.o: In function `s4Da_info': (.text+0x1b21): undefined reference to `genrand_real2' Unit.o: In function `s4RA_info': (.text+0x3e75): undefined reference to `genrand_real2' Unit.o: In function `s4S4_info': (.text+0x3f61): undefined reference to `genrand_real2' Unit.o: In function `s5su_info': (.text+0x40bc): undefined reference to `genrand_real2' /usr/local/lib/mersenne-random-0.1.1/ghc-6.9.20080517/[...] [snip] The missing symbols are inlined functions. ghc 6.9 doesn't include the header files anymore when compiling via C. (The solution is to create C wrappers around those functions. I guess I'll whip up a patch.) HTH, Bertram ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-Cafe] Quick question for a slow program
Am Samstag, 7. Juni 2008 11:26 schrieb Slavomir Kaslev: Hello, I was just brushing my haskell-fu skills writing a solution for Google Treasure Hunt Problem 4. Hers is what it looks like: primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] That alone breaks at least three of the tortoise's legs. Simple trial division: primes = 2:3:filter isPrime [5,7 .. ] isPrime n | n 2 = False | n 4 = True | even n = False | otherwise = go (tail primes) where r = floor $ sqrt (fromIntegral n + 0.5) go (p:ps) = (r p) || (n `mod` p /= 0) go ps is orders of magnitude faster. A really good prime generator wins a lot. sumOf n l = sum (take n l) : sumOf n (tail l) This is also not really good, sumOf n l = zipWith (-) (drop n sms) sms where sms = scanl (+) 0 l is a bit faster, specialising primeSums = scanl (+) 0 primes sumOfPrimes n = zipWith (-) (drop n primeSums) primeSums a bit more. I don't see more improvements directly. find l = foldl1 aux l where aux (x:xs) (y:ys) | x == y = x : aux xs ys | x y = aux xs (y:ys) | x y = aux (x:xs) ys puzzle = find (reverse [primes, p7, p17, p41, p541]) where p7 = sumOf 7 primes p17 = sumOf 17 primes p41 = sumOf 41 primes p541 = sumOf 541 primes main = do mapM (\x - putStrLn $ show x) puzzle While the code is quite readable and straight forward it is as slow as tortoise with four legs broken. What optimizations would you suggest, while still keeping the code clear and highlevel? Thank you in advance. Cheers. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Dynamic curiosity
Hello All, I've recently modified my existing project to support dynamic data (using 'Data.Dynamic'), and despite my earlier benchmarks on 'Dynamic', the program slowed down by a factor of 10. Profiler says that 'fromDynamic' is consuming 60% of the CPU time (with -O2). Using the below function instead of 'fromDynamic' seems to make coercion 20 times faster (thereby solving my problem): {-# OPTIONS -fglasgow-exts #-} import GHC.Prim data Dynamic' = Dynamic' TypeRep Any fromDynamic' :: forall a. Typeable a = Dynamic - Maybe a fromDynamic' d = let Dynamic' t v = unsafeCoerce# d in if t == typeOf (undefined :: a) then Just (unsafeCoerce# v) else Nothing I was able to reproduce the same result from scratch. The only difference with the standard implementation (I put it below for reference), other than the first ugly unsafeCoerce#, seems to be existential quantification (i.e. When I replace if t == typeOf (undefined :: a) ... with the case ... below, performance goes down again.). fromDynamic :: Typeable a = Dynamic - Maybe a fromDynamic (Dynamic t v) = case unsafeCoerce v of r | t == typeOf r - Just r | otherwise - Nothing So what is causing the improvement, or am I missing something? Thanks. -- Gokhan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Fwd: installing happy 1.17
On Sat, 2008-06-07 at 18:44 +0100, Duncan Coutts wrote: Perhaps a better solution is for cabal-install to choose the version of the Cabal library differently. Of course it has to be within the hard constraints specified in the .cabal file and on the command line. But after that perhaps it should prefer the version of the Cabal library that it itself was built with and at second preference the latest version in the same major series. The last preference would be as now, the latest version available. Sound sensible? Done: Sat Jun 7 19:26:00 BST 2008 Duncan Coutts [EMAIL PROTECTED] * Use a smarter preference when picking a Cabal lib to build Setup.hs Instead of just using the latest version we use the best version according to the following preferences in priority order: - the same version as cabal-install was itself built with - the same major version number as cabal-install was built with - a stable version of Cabal (even second digit of major number) - the latest version Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
Am Samstag, 7. Juni 2008 17:31 schrieb Loup Vaillant: 2008/6/6 Andrew Coppin [EMAIL PROTECTED]: Until very recently, it was not at all clear to me that there is actually a very simple solution to this problem: import Text.ParserCombinators.Parsec as P Now I only have to write P.runPaser, which is much shorter. Err, I have a beginner question, then: Is there any difference between: import Very.Long.Module.Name as M and: import qualified Very.Long.Module.Name as M The former lets you access functions from Very.Long.Module.Name also unqualified. ? Loup ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Design your modules for qualified import
Hello Loup, Saturday, June 7, 2008, 7:31:29 PM, you wrote: Is there any difference between: import Very.Long.Module.Name as M and: import qualified Very.Long.Module.Name as M with first you get *both* qualified and unqualified identifiers, with second - only qualified -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Overloading and type classes
2008/6/7 Dmitri O.Kondratiev [EMAIL PROTECTED]: class Store s where put :: Eq k = (k, v) - s - s get :: k s - Maybe v I suspect you want this to be a constructor class. That is, you want to make explicit the fact that the type s depends on k and v. class Store s where put :: Eq k = (k,v) - s k v - s k v get :: s k v - Maybe v If instead you have cell types which are restricted in what they can store in different ways, you might explore fundeps or associated types: -- fundeps class Store s k v | s - k v where put :: (k,v) - s - s get :: s - Maybe v -- associated types class Store s where type Key s :: * type Value s :: * put :: (Key s, Value s) - s - s get :: s - Maybe (Value s) But if you can get away with the former, I would recommend that before looking into these advanced extensions. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Overloading and type classes
On Sat, Jun 7, 2008 at 1:08 PM, Luke Palmer [EMAIL PROTECTED] wrote: 2008/6/7 Dmitri O.Kondratiev [EMAIL PROTECTED]: class Store s where put :: Eq k = (k, v) - s - s get :: k s - Maybe v I suspect you want this to be a constructor class. That is, you want to make explicit the fact that the type s depends on k and v. class Store s where put :: Eq k = (k,v) - s k v - s k v get :: s k v - Maybe v Oops. Should be: get :: k - s k v - Maybe v And correspondingly for the later examples. After actually using my brain thinking about your problem, and reading the word Newbie, I would absolutely stay away from the fundeps/associated types business. :-) Try to get this working with Cell and CellList first :-) Luke If instead you have cell types which are restricted in what they can store in different ways, you might explore fundeps or associated types: -- fundeps class Store s k v | s - k v where put :: (k,v) - s - s get :: s - Maybe v -- associated types class Store s where type Key s :: * type Value s :: * put :: (Key s, Value s) - s - s get :: s - Maybe (Value s) But if you can get away with the former, I would recommend that before looking into these advanced extensions. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Fwd: installing happy 1.17
Duncan Coutts wrote: The immediate workarounds are: * unregister Cabal-1.5.2 Better, hide it (that's reversible) - or does that not work with cabal-install? Bertram ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Fwd: installing happy 1.17
On Sat, 2008-06-07 at 21:20 +0200, Bertram Felgenhauer wrote: Duncan Coutts wrote: The immediate workarounds are: * unregister Cabal-1.5.2 Better, hide it (that's reversible) - or does that not work with cabal-install? If Cabal ignored hidden packages then you could never install packages that depend on the ghc package since that's always hidden. Though again we could use that as a preference rather than a hard constraint. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] example of FFI FunPtr
2008/6/6 Galchin, Vasili [EMAIL PROTECTED]: I want to do an incremental experiment. I want just want to pass a C function to callback to a Haskell function. ??? This is easy; just declare the function via the FFI; here's an example from my implementation for the 2006 ICFP contest (http://www.boundvariable.org/); this interface is used to get access to a fast C VM from the high-level haskell debugger. The C VM can call back into Haskell in order to get and fetch characters from the console, and to notify the debugger of allocations and frees. The haskell-side debugger can query the state of the VM via the get functions exported by the VM. In this example, get_program_size is a first class haskell IO action; it can be passed around like any other action. If you know the function call is referentially transparent (pure), you can leave the IO off of the return result of the function; be careful with this, it's calling into whatever C-code you are giving and so you should treat it as carefully as you treat unsafePerformIO. The unsafe keyword allows GHC to optimize certain calls; in order to use it you need to know that the function won't call back into Haskell code. foreign import ccall unsafe load_program :: Ptr Word32 - Word32 - IO () foreign import ccall execute :: Word32 {-numCycles-} - FunPtr GetChar - FunPtr PutChar - FunPtr Notify {-alloc-} - FunPtr Notify {-free-} - IO Word32 {-returnCode 0=success, 1=failure-} foreign import ccall unsafe get_program :: IO (Ptr Word32) foreign import ccall unsafe get_program_size :: IO Word32 foreign import ccall unsafe get_registers :: Ptr Word32 foreign import ccall unsafe get_pc :: IO Word32 foreign import ccall unsafe get_prev_pc :: IO Word32 foreign import ccall unsafe set_pc :: Word32 - IO Bool type GetChar = IO Word32 type PutChar = Word32 - IO () type Notify = Ptr Word32 - Word32 - IO () foreign import ccall wrapper mkGetChar :: GetChar - IO (FunPtr GetChar) foreign import ccall wrapper mkPutChar :: PutChar - IO (FunPtr PutChar) foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-Cafe] Quick question for a slow program
The second prime generator on this page http://www.haskell.org/haskellwiki/Prime_numbers is quick and easy. I keep it nearby for all those sudden attacks of needing to solve yet another projecteuler problem. -ljr Slavomir Kaslev wrote: Hello, I was just brushing my haskell-fu skills writing a solution for Google Treasure Hunt Problem 4. Hers is what it looks like: primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] sumOf n l = sum (take n l) : sumOf n (tail l) find l = foldl1 aux l where aux (x:xs) (y:ys) | x == y = x : aux xs ys | x y = aux xs (y:ys) | x y = aux (x:xs) ys puzzle = find (reverse [primes, p7, p17, p41, p541]) where p7 = sumOf 7 primes p17 = sumOf 17 primes p41 = sumOf 41 primes p541 = sumOf 541 primes main = do mapM (\x - putStrLn $ show x) puzzle While the code is quite readable and straight forward it is as slow as tortoise with four legs broken. What optimizations would you suggest, while still keeping the code clear and highlevel? Thank you in advance. Cheers. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Fwd: installing happy 1.17
great, sudo cabal install from inside 1.17 distribution dir now seems to do the right thing. however, after it's done installing (apparently without error) the happy version is still 1.16 and the happy executable is from 2006. This means that I still can't install other packages that rely on happy =1.17 sudo cabal install haskell-src-exts Resolving dependencies... 'haskell-src-exts-0.3.4' is cached. Configuring haskell-src-exts-0.3.4... cabal: happy version =1.17 is required but the version found at /usr/bin/happy is version 1.16 cabal: Error: some packages failed to install: haskell-src-exts-0.3.4 failed during the configure step. The exception was: exit: ExitFailure 1 happy-1.17sudo cabal install Resolving dependencies... Warning: defaultUserHooks in Setup script is deprecated. Configuring happy-1.17... Warning: No 'build-type' specified. If you do not need a custom Setup.hs or ./configure script then use 'build-type: Simple'. Preprocessing executables for happy-1.17... Building happy-1.17... [ 1 of 18] Compiling Paths_happy ( dist/build/autogen/Paths_happy.hs, dist/build/happy/happy-tmp/Paths_happy.o ) Linking dist/build/happy/happy ... Installing: /home/thartman/.cabal/bin [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happy-1.17happy --version Happy Version 1.16 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow Happy is a Yacc for Haskell, and comes with ABSOLUTELY NO WARRANTY. This program is free software; you can redistribute it and/or modify it under the terms given in the file 'LICENSE' distributed with the Happy sources. [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happy-1.17ls -l `which happy` -rwxr-xr-x 1 root root 941968 2006-11-23 21:34 /usr/bin/happy [EMAIL PROTECTED]:~/haskellInstalls/smallInstalls/happy-1.17 2008/6/7 Duncan Coutts [EMAIL PROTECTED]: On Sat, 2008-06-07 at 21:20 +0200, Bertram Felgenhauer wrote: Duncan Coutts wrote: The immediate workarounds are: * unregister Cabal-1.5.2 Better, hide it (that's reversible) - or does that not work with cabal-install? If Cabal ignored hidden packages then you could never install packages that depend on the ghc package since that's always hidden. Though again we could use that as a preference rather than a hard constraint. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Fwd: installing happy 1.17
On Sat, 2008-06-07 at 14:46 -0700, Thomas Hartman wrote: great, sudo cabal install from inside 1.17 distribution dir now seems to do the right thing. however, after it's done installing (apparently without error) the happy version is still 1.16 and the happy executable is from 2006. This means that I still can't install other packages that rely on happy =1.17 sudo cabal install haskell-src-exts Resolving dependencies... 'haskell-src-exts-0.3.4' is cached. Configuring haskell-src-exts-0.3.4... cabal: happy version =1.17 is required but the version found at /usr/bin/happy is version 1.16 At the moment by default cabal-install installs binaries to ~/.cabal/bin which isn't on the $PATH unless you deliberately change your $PATH. The reason we don't put things directly into ~/bin/ is because some people worry about cabal-install clobbering programs that the user already had in ~/bin/. One idea for resolving this is: http://hackage.haskell.org/trac/hackage/ticket/289 We'd very much appreciate feedback on what the right thing to do is and if the above spec is ok for someone to implement it. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] sum in hmatrix and blas?
Hi, probably I am just being dumb, but what is the most efficient way to do a sum of every elements in a Vector of either hmatrix or blas? I know there is sum of absolute values from BLAS. So what about I want a plain sum? I can only think of the following two ways. 1. Using Data.List.foldl', so it is sum' = foldl' (+) 0 . toList in hmatrix or sum' = foldl' (+) 0 . elems in blas. 2. Using ., so it is sum' v = constant 1 (dim v) . v in hmatrix or sum' v = constant (dim v) 1 . v in blas. Which one is better? I guess it probably depends on the internal implementation of BLAS, but I am actually thinking in some thing similar to t += *v++; Any delightful idea to convert my mind from a C shaped one to a Haskell shaped one? Best, Xiao-Yong -- c/*__o/* \ * (__ */\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Overloading and type classes
{-- Thanks! Yes, you got it right - I want to make explicit the fact that the type s depends on k and v. So I followed your advice and used the most simple way to do what I need: --} class Store s where put :: Eq k = (k, v) - s k v - s k v get :: Eq k = k - s k v - Maybe v instance Store OneCell where put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get k (Cell (_, v)) = Just v instance Store CellList where put (k,v) (CLst xs) = CLst ((k,v) : xs) get k (CLst xs) = lookup k xs storePut :: (Store s, Eq k) = s k v - k - v - s k v storePut store key value = put (key, value) store storeGet :: (Store s, Eq k) = k - s k v - Maybe v storeGet key store = get key store aCell :: OneCell String Int aCell = Cell(one, 1) lst :: CellList Int String lst = CLst [(1, one),(2, two),(3, three)] st1 = storePut aCell two 2 st2 = storePut lst 4 four -- v1 = storeGet one st2 -- error v2 = storeGet one st1 -- ok {-- And what does the word newbie imply to you when answering my question? In what case using 'fundeps' and 'associated types' will make sence for this example? --} Thanks again for your great help! Dima On Sat, Jun 7, 2008 at 11:11 PM, Luke Palmer [EMAIL PROTECTED] wrote: Oops. Should be: get :: k - s k v - Maybe v And correspondingly for the later examples. After actually using my brain thinking about your problem, and reading the word Newbie, I would absolutely stay away from the fundeps/associated types business. :-) Try to get this working with Cell and CellList first :-) Luke If instead you have cell types which are restricted in what they can store in different ways, you might explore fundeps or associated types: -- fundeps class Store s k v | s - k v where put :: (k,v) - s - s get :: s - Maybe v -- associated types class Store s where type Key s :: * type Value s :: * put :: (Key s, Value s) - s - s get :: s - Maybe (Value s) But if you can get away with the former, I would recommend that before looking into these advanced extensions. Luke -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [ANN] Bindings to Xen Control (xenctrl.h)
Version 0.0.3 was release, which is nearly a complete (and completely trivial) xenctrl.h binding. Aside from unit tests and programs, the main things missing are grant table operations. There is now a quick and dirty home page at the wiki [1] and a darcs repo on c.h.o [2]. Comments, requests, and contributions are all encouraged. TomMD P.S. I intend to finish the bindings then move onto design/implementation of the higher level 'System.Xen' module when time permits. [1] http://haskell.org/haskellwiki/HsXenCtrl [2] http://code.haskell.org/~tommd/hsXenCtrl On Mon, 2008-06-02 at 00:19 -0400, Thomas M. DuBuisson wrote: Don, I'll throw future work ideas in the next releases cabal. The most obvious doors opened are Haskell rewrites of the current Xen infrastructure (virt-install, xm, xend). Slightly more interesting tasks could be (warning: random thoughts): 1) HAPPS server that can manage Xen domains (without requiring python libs or System.cmd) 2) Network or BSD socket based remote management programs in Haskell. haxr or session-types might be of use here. 3) With the functions that can alter the CPUs availability, more complex rules or sharing arrangements could be implemented. Same concept applies to other resources such as PCI and memory allocation. Seeing as Xen doesn't over-commit memory, a guest VM program that detects low/high memory situations and reports to the host for policy controlled balloning (adjustment of VM allocated memory) would be kind of fun... but probably complete overkill for any user of Xen. Right now I think the bindings are enough for an 'xm' replacement but nothing more. I've over doubled the number of functions bound just now. There will probably be regular releases for the next few weeks as I find time. Thomas On Sat, 2008-05-31 at 23:31 -0700, Don Stewart wrote: thomas.dubuisson: All, I'm just getting started with hsXenCtrl [1] as both a fun way to play with Xen and become proficient with Haskell FFI. Once I get my community.haskell.org account squared away I'll likely setup a public darcs repo (and a homepage somewhere). As for modules: I intend to expand on the trival FFI bindings in System.Xen.CBindings and there'll be a higher level interface in System.Xen (functions will standardize on returning Either or throwing exceptions, hiding the xc_handle open/close, etc). Typical Disclaimers: The _only_ thing I've actually done with this, just tonight, is pause / unpause domains. API is subject to change! Only my exact build of Xen is sure to work, and no promise even then. TomMD [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsXenCtrl Good stuff. Perhaps the synopsis should include a link or description of the typical use cases/ thinks we might achieve? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe