Re: [Haskell-cafe] Functors and the Visitor Pattern
Tom.Amundsen wrote: So, last night, I was having this problem with my Java code where I couldn't figure out for the life of me how to write a piece of code without a big if {} else if {} else if {} ... else {} structure. I was Googling Java Reflection to try to determine how to cast to the most concerete subclass at runtime. Then it dawned on me that what I was trying to do has already been solved by using the Visitor design pattern. Then, after reading the Visitor design pattern page on Wiki, it said that the visitor pattern is essentially an implementation of a functor. Aha! It totally clicked. The Visitor pattern allows you to collect code for similar operations, while spreading apart code for similar objects. Now that really sounds like a functor! Although, now I'm second guessing myself, because I can't figure out how we could create some design pattern that simulates an applicative functor. I'm pretty sure the Visitor pattern doesn't take you this far (but I am willing to be corrected). So, is there a way to create applicative functors in non-functional languages? What would that pattern look like? The Visitor pattern isn't a functor, it's a collection of things. The type being visited is the functor[1], the set of methods on that type for accepting a visitor is a catamorphism[2], and the visitor itself is an algebra for the functor[3]. [1] Or rather, the coproduct of all related classes that can chain a visitor forms a type, and that type is a functor. [2] For the recursive Visitor pattern I use most often, that is. For the non-recursive version it's usually fmap. This is the part where the pattern gets a bit shaky because there are actually many different patterns all called Visitor. The main points of interest are whether it's recursive or not, and whether it applies the visitor to itself, to its children, or both. non-recursive + itself == ($) non-recursive + children == fmap (under open-recursion interpretation of the type, aka all nodes are elements) recursive + children == fmap (under closed-recursion interpretation, aka only fringe nodes are elements) recursive + both == cata (usually, though it depends how you aggregate) recursive + itself == This is actually a variant of the Iterator pattern [3] Though again there's some variation in different Visitor patterns. Some variants of the pattern include some of the recursion pattern in the visitor itself rather than in the methods on the visited type. It can be harder to maintain since it's less modular, though it allows the visit methods to serve as many different functions which can be helpful if you need more than one of ($), fmap, cata, traverse,... -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] measure a function in ghci
Jason Dagit da...@codersbase.com writes: Be wary of timing things in GHCi. By default there are no optimizations in ghci so you could find that one implementation is much worse than the other but the situation might be completely different when optimizations are enabled. I'm pretty sure if you start ghci with the -O flag that it will use optimizations. ...or if you compile your module first (ghc -c), I believe GHCi will use the compiled code. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: memscript-0.0.0.2 (Command line utility for memorizing scriptures or any other text)
memscript: Command line utility for memorizing scriptures or any other text http://hackage.haskell.org/cgi-bin/hackage-scripts/package/memscript memscript filename Run memscript with a UTF-8 (or ASCII since ASCII is a subset of UTF8) plain text file. Try to exactly guess the text line by line. If your guess is wrong it will show you a diff like output comparing your guess and the original verse. This will repeat until you get all the verses right. For the test data I included four beloved Psalms (1,23,121,127) from the Old Testament, each in Revised Korean Version (RKV) and New International Version (NIV), which I happened to have had to memorize. You can use it for any other text you'd want to memorize, such as your favorite poems, quotes, or whatsoever. No craft or ticks, really simple and straightforward utility but serves well for the purpose. I used readline because that was the only sane way I know of handling multibyte inputs. an example usage kya...@kyagrd:~/cscs/memscript$ memscript 001en.txt % Blessed is the man who does not walk in the counsel of the wicked or stand in the way of sinners or sit in the seat of mockers. % But his delight is in the law of the LORD, and on his law he meditates night and day. === But his delight is in the law of the LORD, and on his law he meditates day and night. --- But his delight is in the law of the LORD, and on his law he meditates night and day. === % But his delight is in the law of the LORD, and on his law he meditates day and night. % He is like a tree planted by streams of water, which yields its fruit in season and whose leaf does not wither. Whatever he does prospers. % Not so the wicked! They are like chaff that the wind blows away. % The wicked will not stand in the judgment, nor sinners in the assembly of the righteous. === Therefore the wicked will not stand in the judgment, nor sinners in the assembly of the righteous. --- The wicked will not stand in the judgment, nor sinners in the assembly of the righteous. === % Therefore the wicked will not stand in the judgment, nor sinners in the assembly of the righteous. % For the LORD watches over the way of the righteous, but the way of the wicked will perish. kya...@kyagrd:~/cscs/memscript$ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Text formatting question
I'm writing code with hslogger, and I'm finding myself frequently writing things like this: infoM $ printf %s saw %s with %s (show x) (show y) (show z) On #haskell I asked about why you can't have use %s with any instance of (Show a), and augustss, the Text.Printf maintainer, pointed out that it's not possible in Haskell 98 because of overlapping instances. So I'm trying to figure out the best way to work around this in my code. Some of the logging statements can get kind of long, so the ability to elide the calls to `show` would be nice. So what's the best way to do this? I was thinking of making my own variant of printf that only accepted the %s formatter and took (Show a)'s as arguments, but there might be a simpler way? Another thing is the code is already fairly GHC specific at this point, so if there are GHC extensions that might be useful here that I don't know about, I'm interested in hearing about them. Thanks. -- Evan Klitzke e...@eklitzke.org :wq ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] type checking that I can't figure out ....
Daniel Peebles wrote: Yeah, in a way similar to ArrowPlus/ArrowZero. Then again, I'm not sure whether it would be meaningful to split up MonadPlus like that. Well, we could always have: class MonadZero m = MonadPlus m The suggestion is just to broaden the scope of mzero so that you can have it without requiring mplus as well (since mplus is much more specific than mzero). If we have a MonadZero, then the call to fail when pattern binds fail could be replaced with calls to mzero (or at the very least, fail can be moved to MonadZero as well to clean up Monad). Then Monad is clean and accurate, and people just depend on MonadZero if they choose to do pattern binds rather than catching all patterns with a case expression. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functors and the Visitor Pattern
On Thu, Jun 4, 2009 at 9:13 AM, wren ng thornton w...@freegeek.org wrote: The Visitor pattern isn't a functor, it's a collection of things. The type being visited is the functor[1], the set of methods on that type for accepting a visitor is a catamorphism[2], and the visitor itself is an algebra for the functor[3]. [1] Or rather, the coproduct of all related classes that can chain a visitor forms a type, and that type is a functor. [2] For the recursive Visitor pattern I use most often, that is. For the non-recursive version it's usually fmap. This is the part where the pattern gets a bit shaky because there are actually many different patterns all called Visitor. The main points of interest are whether it's recursive or not, and whether it applies the visitor to itself, to its children, or both. non-recursive + itself == ($) non-recursive + children == fmap (under open-recursion interpretation of the type, aka all nodes are elements) recursive + children == fmap (under closed-recursion interpretation, aka only fringe nodes are elements) recursive + both == cata (usually, though it depends how you aggregate) recursive + itself == This is actually a variant of the Iterator pattern Could you be so kind to give an example for each? Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] understanding regex libs
On Wed, Jun 3, 2009 at 5:18 PM, Simon Michael si...@joyful.com wrote: Hi Chris.. thanks for your extensive work on haskell regex libs. I'm looking for a good way to make my regex-using app more portable to windows. I couldn't figure out the difference between the regex-pcre and regex-pcre-builtin on hackage. Could you clarify ? Once you find out please update the page on the wiki covering the different regular expression libs available for Haskell: http://haskell.org/haskellwiki/Regular_expressions AFAICS it lacks information on portability of the non-native libs. /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Scary type inference for monadic function definitions
Ahn, Ki Yung wrote: Scary type inference for monadic function definitions (or, why you'd want to annotate types for monadic function definitions) This is a real example that I've experienced. I defined the following function. checkOneVerseByLineWith readLine v = do mg - readLine case mg of Just g - return Just (v==g) Nothing - return Nothing How about liftM (fmap (v==)) readLine ? -- Mit freundlichen Gruessen Henning Thielemann Viele Gruesse Henning Martin-Luther-Universitaet Halle-Wittenberg, Institut fuer Informatik Tel. +49 - 345 - 55 24773 Fax +49 - 345 - 55 27333 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabalizing legacy' source
Vasili I. Galchin wrote: Hello, I have cabalizing some legacy Haskell source. By legacy, I totally don't mean in a pejorative sense ... code has been designed and written well. I am making good progress ... I have succeeded in building an archive file(library) on a POSIX platform, i.e. Linux. The original author intended to build several executables from this .a file. In addition there are many pairings of .hs/.lhs along with main test files. Currently I have only one .cabal file. This is inadequate for the author's intent: 1) I need to build n test executables. 2) I need to build 1/2 CLI executables. I need advice on the cabal front. E.g. should I first run the library .cabal and then run several subsidary .cabal files, e.g. ntest .cabals and also 1/2 CLI executable .cabals??? I am looking for advice so that I don't have a clumsy cabal build process/tree! You can build several executables from one cabal file. I propose to enable compilation of test programs only by user request. See for example: http://code.haskell.org/~thielema/tagchup/tagchup.cabal ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Strange type error with associated type synonyms
Hello, Apologies for the late contribution; I've been away recently. I have a very strong opinion on this, though. From: Bulat Ziganshin bulat.zigans...@gmail.com Thursday, May 28, 2009, 2:06:36 AM, HT wrote: Prelude let a = 'a'; b = b in a==b interactive:1:27: Couldn't match expected type `Char' against inferred type `[Char]' Is the type of 'a' wrong or that of 'b'? it is not important, well, at least we can live with it. Compiler should say: First argument of == should be of type String while a is of type Char I find this to be a somewhat important issue. If there weren't so many polymorphic functions it wouldn't be as big of a problem. The only reason the first argument of == should be a String is because the second argument is (or alternatively 2nd should be Char, etc.). For polymorphic functions, in which the type of one argument is fixed by another, I think the error message should ideally point out how the compiler is getting expected/inferred types. E.g. Couldn't match expected type `Char' against inferred type `[Char]' Type of [first argument] to `==' must match type of [second argument] where [first|second argument] is filled in with the appropriate expressions. I've become somewhat adept at figuring this out, but I think it would be helpful for those who haven't experienced it before. A related issue is with multiple function definitions. Here's a short example: foo n = ... where bar (Just a) = return $ somefunc a bar (Nothing) = somefunc n a = otherfunc assume that 'a' and 'n' have the same type. Now the type checker won't allow bar, because the two definitions have differing types. GHC's error message would ideally state that the definitions for 'bar' have differing types, but instead we get a message about mismatched types within one of the definitions. I know this example is rather contrived, but I don't have any real code to hand because I've fixed it already. You get a better message if you give a type signature for 'bar', but that requires lexical scoping (at least in my case), which means the code would no longer be Haskell98 (which it otherwise is IIRC). Cheers, John Lato ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Nested Lists
Hi all, If I have a list, and I'd like to convert it to a list of lists, each of length n, I can use a function like bunch: bunch _ [] = [] bunch n as = let (c,cs) = splitAt n as in c:bunch n cs bunch 8 [1..16] [[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]] If I now want to do the same for the nested lists, I can compose an application involving both map and bunch: map (bunch 4) . bunch 8 $ [1..16] [[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]] and I can bunch the new length 4 lists again: map (map (bunch 2)) . map (bunch 4) . bunch 8 $ [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 Clearly there is a pattern here involving the bunch function and latterly, three Int parameters; 2, 4 and 8. My question is, can I create a function that will take such parameters as a list, and give the same result, for example: f [2,4,8] [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 or perhaps: f [bunch 2, bunch 4, bunch 8] [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 I think it may not be possible because the type signature of f would depend on the length of its list parameter; but I'm not sure. -Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Nested Lists
Hi Paul, I don't have time to solve your actual problem, but I think it's doable using associated type families. I attach a module which I'm using in my current project that does things quite similar to what you're asking for. For example: *Main replicateArray (3 : IntArr) 4 [4,4,4] *Main replicateArray (4 : 3 : IntArr) 4 [[4,4,4],[4,4,4],[4,4,4],[4,4,4]] Hope it helps! / Emil Paul Keir skrev: Hi all, If I have a list, and I'd like to convert it to a list of lists, each of length n, I can use a function like bunch: bunch _ [] = [] bunch n as = let (c,cs) = splitAt n as in c:bunch n cs bunch 8 [1..16] [[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]] If I now want to do the same for the nested lists, I can compose an application involving both map and bunch: map (bunch 4) . bunch 8 $ [1..16] [[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]] and I can bunch the new length 4 lists again: map (map (bunch 2)) . map (bunch 4) . bunch 8 $ [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 Clearly there is a pattern here involving the bunch function and latterly, three Int parameters; 2, 4 and 8. My question is, can I create a function that will take such parameters as a list, and give the same result, for example: f [2,4,8] [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 or perhaps: f [bunch 2, bunch 4, bunch 8] [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 I think it may not be possible because the type signature of f would depend on the length of its list parameter; but I'm not sure. -Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe {-# LANGUAGE TypeFamilies #-} class Storable a where data Dimension a type Element a listDimensions :: Dimension a - [Int] replicateArray :: Dimension a - Element a - a makeSquare :: Dimension a - Element a - a - a instance Storable Bool where data Dimension Bool = BoolArr type Element Bool = Bool listDimensions BoolArr = [] replicateArray BoolArr e = e makeSquare BoolArr _ = id instance Storable Int where data Dimension Int = IntArr type Element Int = Int listDimensions IntArr = [] replicateArray IntArr e = e makeSquare IntArr _ = id instance Storable a = Storable [a] where data Dimension [a] = Int : Dimension a type Element [a] = Element a listDimensions (n : ns) = n : listDimensions ns replicateArray (n : ns) a = replicate n (replicateArray ns a) makeSquare (n : ns) a as = as' ++ replicateArray (diff : ns) a where as' = take n (map (makeSquare ns a) as) diff = n - length as' infixr 5 : ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Nested Lists
How about... *Main bunch () [1..16] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] *Main bunch (8 :+: ()) [1..16] [[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]] *Main bunch (8 :+: 4 :+: ()) [1..16] [[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]] *Main bunch (8 :+: 4 :+: 2 :+: ()) [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 Here's the hack :) {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeFamilies #-} infixr 6 :+: data Bunch b = Int :+: b class Bunchable b a where type Bunched b a :: * bunch :: b - [a] - Bunched b a instance Bunchable () a where type Bunched () a = [a] bunch () = id instance Bunchable b a = Bunchable (Bunch b) a where type Bunched (Bunch b) a = [Bunched b a] bunch (n :+: r) = map (bunch r) . simpleBunch n simpleBunch :: Int - [a] - [[a]] simpleBunch _ [] = [] simpleBunch n as = let (c,cs) = splitAt n as in c:simpleBunch n cs The key here is that 'Bunch' reflects its lenght on its type, but '[]' doesn't. It may be possible to keep using a list, but it would be very ugly, I guess. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Static link to packages on Hackage?
Hi, I'd like to be able to put a static link to the Haddock docs for the current version of various packages on my homepage. Right now, I can't find any such URL; they all look like: http://hackage.haskell.org/packages/archive/HSH/2.0.0/doc/html/HSH.html I'd like if there could be something like: http://hackage.haskell.org/packages/archive/HSH/latest/doc/html/HSH.html Incidentally, you can click on this latest URL but it doesn't go to the correct version. I can't just link to the package page either, because sometimes it won't have docs (such as shortly after I've uploaded a new version). Ideas? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A small puzzle: inTwain as function of foldr
Bonjour café, A small puzzle: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Is there a general way to tell if a problem can be expressed as a fold? Thank you, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] A small puzzle: inTwain as function of foldr
Martijn van Steenbergen wrote: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Does this help? http://www.brics.dk/RS/02/12/BRICS-RS-02-12.pdf Ganesh === Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html === ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A small puzzle: inTwain as function of foldr
On Thu, Jun 4, 2009 at 4:22 PM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Bonjour café, A small puzzle: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? I don't think it is without a length before at least. On the other hand if your specification is just splits a list of even length evenly into two sublists, you can contrive something with a simple foldr : inTwain = foldr (\x ~(xs,ys) - (ys, x:xs)) ([],[]) -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Nested Lists
On Thu, 4 Jun 2009, Paul Keir wrote: Hi all, If I have a list, and I'd like to convert it to a list of lists, each of length n, I can use a function like bunch: bunch _ [] = [] bunch n as = let (c,cs) = splitAt n as in c:bunch n cs http://hackage.haskell.org/packages/archive/utility-ht/0.0.5.1/doc/html/Data-List-HT.html#v%3AsliceVertical bunch 8 [1..16] [[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]] If I now want to do the same for the nested lists, I can compose an application involving both map and bunch: map (bunch 4) . bunch 8 $ [1..16] [[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]] and I can bunch the new length 4 lists again: map (map (bunch 2)) . map (bunch 4) . bunch 8 $ [1..16] 1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16 Don't you first break the list into 2-element lists, then the resulting list into 2-element lists and so on? I.e. bunch 2 . bunch 2 . bunch 2 $ [1..16] Calling 'bunch' multiple times is problematic since every call has a different signature, a different depth of list nesting. I guess you have to use a tree type, which allows arbitrary list nesting at run-time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: Nested Lists
Emil, Felipe, Thanks. I don't know Type Families, but take the point that the input can be parameterised with something something other than a list. i.e. (8 :+: 4 :+: 2 :+: ()) presumably has the same type as (4 :+: 2 :+: ()). My intention was to use common list functions on the sublists, but always then a concat for each level, to return to a flat list. With that in mind I made the following oddity, which in any case doesn't compile due to its use of infinite types. app (f:fs) es = appUp (f:fs) es where len = genericLength (f:fs) appUp [] es = appDown es len appUp (f:fs) es = appUp (map map fs) (f es) appDown es len= appDown (concat es) (len - 1) appDown es 0 = es Henning, I agree with you, a tree would be much better for this. Thanks. -Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Static link to packages on Hackage?
http://hackage.haskell.org/packages/archive/HSH/latest/doc/html/HSH.html does take me to a page that says HSH-2.0.0: Library to mix shell scripting with Haskell programs in the blue bar at the top. Maybe some kind of cache? Did you try flushing your browser cache and refreshing? Am I missing something? Thomas On Thu, Jun 4, 2009 at 15:20, John Goerzenjgoer...@complete.org wrote: Hi, I'd like to be able to put a static link to the Haddock docs for the current version of various packages on my homepage. Right now, I can't find any such URL; they all look like: http://hackage.haskell.org/packages/archive/HSH/2.0.0/doc/html/HSH.html I'd like if there could be something like: http://hackage.haskell.org/packages/archive/HSH/latest/doc/html/HSH.html Incidentally, you can click on this latest URL but it doesn't go to the correct version. I can't just link to the package page either, because sometimes it won't have docs (such as shortly after I've uploaded a new version). Ideas? ___ 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] containers dependency on base
I have been unable to compile the stable version of containers-0.2.0.1, having to add the constraint base=4.0.0.0. Can anybody else duplicate this problem? Should I patch it? (I'm working on another modification to containers and encountered this difficulty when attempting to build the whole package.) Louis Wasserman wasserman.lo...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal/primes
On this note, shouldn't there be cabal uninstall? -- ryan On Wed, Jun 3, 2009 at 3:40 PM, Don Stewart d...@galois.com wrote: nowgate: Got it working. I downloaded two packages, primes and Numbers. Since Numbers has the three functions I want to use, primes, isPrime and isProbablyPrime, how do I uninstall the primes package so there won't be a conflict? Easy! $ ghc-pkg unregister primes -- Don ___ 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: wp-archivebot 0.1 - archive Wikipedia's external links in WebCite
I'd like to announce wp-archivebot. # What wp-archivebot is a relatively simple little script which follows all the links in a RSS feed, combs the destination for http:// links, and submits them to WebCite. WebCite https://secure.wikimedia.org/wikipedia/en/wiki/WebCite is an organization much like the more famous Internet Archive. Unlike the Wayback Machine, however, WebCite will archive pages on-demand.* # Why This is good, since link-rot and 404 errors are a fact of life on Wikipedia. Links go stale, fall dead, get banned, edited, censored, etc. If those links are being used as a reference for some important fact or detail, then there is a very big problem. Even the hit-or-miss Internet Archive has proven to be very useful for editors**, so a more reliable way of archiving links would be even better. # Limitations The WebCite FAQhttp://webcitation.org/faq mentions that a good project would be to develop a wikipedia bot which scans new wikipedia articles for cited URLs, submits an archiving request to WebCite®, and then adds a link to the archived URL behind the cited URL Adding a link would be both quite difficult and require community approval; further, although I have thought about this for years, there's no obvious good way to add a link. Any method is either visually awkward, possibly otiose (if [[Google]] links to google.com as the homepage in its infobox, there's no purpose to have an archived version of google.com!), and certainly will bloat up the markup - even if there's any way to insert links without bolloxing templates and other such constructs. So I'm satisfied to just archive the link. WebCite is searchable, after all. If enough people run bots like this and achieve enough coverage, then perhaps editors can be educated to always check in WebCite as well. # Download Install As ever, wp-archivebot is Free and is available from Hackage at: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wp-archivebot You can install with ease by a simple 'cabal install wp-archivebot', or download the tarball and compile it yourself with the usual 'runhaskell Setup configure runhaskell Setup build runhaskell Setup install' dance. # Usage wp-archivebot takes one mandatory argument, an email address; WebCite needs to have somewhere to send notices of archival success/failure. wp-archivebot takes a second, optional, argument. This is a RSS feed to use. It defaults to Special:NewPages on the English Wikipedia, but one could just as well follow, say, RecentChanges. Here's an example: wp-archivebot gwe...@gmail.com 'http://en.wikipedia.org/w/index.php?title=Special:RecentChangesfeed=rss' (This sets my email address as the recipient, and follows RecentChanges. This may not be a good idea as RecentChanges is *much* busier than NewPages.) ## Example Here's an example session's output: [12:35 PM] 829Mb$ wp-archivebot gwe...@gmail.com http://www.webcitation.org/archive?url=http://en.wikisource.org/wiki/Berkeley,_George,_first_earl_of_Berkeley_(DNB00)email=gwe...@gmail.com http://www.webcitation.org/archive?url=http://www.baseball-reference.com/players/u/uhaltfr01.shtmlemail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.baseball-reference.com/players/u/uhaltfr01.shtmlemail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.baseball-reference.com/minors/player.cgi?id=uhalt-001beremail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.baseball-reference.com/minors/player.cgi?id=uhalt-001beremail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.timesargus.com/apps/pbcs.dll/article?AID=/20080509/FEATURES02/805090316/1011/FEATURES02email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.timesargus.com/apps/pbcs.dll/article?AID=/20080509/FEATURES02/805090316/1011/FEATURES02email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.timesargus.com/apps/pbcs.dll/article?AID=/20080509/FEATURES02/805090316/1011/FEATURES02email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.timesargus.com/apps/pbcs.dll/article?AID=/20080509/FEATURES02/805090316/1011/FEATURES02email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.erniestires.net/email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.erniestires.net/email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://thepeerage.com/p4893.htm#i48927email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://thepeerage.com/p4893.htm#i48927email=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.leighrayment.com/commons/Acommons3.htmemail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://www.leighrayment.com/commons/Acommons3.htmemail=gwe...@gmail.com; http://www.webcitation.org/archive?url=http://thepeerage.com/p4893.htm#i48927email=gwe...@gmail.com;
Re: [Haskell-cafe] A small puzzle: inTwain as function of foldr
Possible, yes. Efficient, not really. inTwain = foldr (\x (ls, rs) - if length ls == length rs then (x:ls, rs) else (x:(init ls), (last ls):rs)) ([], []) I have a hunch that everything that reduces a list to a fixed-size data structure can be expressed as a fold, simply by carrying around as much intermediate state as necessary. But I'm too lazy and inexperienced to prove this. Thomas On Thu, Jun 4, 2009 at 16:22, Martijn van Steenbergenmart...@van.steenbergen.nl wrote: Bonjour café, A small puzzle: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Is there a general way to tell if a problem can be expressed as a fold? Thank you, Martijn. ___ 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] Cabal/primes
On Thu, Jun 4, 2009 at 9:52 AM, Ryan Ingram ryani.s...@gmail.com wrote: On this note, shouldn't there be cabal uninstall? You mean ticket 234? http://hackage.haskell.org/trac/hackage/ticket/234 Yes, its been open for a year and has been quietly waiting for developer time... are you the lucky developer who gets to implement it? Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] containers dependency on base
On Jun 4, 2009, at 6:38 PM, Louis Wasserman wrote: I have been unable to compile the stable version of containers-0.2.0.1, having to add the constraint base=4.0.0.0. Can anybody else duplicate this problem? I could also not compile containers-0.2.0.1 and as a workaround added the constraint containers ==0.2.0.0 in the cabal file of my package that uses the containers package. Cheers, Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] A small puzzle: inTwain as function of foldr
How about the following, using difference lists? import Control.Arrow import qualified Data.DList as D start = (Nothing, (D.empty, D.empty)) iter (Nothing, (r1, r2)) x = (Just x, (r1, r2)) iter (Just y, (r1, m)) x = D.list (Nothing, (D.singleton y, D.singleton x)) (\r r2 - let r2' = D.snoc (D.snoc r2 y) x in (Nothing, (D.snoc r1 r, r2'))) m inTwain :: [a] - ([a], [a]) inTwain = (D.toList *** D.toList) . snd . foldl iter start There's no recursion besides the fold. Though using difference lists might be cheating, depending on your definition of cheating :) -Brian Bonjour café, A small puzzle: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Is there a general way to tell if a problem can be expressed as a fold? Thank you, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe _ Windows Live™: Keep your life in sync. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_BR_life_in_synch_062009___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text formatting question
You can use CPS printf, which has the advantage of being completely type-safe: lit :: String - (String - r) - r lit s k = k s str :: (String - r) - (String - r) str k s = k s val :: Show a = (String - r) - a - r val k a = k (show a) (^) :: ((String - r) - s) - ((String - s) - t) - ((String - r) - t) (a ^ b) k = b $ \s - a $ \t - k (s ++ t) cprintf :: ((String - String) - s) - s cprintf k = k id ghci :t cprintf (val ^ lit a ^ val) cprintf (val ^ lit a ^ val) :: (Show a, Show a1) = a1 - a - [Char] ghci putStrLn $ cprintf (val ^ lit a ^ val) 5 () 5a() This can be improved further by using difference lists instead of Strings as the carrier type, to avoid bad behavior in ++, but it's good enough for most uses. It's definitely more wordy than the raw printf, but you can use Template Haskell to build real printf out of it: ghci putStrLn $ $(sprintf %va%v) 5 () 5a() Doing so is kind of fun, so I'll leave it as an exercise :) -- ryan On Thu, Jun 4, 2009 at 12:41 AM, Evan Klitzke e...@eklitzke.org wrote: I'm writing code with hslogger, and I'm finding myself frequently writing things like this: infoM $ printf %s saw %s with %s (show x) (show y) (show z) On #haskell I asked about why you can't have use %s with any instance of (Show a), and augustss, the Text.Printf maintainer, pointed out that it's not possible in Haskell 98 because of overlapping instances. So I'm trying to figure out the best way to work around this in my code. Some of the logging statements can get kind of long, so the ability to elide the calls to `show` would be nice. So what's the best way to do this? I was thinking of making my own variant of printf that only accepted the %s formatter and took (Show a)'s as arguments, but there might be a simpler way? Another thing is the code is already fairly GHC specific at this point, so if there are GHC extensions that might be useful here that I don't know about, I'm interested in hearing about them. Thanks. -- Evan Klitzke e...@eklitzke.org :wq ___ 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] Re: understanding regex libs
Magnus Therning wrote: Once you find out please update the page on the wiki covering the different regular expression libs available for Haskell: http://haskell.org/haskellwiki/Regular_expressions That's a good page, which I've updated a little. It would still be good to clarify the hackage and haddock docs, as they are the front line, and have them link to the above. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] TASE 2009 - Call for Participation
TASE 2009 - CALL FOR PARTICIPATION ** *3rd IEEE International Symposium on * Theoretical Aspects of Software Engineering * (TASE 2009) * 29-31 July 2009, Tianjin, China *http://www.dur.ac.uk/ieee.tase2009 * * Early Registration Deadline : 18 June 2009 * For more information email: ieee.tase2...@durham.ac.uk ***=** TASE 2009 Invited Speakers == Kim G. Larsen, Aalborg University, Denmark Zhong Shao, Yale University, USA Jin-Song Dong, National University of Singapore TASE 2009 Programme Day 1: 29 July 2009 --- Invited Talk: Verification and Performance Analysis of Embedded Systems Kim G. Larsen (Aalborg University) Session 1 : Real-Time and Embedded Systems Improving Responsiveness of Hard Real-Time Embedded Systems Hugh Anderson (Wellington Institute of Technology) and Siau-Cheng KHOO (National University of Singapore) Environmental Simulation of Real-Time Systems with Nested Interrupts Guoqiang Li (Shanghai Jiao Tong University), Shoji Yuen (Nagoya University) and Masakazu Adachi (Toyota Central RD Labs. INC.). Semantics for Communicating Actors with Interdependent Real-Time Deadlines Istv¨¢n Knoll (Aalborg University), Anders P. Ravn (Aalborg University) and Arne Skou (Aalborg University). An Efficient Algorithm for Finding Empty Space for Reconfigurable Systems Zhenhua Duan (Xidian University) and Yan Xiao (Xidian University). Session 2 : Semantics State Visibility and Communication in Unifying Theories of Programming Andrew Butterfield (Trinity College Dublin), Pawel Gancarski (Trinity College Dublin) and Jim Woodcock (University of York). Semantics of Metamodels in UML Lijun Shan (National University of Defence Technology) and Hong Zhu (Oxford Brookes University). Refinement Algebra with Explicit Probabilism Tahiry Rabehaja (UNU/IIST) and Jeffrey Sanders (UNU/IIST). Session 3 : Model Checking Environment Abstraction with State Clustering and Parameter Truncating Hong Pan (Institute of Software, Chinese Academy of Sciences), Yi Lv (Institute of Software, Chinese Academy of Sciences) and Huimin Lin (Institute of Software, Chinese Academy of Sciences). Verification of Population Ring Protocols in PAT Yang Liu (National University of Singapore), Jun Pang (University of Luxembourg), Jun Sun (National University of Singapore) and Jianhua Zhao (Nanjing University). Bounded Model Checking of ACTL Formulae Wei Chen (Institute of Software, Chinese Academy of Sciences) and Wenhui Zhang (Institute of Software, Chinese Academy of Sciences). Day 2, 30 July 2009 --- Invited Talk: Modular Development of Certified System Software Zhong Shao (Yale University) Session 4: Specification and Security Coarse Grained Retrenchment and the Mondex Denial of Service Attacks Richard Banach (Manchester University). Specifying and Enforcing Constraints of Artifact Life Cycles Xiangpeng Zhao (Peking University), Jianwen Su (University of California at Santa Barbara), Hongli Yang (Beijing University of Technology) and Zongyan Qiu (Peking University). Consistency Checking for LSC Specifications Hai-Feng Guo (University of Nebraska at Omaha), Wen Zheng (University of Nebraska at Omaha) and Mahadevan Subramaniam (University of Nebraska at Omaha). Integrating Specification and Programs for System Modeling and Verification Jun Sun (National University of Singapore), Yang Liu (National University of Singapore), Jin Song Dong (National University of Singapore) and Chunqing Chen (National University of Singapore). Session 5 : Software Testing I A Framework and Language Support for Automatic Dynamic Testing of Workflow Management Systems Gwan-Hwan Hwang (National Taiwan Normal University), Che-Sheng Lin (National Taiwan Normal University), Li-Te Tsao (National Taiwan Normal University), Kuei-Huan Chen (National Taiwan Normal University) and Yan-You Li (National Taiwan Normal University). Fault-based Test Case Generation for Component Connectors Bernhard Aichernig (Graz University of Technology), Farhad Arbab (CWI), Lacramioara Astefanoaei (CWI), Frank de Boer (CWI), Meng Sun (CWI) and Jan Rutten (CWI). Test Data Generation for Derived Types in C Program Zheng Wang (East China Normal University), Xiao Yu (East China Normal University), Tao Sun (East China Normal University), Geguang Pu (East China Normal University) and Zuohua Ding (Zhejiang Sci-Tech University). Session 6 : Software Models Program Repair as Sound Optimization of Broken Programs Bernd Fischer (University of Southampton), Ando Saabas (Tallinn University of Technology) and Tarmo Uustalu (Tallinn University of Technology). Modeling Web Applications and Generating Tests: A Combination and Interactions-guided Approach Bo Song (Shanghai University) and Huaikou Miao (Shanghai
Re: [Haskell-cafe] A small puzzle: inTwain as function of foldr
The linked paper appears to show the right style. This appears to satisfy the conditions, however: inTwain as = let (x,y,_) = foldr (\a (r,s,t) - case (t) of {b:(b':bs) - (r,a:s,bs); _ - (a:r,s,t)}) ([],[],as) as in (x,y) In the case of a list of odd length, the first half is given the extra element. On Thu, Jun 4, 2009 at 8:22 AM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Bonjour café, A small puzzle: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Is there a general way to tell if a problem can be expressed as a fold? Thank you, Martijn. ___ 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] Nested Lists
You can also try this: bunch n f = takeWhile (not . null) . unfoldr (Just . (f *** id) . splitAt n) (bunch 8 . bunch 4 . bunch 2) id [1..16] Any way, it's not possible to take list [8, 4, 2], because it's length need to be known at compile time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Static link to packages on Hackage?
Thomas ten Cate wrote: http://hackage.haskell.org/packages/archive/HSH/latest/doc/html/HSH.html does take me to a page that says HSH-2.0.0: Library to mix shell scripting with Haskell programs in the blue bar at the top. Maybe some kind of cache? Did you try flushing your browser cache and refreshing? Am I missing something? Weird. I just now hit reload, and it came up to the correct version. I wonder if perhaps it didn't get updated at the same time the docs did? Thomas On Thu, Jun 4, 2009 at 15:20, John Goerzenjgoer...@complete.org wrote: Hi, I'd like to be able to put a static link to the Haddock docs for the current version of various packages on my homepage. Right now, I can't find any such URL; they all look like: http://hackage.haskell.org/packages/archive/HSH/2.0.0/doc/html/HSH.html I'd like if there could be something like: http://hackage.haskell.org/packages/archive/HSH/latest/doc/html/HSH.html Incidentally, you can click on this latest URL but it doesn't go to the correct version. I can't just link to the package page either, because sometimes it won't have docs (such as shortly after I've uploaded a new version). Ideas? ___ 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: Nested Lists
On Thu, Jun 04, 2009 at 05:09:29PM +0100, Paul Keir wrote: Thanks. I don't know Type Families, but take the point that the input can be parameterised with something something other than a list. i.e. (8 :+: 4 :+: 2 :+: ()) presumably has the same type as (4 :+: 2 :+: ()). In fact, no. (4 :+: 2 :+: ()) :: Bunch (Bunch ()) (8 :+: 4 :+: 2 :+: ()) :: Bunch (Bunch (Bunch ())) Maybe you didn't understand something? Perhaps you should try reading the HaskellWiki[1] page on type families. [1] http://www.haskell.org/haskellwiki/GHC/Type_families HTH, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A small puzzle: inTwain as function of foldr
On Jun 4, 2009, at 4:32 PM, Sittampalam, Ganesh wrote: Martijn van Steenbergen wrote: Consider the function inTwain that splits a list of even length evenly into two sublists: inTwain Hello world! (Hello ,world!) Is it possible to implement inTwain such that the recursion is done by one of the standard list folds? Does this help? http://www.brics.dk/RS/02/12/BRICS-RS-02-12.pdf Ganesh And maybe this helps: http://www.springerlink.com/content/h1547h551422462u/ -- Sebastiaan Visser ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Umlauts in command line arguments
Hello, On Sun, May 31, 2009 at 5:24 PM, GüŸnther Schmidt gue.schm...@web.de wrote: When a command line argument contains an umlaut that argument gets garbled. I'm using ghc 6.10.2 on Win XP. Are there any known solutions for this problem? Your question has inspired me to add a System.Environment.UTF8 module to utf8-string 0.3.5 This module behaves like the System.IO.UTF8 wrapper. -- Eric Mertens ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Fast code question
Hi Folks, I had to transform Packed Decimal file into csv format (does anybody here know what this Mainframe format is?). Because of the file size I could not do this on mainframe directly. So I've created simply program using ByteString. Generally I'm happy with my solution: pgm processes arroud 2MB/s on my pc, so my 3GB file was transformed in reasonable 30 min time. My question is: how to do this faster? {code} module Main where import qualified Data.ByteString.Lazy as B main = B.getContents = myPrint . myConcat . B.unpack myConcat = myConcat' 0 myConcat' :: (Integral a) = Integer - [a] - [Integer] myConcat' _ [] = [] myConcat' acc (x:xs) = case x `mod` 16 of 12 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 13 - ((-10)*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 15 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 10 - fail $ show acc 11 - fail $ show acc 14 - fail $ show acc v - myConcat' (100*acc + (numberOf . fromIntegral) x) xs where restOf n = (n - 12) `div` 16 numberOf n = n - 6 * (n `div` 16) myPrint [] = return () myPrint xs = mapM_ myShow (take 14 xs) putStrLn myPrint (drop 14 xs) myShow x = (putStr . show) x putStr ; {code} I knew that csv output had to be 14 fields per line. Best, Bartek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fast code question
I *do* know what Packed Decimal is; at my previous job, I actually had a whole Haskell library for parsing them. The only immediate suggestion that pops to mind is to use Int instead of Integer (Int uses regular 32- or 64-bit integers, Integer uses arbitrary precision integers). If you send me a sample Packed Decimal file, I can test out your code and get a better feel for it that way. Good luck with those mainframes, they can be beasts sometimes. Have you had to parse EBCDIC yet? *That* was fun, manually copying all those character codes from some IBM web page... ;) Michael On Fri, Jun 5, 2009 at 2:31 AM, Bartosz Wójcik bar...@sudety.it wrote: Hi Folks, I had to transform Packed Decimal file into csv format (does anybody here know what this Mainframe format is?). Because of the file size I could not do this on mainframe directly. So I've created simply program using ByteString. Generally I'm happy with my solution: pgm processes arroud 2MB/s on my pc, so my 3GB file was transformed in reasonable 30 min time. My question is: how to do this faster? {code} module Main where import qualified Data.ByteString.Lazy as B main = B.getContents = myPrint . myConcat . B.unpack myConcat = myConcat' 0 myConcat' :: (Integral a) = Integer - [a] - [Integer] myConcat' _ [] = [] myConcat' acc (x:xs) = case x `mod` 16 of 12 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 13 - ((-10)*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 15 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 10 - fail $ show acc 11 - fail $ show acc 14 - fail $ show acc v - myConcat' (100*acc + (numberOf . fromIntegral) x) xs where restOf n = (n - 12) `div` 16 numberOf n = n - 6 * (n `div` 16) myPrint [] = return () myPrint xs = mapM_ myShow (take 14 xs) putStrLn myPrint (drop 14 xs) myShow x = (putStr . show) x putStr ; {code} I knew that csv output had to be 14 fields per line. Best, Bartek ___ 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] Non Empty List?
Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I can't figure out how to get this right. :( Please help. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Non Empty List?
data Container a = Container a [a] ? Or, maybe, you need something like zipper. On 5 Jun 2009, at 01:53, Günther Schmidt wrote: Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I can't figure out how to get this right. :( Please help. Günther ___ 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] Fast code question
Can you use the bytestring csv parser (or convert it into a pretty printer?) bartek: Hi Folks, I had to transform Packed Decimal file into csv format (does anybody here know what this Mainframe format is?). Because of the file size I could not do this on mainframe directly. So I've created simply program using ByteString. Generally I'm happy with my solution: pgm processes arroud 2MB/s on my pc, so my 3GB file was transformed in reasonable 30 min time. My question is: how to do this faster? {code} module Main where import qualified Data.ByteString.Lazy as B main = B.getContents = myPrint . myConcat . B.unpack ^ That looks bad. myConcat = myConcat' 0 myConcat' :: (Integral a) = Integer - [a] - [Integer] myConcat' _ [] = [] myConcat' acc (x:xs) = case x `mod` 16 of 12 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 13 - ((-10)*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 15 - (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs 10 - fail $ show acc 11 - fail $ show acc 14 - fail $ show acc v - myConcat' (100*acc + (numberOf . fromIntegral) x) xs where restOf n = (n - 12) `div` 16 numberOf n = n - 6 * (n `div` 16) myPrint [] = return () myPrint xs = mapM_ myShow (take 14 xs) putStrLn myPrint (drop 14 xs) myShow x = (putStr . show) x putStr ; {code} I knew that csv output had to be 14 fields per line. Best, Bartek ___ 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] Non Empty List?
Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container a) or data Container a = Container a [a] - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Non Empty List?
Are you looking for something like Streams [1]? They're infinite sequences, defined like this: data Stream a = Cons a (Stream a) They can obviously never be empty (unless you see bottom (undefined) as empty). - Tom [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Stream On Thu, Jun 4, 2009 at 11:53 PM, GüŸnther Schmidt gue.schm...@web.de wrote: Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I can't figure out how to get this right. :( Please help. Günther ___ 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] Re: Non Empty List?
Hi Jake, Jake McArthur schrieb: Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container a) nope, I pretty much meant what I wrote above, the solution here would mean deeply nested containers, since it's a recursive data structure. I need a data structure as in my example without the [] being possible to be empty. It's quite possible that in order to achieve this I would need to split this in 2 separate data declarations. The idea behind this is that an a can pocket siblings, but only one level deep and that an a's list of pocketed/swallowed siblings must not be empty, because otherwise it would automatically be an Single a. Sorry, I really don't know how to put this better. Günther or data Container a = Container a [a] - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Non Empty List?
Hi Tom, thanks for replying, no, I'm not looking for streams. I hope I made myself a bit more clear in my response to Jake. Günther Tom Lokhorst schrieb: Are you looking for something like Streams [1]? They're infinite sequences, defined like this: data Stream a = Cons a (Stream a) They can obviously never be empty (unless you see bottom (undefined) as empty). - Tom [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Stream On Thu, Jun 4, 2009 at 11:53 PM, GüŸnther Schmidt gue.schm...@web.de wrote: Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I can't figure out how to get this right. :( Please help. Günther ___ 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: Non Empty List?
Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Dan Günther Schmidt wrote: Hi Jake, Jake McArthur schrieb: Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container a) nope, I pretty much meant what I wrote above, the solution here would mean deeply nested containers, since it's a recursive data structure. I need a data structure as in my example without the [] being possible to be empty. It's quite possible that in order to achieve this I would need to split this in 2 separate data declarations. The idea behind this is that an a can pocket siblings, but only one level deep and that an a's list of pocketed/swallowed siblings must not be empty, because otherwise it would automatically be an Single a. Sorry, I really don't know how to put this better. Günther or data Container a = Container a [a] - Jake ___ 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] Re: Non Empty List?
Dan Weston schrieb: Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Hi Dan, the above solution would still allow to construct, for instance, Many 5 42 [] :: Container Int The reason why I'm trying to find the design for a data structure in which this would not even be possible is to be able to avoid writing additional bookkeeping code into the functions that operate on the structure, ie. the lookups, inserts, delete etc. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Non Empty List?
Hi Günther, Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above I need a data structure as in my example without the [] being possible to be empty. So lets write a variant of list which cannot be empty. A usual list is empty, or a head and a tail: data List a = Empty | HeadAndTail a (List a) Now, our kind of list should be just one element, or a head and a tail: data NonEmptyList a = JustOne a | HeadAndNonEmptyTail a (NonEmptyList a) So we can replace [] by NonEmptyList in your definition to get what you want: data Container a = Single a | Many a (NonEmptyList a) However, since Container and NonEmptyList are isomorphic, we can use one instead of the other: data Container a = Single a | Many a (Container a) Whether this is a good idea depends on the purpose of the types, but I guess it is. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Non Empty List?
I note that you didn't address the suggestion of a zipper. Günther Schmidt wrote: Dan Weston schrieb: Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Hi Dan, the above solution would still allow to construct, for instance, Many 5 42 [] :: Container Int The reason why I'm trying to find the design for a data structure in which this would not even be possible is to be able to avoid writing additional bookkeeping code into the functions that operate on the structure, ie. the lookups, inserts, delete etc. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Tony Morris http://tmorris.net/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Non Empty List?
Hi Tony, that's because I wasn't sure whether or not it would be applicable here. As with monads, continuations, delimited continuations and quite a number of other high level concepts I only understand them in part even though I realize at the same time that understanding them fully would yield enormous benefits. I am aware of the power of these concepts, but have not gained the intuition yet. As for the zipper: In some of the examples I've seen, the zipper is implemented on top of an underlying data structure, but not the data structure itself. In my app I was actually going to pull a zipper over it, once I had the underlying structure right. Günther PS: please also see my reply to Tillman Tony Morris schrieb: I note that you didn't address the suggestion of a zipper. Günther Schmidt wrote: Dan Weston schrieb: Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Hi Dan, the above solution would still allow to construct, for instance, Many 5 42 [] :: Container Int The reason why I'm trying to find the design for a data structure in which this would not even be possible is to be able to avoid writing additional bookkeeping code into the functions that operate on the structure, ie. the lookups, inserts, delete etc. Günther ___ 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] Re: Non Empty List? - Apologies
Hi Jake, apologies, Jake McArthur schrieb: Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container a) you're right, the above solution is indeed exactly what I need. It took me until Tillmans later elaborate reply to realize. Sometimes I'm unable to see things even when they bite me in the face, ouch! Günther or data Container a = Container a [a] - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Non Empty List?
On Fri, 2009-06-05 at 02:08 +0200, Günther Schmidt wrote: As for the zipper: In some of the examples I've seen, the zipper is implemented on top of an underlying data structure, but not the data structure itself. In my app I was actually going to pull a zipper over it, once I had the underlying structure right. I have a package on Hackage that implements a zipper-ish non-empty list structure. PointedList [1] is a datatype composed of a list of items on the left, the current item, and a list of items on the right. Is that close to what you're looking for? [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pointedlist ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Non Empty List?
Hi Tillmann, thank you for the elaborate example. This is exactly what it took for me to realize that you and Jake have indeed given me the solution that I need. I had a very hard time getting my head around it, but to my defense I'm usually working on this stuff in the wee hours. :) Günther Tillmann Rendel schrieb: Hi Günther, Günther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above I need a data structure as in my example without the [] being possible to be empty. So lets write a variant of list which cannot be empty. A usual list is empty, or a head and a tail: data List a = Empty | HeadAndTail a (List a) Now, our kind of list should be just one element, or a head and a tail: data NonEmptyList a = JustOne a | HeadAndNonEmptyTail a (NonEmptyList a) So we can replace [] by NonEmptyList in your definition to get what you want: data Container a = Single a | Many a (NonEmptyList a) However, since Container and NonEmptyList are isomorphic, we can use one instead of the other: data Container a = Single a | Many a (Container a) Whether this is a good idea depends on the purpose of the types, but I guess it is. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Non Empty List?
Hi Jeff, it might actually be, I'll check it out after a good nights sleep. Apparently working on this in the wee hours only leads to self embarrassing requests for help. Actually when it comes to the underlying data structure, Jake and Tillmann have already found it for me, even though I failed to realize that in Jakes post and only got it after Tillmanns post. It's been a long night :) Günther Jeff Wheeler schrieb: On Fri, 2009-06-05 at 02:08 +0200, Günther Schmidt wrote: As for the zipper: In some of the examples I've seen, the zipper is implemented on top of an underlying data structure, but not the data structure itself. In my app I was actually going to pull a zipper over it, once I had the underlying structure right. I have a package on Hackage that implements a zipper-ish non-empty list structure. PointedList [1] is a datatype composed of a list of items on the left, the current item, and a list of items on the right. Is that close to what you're looking for? [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pointedlist ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Non Empty List?
Günther, Miguel had the easiest suggestion to get right: Your goal is to avoid the redundant encoding of a list of one element, so why do you need to get rid of the Many a [] case when you can get rid of your Single a case! module NE where import Prelude hiding (foldr, foldl, foldl1, head, tail) import Data.Foldable (Foldable, foldr, toList, foldl, foldl1) import Data.Traversable (Traversable, traverse) import Control.Applicative data NE a = NE a [a] deriving (Eq,Ord,Show,Read) Now we can fmap over non-empty lists instance Functor NE where fmap f (NE a as) = NE (f a) (map f as) It is clear how to append to a non-empty list. cons :: a - NE a - NE a a `cons` NE b bs = NE a (b:bs) head is total. head :: NE a - a head (NE a _) = a tail can return an empty list, so lets model that tail :: NE a - [a] tail (NE _ as) = as We may not be able to construct a non-empty list from a list, if its empty so model that. fromList :: [a] - Maybe (NE a) fromList (x:xs) = Just (NE x xs) fromList [] = Nothing We can make our non-empty lists an instance of Foldable so you can use Data.Foldable's versions of foldl, foldr, etc. and nicely foldl1 has a very pretty total definition, so lets use it. instance Foldable NE where foldr f z (NE a as) = a `f` foldr f z as foldl f z (NE a as) = foldl f (z `f` a) as foldl1 f (NE a as) = foldl f a as We can traverse non-empty lists too. instance Traversable NE where traverse f (NE a as) = NE $ f a * traverse f as And they clearly offer a monadic structure: instance Monad NE where return a = NE a [] NE a as = f = NE b (bs ++ concatMap (toList . f) as) where NE b bs = f a and you can proceed to add suitable instance declarations for it to be a Comonad if you are me, etc. Now a singleton list has one representation NE a [] A list with two elements can only be represented by NE a [b] And so on for NE a [b,c], NE 1 [2..], etc. You could also make the data Container a = Single a | Many a (Container a) definition work that Jake McArthur provided. For the category theory inspired reader Jake's definition is equivalent to the Cofree comonad of the Maybe functor, which can encode a non-empty list. I leave that one as an exercise for the reader, but observe Single 1 Many 1 (Single 2) Many 1 (Many 2 (Single 3)) And the return for this particular monad is easy: instance Monad Container where return = Single In general Jake's non-empty list is a little nicer because it avoids a useless [] constructor at the end of the list. -Edward Kmett On Thu, Jun 4, 2009 at 5:53 PM, GüŸnther Schmidt gue.schm...@web.de wrote: Hi, I need to design a container data structure that by design cannot be empty and can hold n elements. Something like a non-empty list. I started with: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I can't figure out how to get this right. :( Please help. Günther ___ 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] GHCI Curl under Windows
On Thu, 2009-06-04 at 12:57 +1000, John Lask wrote: The issue you are experiencing is the result of ghci not using import libraries to resolve external symbols. Just a bit of explanation for reference, which will also help you understand the solution to your problem. [..] The long and the short of it is --- much work still needs to be done to ensure that building and maintaining packages on windows platforms via cabal and ghc is painless - so far every package I have used that relied on external libraries has required some tweaking (and not just setting library paths). Thanks for the detailed writeup. We would of course like to have better support on Windows in cabal and ghc for packages that bind C libs. Perhaps you can file some tickets with concrete suggestions? http://hackage.haskell.org/trac/hackage/ http://hackage.haskell.org/trac/ghc/ Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functors and the Visitor Pattern
Johan Tibell wrote: wren ng thornton wrote: [2] For the recursive Visitor pattern I use most often, that is. For the non-recursive version it's usually fmap. This is the part where the pattern gets a bit shaky because there are actually many different patterns all called Visitor. The main points of interest are whether it's recursive or not, and whether it applies the visitor to itself, to its children, or both. non-recursive + itself == ($) non-recursive + children == fmap (under open-recursion interpretation of the type, aka all nodes are elements) recursive + children == fmap (under closed-recursion interpretation, aka only fringe nodes are elements) recursive + both == cata (usually, though it depends how you aggregate) recursive + itself == This is actually a variant of the Iterator pattern Could you be so kind to give an example for each? In OOP you mean? /* nonrecursive + self == application */ class A { T app(Visitor v) { return v.visit(this); } } class B { T app(Visitor v) { return v.visit(this); } } ... // An allomorphic function :: (A | B | ...) - T class Visitor { T visit(A a) { ... } T visit(B b) { ... } ... } This particular version often isn't too helpful because it's just reflecting the method call, we could've just called visit directly instead of calling app. But there are times where it is useful, particularly when you want to have some visitors which are recursive and some which are not. In which case it doesn't matter which method you start with, but you do need both in order to reflect back on recursion. /* nonrecursive + children == fmap (with real parametricity) */ class FA { ChildrenA as; F(ChildrenA as) { this.as = as; } FB fmap(VisitorA,B v) { ChildrenB bs = new ChildrenB(); for (A a : this.as) bs.add( v.visit(a) ); return new FB(bs); } } ... interface VisitorA,B { B visit(A a); } This is a rather Haskellish take on this version. In practice people often don't bother supporting parametricity (needed for making F a real functor). That is, usually they'll do destructive updates to F, only have endofunction visitors (so there's no change of types), or use side-effect only visitors (see below). /* recursive + children == fmap (side-effect only) */ abstract class Tree { abstract void rmap(Visitor v); } class Branch extends Tree { ChildrenTree subtrees; void rmap(Visitor v) { for (Tree t : this.subtrees) v.visit(t); } } class Leaf extends Tree { void rmap(Visitor v) { // Just in case we're the root node. v.visit(this); // Or we could do nothing instead, // depending on desired semantics } } class Visitor { void visit(Branch t) { t.rmap(this); } // reflect to recurse void visit(Leaf t) { ... } // don't reflect or you'll hit _|_ } This highlights an additional axis of variation in the many different visitor patterns, whether the result is returned directly (as in the previous example), whether it is accumulated in the Visitor itself (requiring explicit lookup later), or whether it's done via side-effects on global state. The accumulator and side-effect versions are a bit more general since their return type isn't restricted by the classes being visited. /* recursive + self/both == a kind of Iterator/catamorphism */ abstract class Tree { abstract void observe(Visitor v); } class Branch extends Tree { ChildrenTree subtrees; void observe(Visitor v) { v.visit(this); for (Tree t : this.subtrees) t.observe(v); } } class Leaf extends Tree { void observe(Visitor v) { v.visit(this); } } class Visitor { void visit(Branch t) { ... } void visit(Leaf t) { ... } } This is different from the recursive+children version because this version keeps all of the recursion code on the side of the visited classes, and it also meaningfully visits interior nodes. In the recursive+children version the visitor ignored branches (though it doesn't need to) and reflected back to initiate recursion, whereas this version will recurse no matter what the visitor does (barring exceptions, etc). This version is a push iterator which forces you to visit all nodes, rather than the more usual pull iterator where you need to call next() to get the next node. We can convert between the two varieties by using co-routines or threads or other control-flow tricks. If we reverse the order of the recursive observe and the visit(this) then we get something like a catamorphism. Whether it's actually a catamorphism depends on what the visitor does, or rather what knowledge about the shape of Branch and Leaf it makes use of. Real catamorphisms are fairly rare in OOP, though you often find things like using a visitor to add decoration to a tree (which is much like passing the initial algebra to cata) or maintaining some aggregation in the visitor. -- Live