[Haskell-cafe] Record updates
Haskell's record syntax is quite nice, for a number of reasons. However, suppose I have some record: data Foobar = Foobar {foo1, foo2, foo3...} Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up having to write something like let v1 = v0 {foo3 = 5 : (foo3 v0)} If the field name isn't foo but something more descriptive, and the transformation to be applied to it is more intricate, you end up with quite a bit of code. In summary, record syntax gives you a nice way of replacing the value of one field with something else, but no easy way to *modify* the existing value somehow. Does anybody know of a way around this? Is there some trick I'm not seeing? Is there an extension or proposal that fixes this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Record updates
Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template -- ryan On Sun, Mar 29, 2009 at 2:13 AM, Andrew Coppin andrewcop...@btinternet.com wrote: Haskell's record syntax is quite nice, for a number of reasons. However, suppose I have some record: data Foobar = Foobar {foo1, foo2, foo3...} Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up having to write something like let v1 = v0 {foo3 = 5 : (foo3 v0)} If the field name isn't foo but something more descriptive, and the transformation to be applied to it is more intricate, you end up with quite a bit of code. In summary, record syntax gives you a nice way of replacing the value of one field with something else, but no easy way to *modify* the existing value somehow. Does anybody know of a way around this? Is there some trick I'm not seeing? Is there an extension or proposal that fixes this? ___ 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] ANN: cmonad 0.1.1
I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Example: Computing some Fibonacci numbers: fib = do { a - arrayU[40]; i - auto 0; a[0] =: 1; a[1] =: 1; for (i =: 2, (i :: EIO Int) 40, i += 1) $ do { a[i] =: a[i-1] + a[i-2]; }; retrn (a[39]); } Example: Copying stdin to stdout: cat = do { c - auto 0; while ((c =: getchar()) = 0) $ do { putchar(c); }; return (); } -- Lennart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Excerpts from Henning Thielemann's message of Sat Mar 28 21:49:33 +0100 2009: On Sat, 28 Mar 2009, John Lato wrote: From: Donn Cave d...@avvanta.com I have never felt that I really understood that one. Honestly, me neither, until recently. I'm only barely starting to understand it, and I do think there's a great deal of overlap. Even if an error is a bug that can be fixed by the programmer, certain exceptional situations can also be fixed by the programmer by handling the exception, even if they can't be detected in advance. For example? Btw. not handling an exception is an error. I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) Not necessarily, but possibly. The big difference, of course, is that decoding can be a pure operation, while reading never is. I personally wouldn't mind if hGetLine had the type you give. The way I see it, there are two advantages to exceptions in this case. The first is that it's very easy for exceptions to trickle up and be handled at a higher level. The second 'advantage' is that the programmer doesn't need to explicitly handle exceptions, whereas an Either would require at least a pattern match to use the resulting value. I'm afraid there is some confusion about what we mean with exception. Do you only mean the thing that is silently handled in the IO monad? Is Left in Either an exception for you, too? In explicit-exception I call the corresponding constructor Exception, because that's what it is used for. I like to call all those things exceptions, because they are intended for the same purpose: Signalling exceptional situations that we cannot avoid in advance but that must be handled when they occur. You can use IO and its exceptions, I call them IO exceptions. It does not show in its types that and which exceptions can occur. Some people consider this an advantage, I consider this an disadvantage. You can use error codes or Either or even better Exceptional from the explicit-exception package, and Haskell is strong enough to treat these like exceptions in C++/Java/Modula-3 etc. because you can use their monad transformer variants ErrorT and ExceptionalT respectively. Those monad transformers allow automatical termination of a series of actions once an exceptional result is obtained. But since ErrorT and ExceptionalT are burned into the types, you cannot miss to handle them. So the most convenient type for hGetLine would be hGetLine :: Handle - ErrorT IOError IO String By reading the documentation of 'hGetLine' [1] one can see that this function can throw only an EOF exception so why not give it a type like below? hGetLine :: Handle - ErrorT EOF IO String Since one will have to handle the error case it would be better to treat only the possible cases, no? [1]: http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#v%3AhGetLine -- Nicolas Pouillard ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Record updates
Ryan Ingram wrote: Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template So, to summarise, it provides a datatype to encapsulate a pair of get/set functions, some infix sugar for using it, and some TH for autogenerating said data. Is that about right? I'll have a go at trying this later... Thanks. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Sat, Mar 28, 2009 at 9:49 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Sat, 28 Mar 2009, John Lato wrote: From: Donn Cave d...@avvanta.com I have never felt that I really understood that one. Honestly, me neither, until recently. I'm only barely starting to understand it, and I do think there's a great deal of overlap. Even if an error is a bug that can be fixed by the programmer, certain exceptional situations can also be fixed by the programmer by handling the exception, even if they can't be detected in advance. For example? A file not being written because of a permissions error. This can't be detected in advance due to effects from other processes, but it's a predictable enough exception that the programmer should handle it for IO. Handling a DivByZero exception when doing IO, however, is very likely wrong. Btw. not handling an exception is an error. Agreed generally. But some exceptions are likely in given contexts, others are not. I don't think it's necessary to handle every possible exception, just the ones that are likely and predictable for a given activity. Excluding generic The impossible happened, file a bug report handlers. I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) Not necessarily, but possibly. The big difference, of course, is that decoding can be a pure operation, while reading never is. I personally wouldn't mind if hGetLine had the type you give. The way I see it, there are two advantages to exceptions in this case. The first is that it's very easy for exceptions to trickle up and be handled at a higher level. The second 'advantage' is that the programmer doesn't need to explicitly handle exceptions, whereas an Either would require at least a pattern match to use the resulting value. I'm afraid there is some confusion about what we mean with exception. Do you only mean the thing that is silently handled in the IO monad? Yes. I was comparing exceptions as they exist in IO in Haskell to the proposed hGetLine type. Is Left in Either an exception for you, too? No. In explicit-exception I call the corresponding constructor Exception, because that's what it is used for. I like to call all those things exceptions, because they are intended for the same purpose: Signalling exceptional situations that we cannot avoid in advance but that must be handled when they occur. You can use IO and its exceptions, I call them IO exceptions. It does not show in its types that and which exceptions can occur. Some people consider this an advantage, I consider this an disadvantage. I remain undecided on this for the moment. I should take another look at explicit-exception now that I understand its intent better. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Record updates
Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up having to write something like let v1 = v0 {foo3 = 5 : (foo3 v0)} There used to be a feature in pre-Haskell'98 called named field puns, which allows to use a shorter form of field access. Your example would come out as f v0{foo3} = let v1 = v0 {foo3 = 5: foo3} in ... Have a look in the Haskell-1.4 Language Report to see how it works. The behaviour is still supported as an extension by Hugs (-98), nhc98 (-puns), and ghc (-XNamedFieldPuns). Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Record updates
There is a page for extensible records in the wiki: http://www.haskell.org/haskellwiki/Extensible_record Haskell's records system has many insuficiencies. Some libraries (see grapefruit or HaskellDB) encode records as classes, but although some proposals Haskell still lacks a good implementation for extensible and updatable records. On Sun, Mar 29, 2009 at 10:41 AM, Andrew Coppin andrewcop...@btinternet.com wrote: Ryan Ingram wrote: Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template So, to summarise, it provides a datatype to encapsulate a pair of get/set functions, some infix sugar for using it, and some TH for autogenerating said data. Is that about right? I'll have a go at trying this later... Thanks. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- www.di.uminho.pt/~hpacheco ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: cmonad 0.1.1
2009/03/29 Lennart Augustsson lenn...@augustsson.net: ...GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Is this surprising to anyone? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem using #define in .hsc files
Hi, I'm trying to have hsc2hs interpret this snippet that picks a calling convention to use for FFI imports: #if !defined(CALLCONV) #ifdef WITH_WINSOCK #define CALLCONV stdcall #else #define CALLCONV ccall #endif #endif foreign import CALLCONV unsafe send c_send :: CInt - Ptr a - CSize - CInt - IO CInt Compiling results in: parse error on input `CALLCONV' Inspecting the generated .hs file shows that CALLCONV appear in the source code instead of being replaced with either stdcall or ccall as expected. What's the correct way to use #define in .hsc files? Changing the file extension to .cpphs solves the problem, by using plain CPP instead of hsc2hs I presume. Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: cmonad 0.1.1
On Sunday 29 March 2009, Lennart Augustsson wrote: I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Now I've heard that Haskell makes a fine (if not the finest) imperative language, but isn't this taking that thought a bit too far ;) Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. I mean as a proof-of-concept this is cool, but if your primary concern is performance then I think you're barking up the wrong tree with this. Cheers! Marcin Kosiba signature.asc Description: This is a digitally signed message part. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Sat, 2009-03-28 at 12:51 +0300, Gregory Petrosyan wrote: On Sat, Mar 28, 2009 at 10:53 AM, Ketil Malde ke...@malde.org wrote: So the difference between an exception or an error type is mainly what you intend to do about it. There's no point in wrapping divisions in Maybe unless you actually are able to do something useful to recover from a zero denominator. That is exactly the point I was trying to make. When I write a code, I can't say in advance, in what way it will be used. So, for dealing with errors, I have to choose one way or another, mostly without that knowledge. When I'm using e.g. C++, it's easy: something like mantra when in doubt, throw an exception :-) combined with RAII, works good (but not ideal, of course). So, I'll ask again: when I program in Haskell, what mechanism should I use? If you don't know, use a (true) exception. That is, Left or Exception or throwIO. Only use error or throw when you *know* the condition is un-recoverable. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: cmonad 0.1.1
Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc lacks a crucial optimization for specialization of constructor returns. With that in place I think the code could be quite performant. -- Lennart On Sun, Mar 29, 2009 at 3:13 PM, Jason Dusek jason.du...@gmail.com wrote: 2009/03/29 Lennart Augustsson lenn...@augustsson.net: ...GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Is this surprising to anyone? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: cmonad 0.1.1
If my primary concern is speed I'll write in C. 2009/3/29 Marcin Kosiba marcin.kos...@gmail.com: On Sunday 29 March 2009, Lennart Augustsson wrote: I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Now I've heard that Haskell makes a fine (if not the finest) imperative language, but isn't this taking that thought a bit too far ;) Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. I mean as a proof-of-concept this is cool, but if your primary concern is performance then I think you're barking up the wrong tree with this. Cheers! Marcin Kosiba ___ 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] Rational and % operator remix
Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Exception handling in numeric computations
Henning Thielemann schlepp...@henning-thielemann.de wrote: Actually, I really object to have exception handling built into IO monad. I couldn't agree more. If I want to write non-recovering code, I can always just say (Right foo) - readLine , and hope that the RTS is smart enough to print the error message in the left constructor should that match fail. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
I think you probably mean ==, the comparison operator (function), not = (assignment in let-forms or where-forms) -Ross On Mar 29, 2009, at 1:40 PM, michael rice wrote: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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] Template Haskell messes up scoping?
Hi, when I tried to reorganize some code to use the data-accessor and data-accessor-template packages, i stumbled across a strange effect: When using template haskell some things are out of scope that really shouldn't be. Let me give an example: == T.hs == {-# LANGUAGE TemplateHaskell #-} data Foo = Foo { bar :: Bar } $( return [] ) data Bar = Bar == ghci T.hs GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( T.hs, interpreted ) T.hs:4:13: Not in scope: type constructor or class `Bar' Failed, modules loaded: none. No matter what you do in $( ... ), the code doesn't compile. Even in the simple case above, it doesn't work. What's happening here? Bug or feature? And do you know a workaround? //Stephan -- Früher hieß es ja: Ich denke, also bin ich. Heute weiß man: Es geht auch so. - Dieter Nuhr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
Mmm, my email was indeed very unclear about my question. A very simple example: suppose a development team is working on a program. This program consist of modules A and B. Each module has it's own Darcs repository. Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get server://program/B (that B is required is usually discovered after a compilation error, talking to other developers to find out what the dependencies are, or by reading the cabal file). Furthermore it is unclear which version of A required which version of B (so you can't really roll back to old versions). Now assume you don't have 2 modules but dozens... To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. So my question is really, how do you solve the dependency tracking between several Darcs repositories? (maybe I should email this to the darcs mailing list...) On Sat, Mar 28, 2009 at 4:54 AM, Simon Michael si...@joyful.com wrote: I assume cabal install darcs isn't what you're looking for.. can you give a real-world example ? ___ 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] Rational and % operator remix
You can use floor in a Rational directly, no need to take it apart and divide. There is no need to write (toRational 1), just write 1. Don't write (subtract ai a), write (ai - i). You also have a type error; the ai should no be a Rational, so you need to move to toRational call to the comparison. -- Lennart 2009/3/29 michael rice nowg...@yahoo.com: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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] Rational and % operator remix
Am Sonntag 29 März 2009 19:40:19 schrieb michael rice: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, Not for rational numbers. but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. That should be '=='. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) import Data.List (unfoldr) cf3 :: Rational - [Integer] -- Int may overflow cf3 0 = [0] cf3 x = a0:unfoldr f r where a0 = floor x r = x - fromInteger a0 f 0 = Nothing f y = Just (properFraction $ recip y) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
Peter Verswyvelen bugf...@gmail.com wrote: To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. So my question is really, how do you solve the dependency tracking between several Darcs repositories? Shouldn't this be done by cabal, not darcs? i.e. cabal update querying a list of repositories for info about available versions (think standardised tags): cabal install can then figure out what to pull. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell messes up scoping?
Hi Martijn, Martijn van Steenbergen wrote: [...] Apart from the specific problematic file you gave, I had some other scoping issues when using TH to generate the accessors. I worked around this by defining my data types in a separate module Types and calling the TH functions in that module as the last lines. [...] looks like your workaround also works in this case. This file (the template instanciation was moved to the last line) compiles: == T.hs == {-# LANGUAGE TemplateHaskell #-} data Foo = Foo { bar :: Bar } data Bar = Bar $( return [] ) == It looks like the scope is interrupted just above $( ... ) - but I'd like to know why and find a more beautiful way than just moving all th calls to the bottom of the module file :) Regards Stephan -- Früher hieß es ja: Ich denke, also bin ich. Heute weiß man: Es geht auch so. - Dieter Nuhr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] uvector package appendU: memory leak?
Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Today I have rewritten my program to use `alter` and `snocU`: append Nothing = Just $ singletonU (a :*: b) append (Just u) = Just $ snocU u (a :*: b) alter append k m This, finally, works. Unfortunately I'm still not able to load the entire Netflix Prize training data set, grouping ratings by customers, because my PC has only 2 GB of RAM. The required memory is about 2 GB, but when the system start to swap, I have to kill the program. So the question is: why appending an array of only one element to an existing array causes memory problems? This should be pratically the same as adding an element. Thanks Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
manlio_perillo: Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Today I have rewritten my program to use `alter` and `snocU`: append Nothing = Just $ singletonU (a :*: b) append (Just u) = Just $ snocU u (a :*: b) alter append k m This, finally, works. Unfortunately I'm still not able to load the entire Netflix Prize training data set, grouping ratings by customers, because my PC has only 2 GB of RAM. The required memory is about 2 GB, but when the system start to swap, I have to kill the program. So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell messes up scoping?
Hi Stephan, Stephan Friedrichs wrote: Hi, when I tried to reorganize some code to use the data-accessor and data-accessor-template packages, i stumbled across a strange effect: When using template haskell some things are out of scope that really shouldn't be. Apart from the specific problematic file you gave, I had some other scoping issues when using TH to generate the accessors. I worked around this by defining my data types in a separate module Types and calling the TH functions in that module as the last lines. Then I had my other modules import Types, bringing the types and the accessors back in scope. See: http://code.google.com/p/custard/source/browse/trunk/MudTypes.hs Hope this helps, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell messes up scoping?
It looks like the scope is interrupted just above $( ... ) - but I'd like to know why and find a more beautiful way than just moving all th calls to the bottom of the module file :) Top-level splices can introduce bindings. IIRC, the current TH implementation uses a simple sequencing approach, preventing splices to be part of a recursive dependency chain. If you have A; $(S); B then first A is compiled, then S, then B. So, B can refer to what S builds, but neither A nor S can refer to B. Btw, there is a TH mailing list, and a wiki page with links to tutorials and papers, needed given the sparsity of the Haddocks: http://www.haskell.org/haskellwiki/Template_Haskell Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
On Sun, 29 Mar 2009, Peter Verswyvelen wrote: Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get server://program/B (that B is required is usually discovered after a compilation error, talking to other developers to find out what the dependencies are, or by reading the cabal file). Furthermore it is unclear which version of A required which version of B (so you can't really roll back to old versions). Now assume you don't have 2 modules but dozens... To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. So my question is really, how do you solve the dependency tracking between several Darcs repositories? There's an (unimplemented) proposal by David Roundy for darcs sub-repos that would solve this problem: you have a darcs patch type that means depend on this patch from this other darcs repo which will be checked out in a given subdirectory. I think that solves precisely the problem you describe, and I think it should be implemented :-) Ganesh ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what happens to the temporary memory used for array copying? I have executed the program with: +RTS -A128M -s -c -F1.1 -RTS The memory seems to leak. -- Don Thanks Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
On Sun, Mar 29, 2009 at 10:04 PM, Ganesh Sittampalam gan...@earth.liwrote: There's an (unimplemented) proposal by David Roundy for darcs sub-repos that would solve this problem: you have a darcs patch type that means depend on this patch from this other darcs repo which will be checked out in a given subdirectory. I think that solves precisely the problem you describe, and I think it should be implemented :-) Yep, that sounds really good. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
Correct, if it can be stated as a Rational then it terminates. I was messing around last night with the first function on a sequence that approximates sqrt(2) cf (take 25 (1: [2,2..])) forgetting that while the sequence is infinite, I only grabbed the first 25 elements. Your replacement code works fine except for a missing import Data.Ratio It's quite removed from what I was trying so I'm going to have to read ahead a bit to understand it. Thanks, Michael --- On Sun, 3/29/09, Daniel Fischer daniel.is.fisc...@web.de wrote: From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-cafe] Rational and % operator remix To: haskell-cafe@haskell.org Cc: michael rice nowg...@yahoo.com Date: Sunday, March 29, 2009, 2:35 PM -Inline Attachment Follows- Am Sonntag 29 März 2009 19:40:19 schrieb michael rice: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, Not for rational numbers. but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. That should be '=='. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) import Data.List (unfoldr) cf3 :: Rational - [Integer] -- Int may overflow cf3 0 = [0] cf3 x = a0:unfoldr f r where a0 = floor x r = x - fromInteger a0 f 0 = Nothing f y = Just (properFraction $ recip y) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
manlio_perillo: Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what happens to the temporary memory used for array copying? I have executed the program with: +RTS -A128M -s -c -F1.1 -RTS The memory seems to leak. Send me a test case. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me. I did the things you suggested, but I think the last one may have gotten garbled. Anyway, this is what I ended up with cf2 :: Rational - [Int] cf2 a = let ai = floor a in if a == (toRational ai) then [ai] else ai : cf2 (1 / (a - ai)) but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where did I go wrong or what did I leave out? Michael --- On Sun, 3/29/09, Lennart Augustsson lenn...@augustsson.net wrote: From: Lennart Augustsson lenn...@augustsson.net Subject: Re: [Haskell-cafe] Rational and % operator remix To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Sunday, March 29, 2009, 2:29 PM You can use floor in a Rational directly, no need to take it apart and divide. There is no need to write (toRational 1), just write 1. Don't write (subtract ai a), write (ai - i). You also have a type error; the ai should no be a Rational, so you need to move to toRational call to the comparison. -- Lennart 2009/3/29 michael rice nowg...@yahoo.com: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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: Darcs - dependencies between repositories (aka forests)
Peter Verswyvelen bugf...@gmail.com writes: Mmm, my email was indeed very unclear about my question. A very simple example: suppose a development team is working on a program. This program consist of modules A and B. Each module has it's own Darcs repository. Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get server://program/B (that B is required is usually discovered after a compilation error, talking to other developers to find out what the dependencies are, or by reading the cabal file). Furthermore it is unclear which version of A required which version of B (so you can't really roll back to old versions). Now assume you don't have 2 modules but dozens... I can't imagine such kind of situation, unless you are really working on a very big project. Usually, if your project depends on other projects, mostly it should work with stable version of other projects, but not their develop version. You might need some features of other projects that is still under development, than you might have a few repositories. However, such situation should be well known across all developers of your project. And usually you guys should agree on one particular develop version of those dependency projects, to make sure that you guys are working with the same set of API's. If those aforementioned dependency projects are just some modules within your big projects, I think the way to go is actually make them in the same repository. I can't see the benefit of splitting those small modules to different repositories, apart from not letting other people know your current developing code. But we are using a distributed revision control system, as darcs is, you can choose which patch to push to the upper stream anyway. So my point of view is that it is a management issue rather than a issue of revision control system. The developers should actually agree upon a proper set of API's before you guys actually start building the modules separately. Another reason for such kind of RCS built-in dependency check being impossible is that darcs are basically dealing with a bunch of dependent patches. Those patches only know their dependencies within a particular repository. You can't logically put a dependency of an external repository before you start pulling from that repository. To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. Can you provide some examples of RCS that have such kind of dependency system? So my question is really, how do you solve the dependency tracking between several Darcs repositories? Because every source tree is a branch in darcs, you can't. -- c/*__o/* \ * (__ */\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
On 2009 Mar 29, at 16:19, michael rice wrote: but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where did I go wrong or what did I leave out? cf2 returns [Int], but you're using it as the tail of a list starting with ai, which is a Rational. Need to decide which you actually want. At a guess: cf2 a = let ai = floor a rai = toRational ai in if a == rai then [ai] else rai : cf2 (1 / (a - ai)) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
On 2009 Mar 29, at 16:26, Xiao-Yong Jin wrote: Peter Verswyvelen bugf...@gmail.com writes: Module A requires B. When a new developer wants to get the source code, he does a darcs get server://program/A, which gives him only the latest version of A. So he manually needs to do darcs get server://program/ B (that B is required is usually discovered after a compilation error, talking to other developers to find out what the dependencies are, or by reading the cabal file). Furthermore it is unclear which version of A required which version of B (so you can't really roll back to old versions). Now assume you don't have 2 modules but dozens... I can't imagine such kind of situation, unless you are really working on a very big project. Usually, if your Ever looked at ghc's source? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
On 2009 Mar 29, at 16:27, Brandon S. Allbery KF8NH wrote: cf2 a = let ai = floor a rai = toRational ai in if a == rai then [ai] else rai : cf2 (1 / (a - ai)) Nope, went a bit too fast there, ignore me -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
cf2 :: Rational - [Int] cf2 a = let ai = floor a -- Doesn't this make ai an Int? -Michael in if a == (toRational ai) then [ai] else ai : cf2 (1 / (a - ai)) --- On Sun, 3/29/09, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-cafe] Rational and % operator remix To: michael rice nowg...@yahoo.com Cc: Brandon S. Allbery KF8NH allb...@ece.cmu.edu, Lennart Augustsson lenn...@augustsson.net, haskell-cafe@haskell.org Date: Sunday, March 29, 2009, 4:27 PM On 2009 Mar 29, at 16:19, michael rice wrote:but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where did I go wrong or what did I leave out? cf2 returns [Int], but you're using it as the tail of a list starting with ai, which is a Rational. Need to decide which you actually want. At a guess: cf2 a = let ai = floor a rai = toRational ai in if a == rai then [ai] else rai : cf2 (1 / (a - ai)) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.comsystem administrator [openafs,heimdal,too many hats] allb...@ece.cmu.eduelectrical and computer engineering, carnegie mellon university KF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Since 'insertWith' doesn't actually do the 'appendU', the appends will also be compressed in time, at point of use, rather than spread out in time, over construction. Which might be inconvenient if large volumes of data are involved. So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. And doing this repeatedly, with arrays of increasing length, would not be a good idea. For single-threaded use, one might use fusion to avoid the construction/recopying of the intermediate arrays. As usual, if the single-threading happens in the body of a recursive loop, compile-time fusion won't get a chance to work unless one unfolds the recursion a few steps. But one could do similar fusion dynamically, by partially reifying the construction functions (if we are appending an array that is itself created via append, then a single combined append will do). Wasn't there once a similar issue with strict bytestrings and cons? Ah, found it - different mailing list: http://www.haskell.org/pipermail/glasgow-haskell-users/2006-November/011603.html Was this actually resolved? From a quick glance, it seems I suggested runtime fusion, Don answered with compile-time fusion, Duncan suggested a different hack to achieve runtime fusion. But was the runtime fusion of nested cons in strict bytestring, or nested appends in uvector, ever implemented? Does the stream-fusion framework handle that implicitly? Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
cf2 a = let ai = floor a air = toRational ai in ai : if a == air then [] else cf2 (1 / (a - air)) On 30 Mar 2009, at 00:19, michael rice wrote: I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me. I did the things you suggested, but I think the last one may have gotten garbled. Anyway, this is what I ended up with cf2 :: Rational - [Int] cf2 a = let ai = floor a in if a == (toRational ai) then [ai] else ai : cf2 (1 / (a - ai)) but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where did I go wrong or what did I leave out? Michael --- On Sun, 3/29/09, Lennart Augustsson lenn...@augustsson.net wrote: From: Lennart Augustsson lenn...@augustsson.net Subject: Re: [Haskell-cafe] Rational and % operator remix To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Sunday, March 29, 2009, 2:29 PM You can use floor in a Rational directly, no need to take it apart and divide. There is no need to write (toRational 1), just write 1. Don't write (subtract ai a), write (ai - i). You also have a type error; the ai should no be a Rational, so you need to move to toRational call to the comparison. -- Lennart 2009/3/29 michael rice nowg...@yahoo.com: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Rational and % operator remix
Works like a charm. Here's a final copy for those interested. Michael = import Data.Ratio cf2 :: Rational - [Int] cf2 a = let ai = floor a air = toRational ai in ai : if a == air then [] else cf2 (1 / (a - air)) --- On Sun, 3/29/09, Miguel Mitrofanov miguelim...@yandex.ru wrote: From: Miguel Mitrofanov miguelim...@yandex.ru Subject: Re: [Haskell-cafe] Rational and % operator remix To: michael rice nowg...@yahoo.com Cc: Lennart Augustsson lenn...@augustsson.net, haskell-cafe@haskell.org Date: Sunday, March 29, 2009, 4:25 PM cf2 a = let ai = floor a air = toRational ai in ai : if a == air then [] else cf2 (1 / (a - air)) On 30 Mar 2009, at 00:19, michael rice wrote: I'm a Lisper, kind of feeling my way around here in Haskell, so please bear with me. I did the things you suggested, but I think the last one may have gotten garbled. Anyway, this is what I ended up with cf2 :: Rational - [Int] cf2 a = let ai = floor a in if a == (toRational ai) then [ai] else ai : cf2 (1 / (a - ai)) but I'm still at least one error short of a clean run Main :load cf.hs ERROR cf.hs:7 - Type error in application *** Expression : ai : cf2 (1 / (a - ai)) *** Term : ai *** Type : Ratio Integer *** Does not match : Int Where did I go wrong or what did I leave out? Michael --- On Sun, 3/29/09, Lennart Augustsson lenn...@augustsson.net wrote: From: Lennart Augustsson lenn...@augustsson.net Subject: Re: [Haskell-cafe] Rational and % operator remix To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Sunday, March 29, 2009, 2:29 PM You can use floor in a Rational directly, no need to take it apart and divide. There is no need to write (toRational 1), just write 1. Don't write (subtract ai a), write (ai - i). You also have a type error; the ai should no be a Rational, so you need to move to toRational call to the comparison. -- Lennart 2009/3/29 michael rice nowg...@yahoo.com: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
Manlio Perillo ha scritto: Hi. As with a previous post, I think I have found a possible memory problem with the uvector package. I have this data structure (for, again, my Netflix Prize project): IntMap (UArr (Word16 :*: Word8)) [...] Today I have rewritten my program to use `alter` and `snocU`: append Nothing = Just $ singletonU (a :*: b) append (Just u) = Just $ snocU u (a :*: b) alter append k m [...] Unfortunately I'm still not able to load the entire Netflix Prize training data set, grouping ratings by customers, because my PC has only 2 GB of RAM. The required memory is about 2 GB, but when the system start to swap, I have to kill the program. Just another small strictness hint: append (Just u) = u `seq` Just $ snocU u (a :*: b) and now memory usage is 955 MB. Regards Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Is Text.XHtml.Table usable?
I was playing with Text.XHtml.Table but couldn't use it to output tables. ( cell . toHtml $ a ) `beside` (cell . toHtml $ b ) tr a b /tr already seems wrong -- should be two cells, right? And the result doesn't get embedded in a table tag? Is there something I'm missing? Working code samples would be great. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
Claus Reinke ha scritto: IntMap (UArr (Word16 :*: Word8)) I was adding elements to the map using something like: v = map singletonU (a :*: b) insertWith appendU k v m However doing this eats a *lot* of memory. Since 'insertWith' doesn't actually do the 'appendU', the appends will also be compressed in time, at point of use, rather than spread out in time, over construction. Which might be inconvenient if large volumes of data are involved. Ah, ok; that may explain the problem, but I'm still not sure. With this program: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=3063 Memory usage seems ok. 955 MB, against 622 MB when ratings are grouped by movies ( using [(MovieID, UArr (Word32 :*: Word8))] ) The version using `insertWith appendU` is here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=3063#a3065 I still can not explain so much difference in memory usage. So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. And doing this repeatedly, with arrays of increasing length, would not be a good idea. I can't really see other solutions. For single-threaded use, one might use fusion to avoid the construction/recopying of the intermediate arrays. Fusion is not possible, in my case, IMHO. I'm parsing movie ratings, where we have customers ratings for each movie in separate files (17770 total movies). Each file has format movie1: customer1,rating1,date1 customer2,rating2,date2 ... movie2: customer3,rating3,date3 ... I want to group ratings by customers, instead of grouping them by movies. Stream fusion is only possible in the latter case (but in this case I don't even need an IntMap). I'm missing something? [...] Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
Don Stewart ha scritto: manlio_perillo: Don Stewart ha scritto: [...] So the question is: why appending an array of only one element to an existing array causes memory problems? It must copy the entire array. Isn't it the same with snocU? And, since the final result is the same, what happens to the temporary memory used for array copying? I have executed the program with: +RTS -A128M -s -c -F1.1 -RTS The memory seems to leak. Send me a test case. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=3071 But Claus was right, appendU is lazy; this seems to be the cause of the problem. However now I don't really understand why the two implementations differs in lazyness. Or, to ask a different question, how can I make the version using insertWith strict? Thanks Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
On Sun, Mar 29, 2009 at 10:26 PM, Xiao-Yong Jin xj2...@columbia.edu wrote: Now assume you don't have 2 modules but dozens... I can't imagine such kind of situation, unless you are really working on a very big project. Usually, if your project depends on other projects, mostly it should work with stable version of other projects, but not their develop version. You might need some features of other projects that is still under development, than you might have a few repositories. However, such situation should be well known across all developers of your project. And usually you guys should agree on one particular develop version of those dependency projects, to make sure that you guys are working with the same set of API's. Even if you have just two modules, manually keeping track which version used which other version feels error prone. And you need that when you want to revert to old versions (which I heard is very hard to do with Darcs anyway, but I can't confirm that, haven't tried it yet) I don't think it is realistic to expect that for a project of medium to large size that you work only with stable versions of modules (this would exclude most packages on Hackage I guess). I understand this is the way it *should* be, but I don't think it often does. I prefer to use some unstable packages from Hackage, and contribute bugfixes or even enhancements to these packages. If those aforementioned dependency projects are just some modules within your big projects, I think the way to go is actually make them in the same repository. Yep, that's the way it's usually done. But when you have multiple teams working on different modules within the same repository, this gets annoying. I can't see the benefit of splitting those small modules to different repositories, apart from not letting other people know your current developing code. But we are using a distributed revision control system, as darcs is, you can choose which patch to push to the upper stream anyway. So my point of view is that it is a management issue rather than a issue of revision control system. Currently it mostly is a management issue, and so it often goes wrong :) The developers should actually agree upon a proper set of API's before you guys actually start building the modules separately. In an idealized world I agree, but with modern agile software development methodologies, these APIs also evolve... Another reason for such kind of RCS built-in dependency check being impossible is that darcs are basically dealing with a bunch of dependent patches. Those patches only know their dependencies within a particular repository. You can't logically put a dependency of an external repository before you start pulling from that repository. Sure, but that sounds like a current limitation, doesn't seem like this is impossible to extend. To me, any version control system should be able to track dependencies between repositories. Something similar like Cabal's dependency system. Can you provide some examples of RCS that have such kind of dependency system? Mercurial had an extensionhttp://www.selenic.com/mercurial/wiki/index.cgi/ForestExtensionfor this. I'm not sure but maybe ClearCase and Accurev also support something like. A couple of years ago I also developed a version control system (closed source, private solution for customer, NTFS only) that supported dependencies between repositories ( too bad that company did not want to release the software as open source :| ) So my question is really, how do you solve the dependency tracking between several Darcs repositories? Because every source tree is a branch in darcs, you can't. Too bad. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] uvector package appendU: memory leak?
But Claus was right, appendU is lazy; this seems to be the cause of the problem. appendU is strict, insertWith just doesn't force it (follow the source link in the haddocks to see why). However now I don't really understand why the two implementations differs in lazyness. Or, to ask a different question, how can I make the version using insertWith strict? deja vu:-( http://www.haskell.org/pipermail/haskell-cafe/2009-March/057032.html As you've noticed, alter also allows to enforce strictness. But piling up appendUs is still not a good idea. For a moment, I thought that the stream representation's (+++) was handling runtime fusion gracefully, but a simple test case suggests otherwise at least for the simpler case of consU (the attached appendU.hs doesn't do any appendUs, as the consU case already demonstrates the issue; be careful with large numbers here, it'll quickly eat your ram): The test is a silly loop, using consU a lot (which isn't uvectors main target), to copy an array. The difference between the plain loop and the unfolded loop shows that compile-time fusion can improve this, suggesting that no runtime fusion is taking place. The simulated runtime fusion version demonstrates (by staying within lists till the end, only then switching back to arrays, avoiding all the intermediate partial array copies). The old bytesting cons thread I linked to was about integrating real runtime fusion into things like bytestring/uvector. Claus appendU.hs Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] type-level programming support library
I've been doing some basic work on a support library for type level programming ( see http://hackage.haskell.org/trac/summer-of-code/ticket/1541 ). I know there have been similar attempts using fundeps ( Edward Kmett showed me some of his work, but I've lost the address... ) but this approach uses type families. Anyway, I would like to hear your critique! Currently I have higher order type functions and ad-hoc parametrized functions. Here's what foldl looks like: type family Foldl ( func :: * - * - * ) val list type instance Foldl func val ( Cons first rest ) = Foldl func ( Eval ( func val first ) ) rest type instance Foldl func val Nill = val Notice the use of Eval - this is a trick to enable us to pass around data with kind * - *, or whatever, and then trip this into becoming a value. Here's an example, using this trick to define factorial: -- multiplication type family Times x y type instance Times x Zero = Zero type instance Times x ( Succ y ) = Sum x ( Times x y ) -- The first order function version of Times data TimesL x y -- Where what Eval forced TimesL to become. type instance Eval ( TimesL x y ) = Times x y -- multiplies all the elements of list of Nat together type Product l = Foldl TimesL ( Succ Zero ) l -- here list to creates a list from ( Succ Zero ) to the given number type Factorial x = Product ( ListTo x ) We can now use the function like this: *TPrelude result ( ) :: Factorial ( Succ ( Succ ( Succ ( Zero ) ) ) ) Succ (Succ (Succ (Succ (Succ (Succ Zero) Using the parametrized types kinda reminds me of programming in Erlang: -- What would conventionally be the monad type class, parametized over m type family Bind m ma ( f :: * - * ) type family Return m a type family Sequence m ma mb Here's the maybe monad: -- Monad instance type instance Bind ( Maybe t ) Nothing f = Nothing type instance Bind ( Maybe t ) ( Just a ) f = Eval ( f a ) type instance Sequence ( Maybe t ) Nothing a = Nothing type instance Sequence ( Maybe t ) ( Just a ) b = b type instance Return ( Maybe t ) a = Just a type instance Eval ( Just x ) = Just x Here's an example: *TPrelude result ( ) :: Bind ( Maybe Nat ) ( Just Zero ) Just Just Zero For more information and to download the loose collection of module implementing this please see: http://www.killersmurf.com/projects/typelib John Morrice ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is Text.XHtml.Table usable?
Thomas Hartman wrote: I was playing with Text.XHtml.Table but couldn't use it to output tables. ( cell . toHtml $ a ) `beside` (cell . toHtml $ b ) tr a b /tr already seems wrong -- should be two cells, right? And the result doesn't get embedded in a table tag? 'cell' is not a TD element, it's an abstraction used to manage cells and deal with arbitrary numbers of rows and columns. You won't normally use 'cell' directly, but it gets used when laying out a table. Here's a simple two-cell table: table (td a ) `beside` (td b ) TABLE TR TD a /TD TD b /TD /TR /TABLE Note that 'beside' has an infix version, -. 'above' also has an infix version, /. So here's a 2x2 table: table (td a - td b / td c - td d) (I haven't included the HTML output, but it works.) To see what 'cell' does, we can create a table with cell widths and heights other than 1. In GHCi: let twoDown = (td a / td b) let threeAcross = (td d - td e - td f) let threeDown = (td g / td h / td i) let oneTopTwoBottom = (td j / td k - td l) table (twoDown - threeAcross - threeDown - oneTopTwoBottom) The 'cell' function doesn't get called explicitly above, but it gets used internally. Try it, the results are fairly self-explanatory. Anton ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell] Re: [Haskell-cafe] ANN: cmonad 0.1.1
Nested constructed product returns? Or constructed sums? lennart: Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc lacks a crucial optimization for specialization of constructor returns. With that in place I think the code could be quite performant. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: wxAsteroids 1.0
On Fri, 27 Mar 2009 15:34:06 +0100, Henk-Jan van Tuyl hjgt...@chello.nl wrote: On Thu, 26 Mar 2009 20:41:57 +0100, Henk-Jan van Tuyl hjgt...@chello.nl wrote: Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is a game demonstrating the wxHaskell GUI. More about this at: http://www.haskell.org/haskellwiki/wxAsteroids Maybe I should add more informationn to this: The main purpose of this game is to learn how to use wxHaskell; it also shows, in the main function, how a cabalized program can find its data files. I don't want to take the credit for this program; I took the source code and images from the paper: wxHaskell - A Portable and Concise GUI Library for Haskell [1] by Daan Leijen. If you want to learn how to use wxHaskell, I can advise you to read this paper. Daan gave me permission to publish the code with a BSD license. [1] http://legacy.cs.uu.nl/daan/download/papers/wxhaskell.pdf This sounds entertaining, but according to the HaskellWiki entry for GuiTV (see http://haskell.org/haskellwiki/GuiTV), wxHaskell ... can be difficult to install. Has this difficulty been resolved? I am somewhat hesitant to install wxHaskell because of this reported difficulty. Has anybody had any recent difficulties in installing this package combination on Windows XP Professional, Service Pack 2? -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 Furuike ya, kawazu tobikomu mizu no oto. -- Matsuo Basho^ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe