Re: [Haskell-cafe] Storing failing testcases for QuickCheck
On 24 April 2011 01:49, wren ng thornton w...@freegeek.org wrote: I would *love* there to be a tool which (a) automatically saves failing QuickCheck values to disk, and (b) automates using HUnit to load those in and test them. I'm not so sure that QuickCheck should be doing the second step of that since that'd really mess with the QuickCheck infrastructure; once you have the code for reading from disk, it'd be trivial to just use HUnit. Maybe this is a job for test-framework? I think the API's of QuickCheck and HUnit expose enough information for this to be possible. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] http://trac.haskell.org/ not redering correctly
On 21/04/2011 02:36 AM, Conrad Parker wrote: I thought the purpose of filing a bug report was to get things fixed? The purpose of filing bug reports is to ensure that problems are not forgotten. It allows the community (people like you) to have a useful understanding of the problems that exist when choosing what tasks to put time and effort into fixing. *sigh* I guess that means the next step is to figure out if it's broken for the Linux builds as well, or just for Windows. (Can't test for Mac OS since I don't have access to the necessary hardware or software...) The first step would be to make a patch that works for you, and to attach it to the ticket. Wouldn't that require me to somehow get hold of whatever repo contains the script for generating the Windows installer? Then again if it's simply a matter of generating additional HTML text (as opposed to styling/rendering issues) then it should be straightforward to verify that the new content is added in the generated files without worrying about other platforms. I imagine the issue is something utterly trivial list a line of text missing from a file - which is why I'm so surprised that the problem has been reported multiple times and yet not fixed... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A small Darcs anomoly
I've discovered something interesting. Darcs stores history as a partially-ordered set of changes. This is a beautiful and elegant idea. In theory, this lets me apply any combination of changes, possibly generating file versions which have never actually existed before. (E.g., the new type checker from GHC 7.0 embedded in the GHC 6.6 codebase - not that I imagine it would compile, but in principle I can do it.) So I was a little surprised to discover that... Darcs doesn't actually support doing this. Darcs is only really interested in the result of applying *all* changes in a repo. If you want to apply some subset of changes, you need to make a seperate repo containing only the changes you want applied. It seems daft to me that you would design a sophisticated system for splitting history into independent chunks, and then not let me manipulate them independently. (If you think about it, the difference between, say, GHC 7.0 and GHC 6.6 is which set of changes are applied. Yet because Darcs doesn't support looking at it like this, you must have a completely seperate repo for each one...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A small Darcs anomoly
On Sun, 24 Apr 2011, Andrew Coppin wrote: (If you think about it, the difference between, say, GHC 7.0 and GHC 6.6 is which set of changes are applied. Yet because Darcs doesn't support looking at it like this, you must have a completely seperate repo for each one...) But darcs shares the patch files between repositories on the same file system using hard links. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] fishing for ST mutable Vector examples
I also recently implemented a Fisher-Yates shuffle in mutable vectors. I probably should have used Gen (from mwc-random) in ST, but I already had a GenIO hanging around for other reasons. -- import Control.Monad.ST (unsafeIOToST) import Data.Vector (Vector) import qualified Data.Vector as V import qualified Data.Vector.Mutable as MV import System.Random.MWC shuffle :: GenIO - Vector k - Vector k shuffle rng v = if V.null v then v else V.modify go v where !n = V.length v go mv = f (n-1) where -- note: inclusive pickOne b = unsafeIOToST $ uniformR (0,b) rng swap = MV.unsafeSwap mv f 0 = return () f !k = do idx - pickOne k swap k idx f (k-1) -- G. On Sun, Apr 24, 2011 at 5:21 AM, Globules globu...@gmail.com wrote: brad clawsie clawsie at fastmail.fm writes: hi all i was wondering if anyone could post some minimal examples on using mutable Vectors in the ST monad. i've been digging around in the usual places but haven't been able to find anything to get me over the hump thanks in advance brad I was just looking into the same thing. This link at Rosetta Code has a list shuffling function, which is my first experiment with mutable Vectors: http://rosettacode.org/wiki/Balanced_brackets#Haskell The list is converted to a mutable Vector, the mapM_ performs a series of element swaps, then the result is frozen and converted back to a list. - Globules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] fishing for ST mutable Vector examples
There is vector-algorithms [1] which has lots of mutable code. Note that it uses 'PrimMonad m = m ...', which means that the code may work on ST or IO. Cheers, [1] http://hackage.haskell.org/package/vector-algorithms -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to use cabal's data-files feature and run in-place?
balodja schrieb: For such purposes I use separate directory for Paths_pkg.hs and don't notice it in pkg.cabal. For example, imagine src directory with source files (appropriately mentioned in pkg.cabal with hs-source-dirs: src) and additional plugs directory with Paths_pkg.hs (that is not mentioned in pkg.cabal). In such case cabal builds project with autogenerated Paths_pkg.hs and ghci also can be launched in src directory with ghci Main.hs -i../plugs. or you run from your package directory with pkg$ ghci -i:src:plugs Main This only works, if the module Main has filename Main.hs Otherwise start with pkg$ ghci -i:src:plugs src/Main.hs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] More ideas for controlled mutation
Laziness can be viewed as a form of controlled mutation, where we overwrite a thunk with its actual value, thus only running the code once and reaping great time benefits. I've been toying around with some ideas where we do alternative forms of controlled mutation. One such idea has to do with memoization. One way we memoize functions is by building up a data-structure that covers the entirety of input domain of the function, with the values in each slot being thunks for the corresponding function call. Now, this is all very nice and well, but for some types of inputs (like machine integers) we end up making a very big structure for a function for which, in practice, we'll only store and retrieve a few values of the domain. Hash tables take advantage of this fact by simply chaining together values in a linked list if they land in the same bucket. Could we have similarly bucketized memoization? What we want here is for a *thunk to possibly evaluate to different values, but calls to the API be observationally equivalent.* That is, if the only way I can inspect a dictionary list is do a lookup, I don't care if my representation is [(1,4),(2,2)] or [(2,2),(1,4)]. An obvious way to do this is to use unsafePerformIO to read out an IORef stating the value currently being looked up, and have the thunk evaluate to the pair of that key and the result. There are some synchronization concerns, of course: ideally we would only take out a lock on the thunk once we realize that the value doesn't already exist in the memotable, but I don't think there's a way in GHC Haskell to observe if a value is a thunk or not (maybe such a mechanism would be useful?) This seems related to lazy IO, where thunks are co-opted into performing input-output effects. After all, mutation is just a controlled form of IO. Is lazy IO evil or not? One consensus is that for operations that involve limited resources (file descriptors, etc.) lazy IO is too opaque for its own good. It seems we also haven't cracked it's performance problems either (for the relatively un-objectionable generation of an infinite stream of random numbers, Don Stewart notes: There are real overheads here. Consider eagerly filling chunks and extracting elements piecewise.). But code that looks pure and can be reasoned about like pure code, but has the efficiency benefits of mutation is a very attractive thing indeed. I think it's worth some thought, though the programming world at large has a hard enough time reasoning about laziness even when everything is completely pure! Cheers, Edward P.S. An obvious question is whether or not we could use this technique to implement splay heaps or hash tables with pure interfaces. My opinion is no, because these structures demand you be able to *observe* the mutation. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More ideas for controlled mutation
On Sun, 24 Apr 2011, Edward Z. Yang wrote: Laziness can be viewed as a form of controlled mutation, where we overwrite a thunk with its actual value, thus only running the code once and reaping great time benefits. Reminds me on a discussion about 'blue printing' in the past: http://www.haskell.org/haskellwiki/Blueprint ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] generics and sql
Dear Group, Greetings. I have a feeling that what I am trying to do is easy, I just don't know how to say it in Haskell. Let's start with: {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-} import Database.HDBC import Data.Typeable (Typeable) import Data.Data data C = C { str :: String, dbl:: Double } deriving (Eq, Ord, Typeable, Data) a :: C a = C twelve 12.0 Now I load this up in ghci and I can do the following: toSql . str $ a -- result: SqlString twelve toSql . dbl $ a -- result: SqlDouble 12.0 but what I would really like to do is something like: gmapQ toSql $ a which results in: interactive:1:7: Could not deduce (Convertible d SqlValue) arising from a use of `toSql' from the context (Data d) bound by a type expected by the context: Data d = d - SqlValue at interactive:1:1-11 Possible fix: add (Convertible d SqlValue) to the context of a type expected by the context: Data d = d - SqlValue or add an instance declaration for (Convertible d SqlValue) In the first argument of `gmapQ', namely `toSql' In the expression: gmapQ toSql In other words, I'm looking for a function with a signature: (Whatever Instances I neeed here) = a - [SqlValue] I have tried various incantations of type signatures, but thus far I can't get it right. Can someone point me in the right direction? Thanks. Henry Laxen -- Nadine Henry LaxenBelle, Venus, Aphrodite 10580 N. McCarran Blvd. Adonis, Miss Parker Jarod Suite 115-396 Via Alta # 6 Reno, NevadaChapala, Jalisco, Mexico 89503-1896 CP 45900 The rest is silence. (Hamlet) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] generics and sql
Hmm, this is a bit peculiar. The problem is you don't get control over how gmapQ invokes the function toSql: it will only ever be done with the type signature Data d = d - u. There is good reason for this too: imagined you tried to run gmapQ toSql on a data-type that contained a member that was not convertible to a SqlValue: then it ought to fail with a type error! You may be able to work around this with more generics madness: use Typeable to check if the types of all the fields are kosher, and then do an appropriate casts before invoking toSql. But you won't get particularly good static guarantees doing it this way. So... what are you really trying to do? :-) Edward Excerpts from nadine.and.henry's message of Sun Apr 24 10:21:03 -0400 2011: Dear Group, Greetings. I have a feeling that what I am trying to do is easy, I just don't know how to say it in Haskell. Let's start with: {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-} import Database.HDBC import Data.Typeable (Typeable) import Data.Data data C = C { str :: String, dbl:: Double } deriving (Eq, Ord, Typeable, Data) a :: C a = C twelve 12.0 Now I load this up in ghci and I can do the following: toSql . str $ a -- result: SqlString twelve toSql . dbl $ a -- result: SqlDouble 12.0 but what I would really like to do is something like: gmapQ toSql $ a which results in: interactive:1:7: Could not deduce (Convertible d SqlValue) arising from a use of `toSql' from the context (Data d) bound by a type expected by the context: Data d = d - SqlValue at interactive:1:1-11 Possible fix: add (Convertible d SqlValue) to the context of a type expected by the context: Data d = d - SqlValue or add an instance declaration for (Convertible d SqlValue) In the first argument of `gmapQ', namely `toSql' In the expression: gmapQ toSql In other words, I'm looking for a function with a signature: (Whatever Instances I neeed here) = a - [SqlValue] I have tried various incantations of type signatures, but thus far I can't get it right. Can someone point me in the right direction? Thanks. Henry Laxen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] generics and sql
Thanks for the quick reply Edward. What I'm trying to do is be lazy. I have a longish data structure, say: data Loan = Loan { loan_address :: String, loan_initialAmount :: Double, loan_interestRate :: Double, loan_term:: Int, loan_originated :: Day, loan_minimumPayment :: Double, loan_usualPayment :: Double, loan_familiarName :: String, loan_password :: String, loan_lastVisit :: Day, loan_nextToLastVisit :: Day, loan_emailAddress :: String, } deriving (Read, Show, Eq, Ord, Typeable, Data) where each component is an instance of (Convertible a SqlValue), and I would like to be able to say something like: let vals = magicalGmapIncantation toSql loan liftIO $ withtransaction db $ \d - run query vals of course I could do: let vals = [toSql (loan_address loan), toSql (loan_initialAmount loan) ...] but that feels so dirty, when all those fields are just waiting for me inside that loan data type. Best wishes, H EZY == Edward Z Yang ezy...@mit.edu writes: EZY Hmm, this is a bit peculiar. The problem is you don't get control EZY over how gmapQ invokes the function toSql: it will only ever be done EZY with the type signature Data d = d - u. There is good reason for EZY this too: imagined you tried to run gmapQ toSql on a data-type that EZY contained a member that was not convertible to a SqlValue: then it EZY ought to fail with a type error! EZY You may be able to work around this with more generics madness: use EZY Typeable to check if the types of all the fields are kosher, and then EZY do an appropriate casts before invoking toSql. But you won't get EZY particularly good static guarantees doing it this way. EZY So... what are you really trying to do? :-) Greetings. I have a feeling that what I am trying to do is easy, I just don't know how to say it in Haskell. Let's start with: {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-} import Database.HDBC import Data.Typeable (Typeable) import Data.Data data C = C { str :: String, dbl:: Double } deriving (Eq, Ord, Typeable, Data) a :: C a = C twelve 12.0 Now I load this up in ghci and I can do the following: toSql . str $ a -- result: SqlString twelve toSql . dbl $ a -- result: SqlDouble 12.0 but what I would really like to do is something like: gmapQ toSql $ a which results in: interactive:1:7: Could not deduce (Convertible d SqlValue) arising from a use of `toSql' from the context (Data d) bound by a type expected by the context: Data d = d - SqlValue at interactive:1:1-11 Possible fix: add (Convertible d SqlValue) to the context of a type expected by the context: Data d = d - SqlValue or add an instance declaration for (Convertible d SqlValue) In the first argument of `gmapQ', namely `toSql' In the expression: gmapQ toSql In other words, I'm looking for a function with a signature: (Whatever Instances I neeed here) = a - [SqlValue] I have tried various incantations of type signatures, but thus far I can't get it right. Can someone point me in the right direction? Thanks. -- Nadine Henry LaxenBelle, Venus, Aphrodite 10580 N. McCarran Blvd. Adonis, Miss Parker Jarod Suite 115-396 Via Alta # 6 Reno, NevadaChapala, Jalisco, Mexico 89503-1896 CP 45900 The rest is silence. (Hamlet) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] generics and sql
Where did 'query' come from? Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] generics and sql
EZY == Edward Z Yang ezy...@mit.edu writes: EZY Where did 'query' come from? Edward I left that out because it was just a prebuilt db query. It came from something like: dataNames :: Data a = a - [String] dataNames = constrFields . toConstr loanNames = datanames (loan :: Loan) {- yielding: [loan_address,loan_initialAmount,loan_interestRate,loan_term,loan_originated,loan_minimumPayment,loan_usualPayment,loan_familiarName,loan_password,loan_lastVisit,loan_nextToLastVisit,loan_emailAddress] -} let query = INSERT INTO loans ( ++ loanNames ++ ) values ( ++ (intercalate , (replicate (length loanNames) ?)) ++ ) Best wishes, H ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A small Darcs anomoly
On Sun, Apr 24, 2011 at 2:05 AM, Andrew Coppin andrewcop...@btinternet.comwrote: I've discovered something interesting. Darcs stores history as a partially-ordered set of changes. This is a beautiful and elegant idea. In theory, this lets me apply any combination of changes, possibly generating file versions which have never actually existed before. (E.g., the new type checker from GHC 7.0 embedded in the GHC 6.6 codebase - not that I imagine it would compile, but in principle I can do it.) So I was a little surprised to discover that... Darcs doesn't actually support doing this. Darcs is only really interested in the result of applying *all* changes in a repo. If you want to apply some subset of changes, you need to make a seperate repo containing only the changes you want applied. It seems daft to me that you would design a sophisticated system for splitting history into independent chunks, and then not let me manipulate them independently. This is because of a deliberate choice that was made by David Roundy. In darcs, you never have multiple branches within a single darcs repository directory tree. To get the effect you want, you simply create two repositories. One having only the patches for ghc 6.6 and one having the patches of ghc 7.0 and then you pull just the patches you want from 7.0 into 6.6. There are options to 'darcs get' that help you select the right set of patches to help you create the two repositories. If you're interested in the details of how to do it, I would suggest asking on the darcs-users mailing list. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to keep cabal and ghci package versions in sync?
Hi all, I have a project with a .cabal file listing package dependencies using the usual version constraints ==X.Y.* Z.W or =K.J syntax. Standard route cabal configure; cabal build works correctly as it is able to select working set of package versions. I have also a .ghci file. When I run GHCi it uses all latest installed packages in the system. This prevents the project from loading. I tried to use 'cabal-dev ghci', but this still selects latest global packages. So, how to I load up ghci with the same package versions as selected by cabal? Thanks! -- Gracjan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to keep cabal and ghci package versions in sync?
On Sun, Apr 24, 2011 at 11:13 AM, Gracjan Polak gracjanpo...@gmail.com wrote: I have a project with a .cabal file listing package dependencies using the usual version constraints ==X.Y.* Z.W or =K.J syntax. Standard route cabal configure; cabal build works correctly as it is able to select working set of package versions. I have also a .ghci file. When I run GHCi it uses all latest installed packages in the system. This prevents the project from loading. I tried to use 'cabal-dev ghci', but this still selects latest global packages. This should only arise for the base ghc packages, which are tied closely enough to ghc that you should probably switch ghc versions if you want to work with different versions of those core packages. If you're installing additional packages globally, my only advice is: Beware, there be dragons! I strongly recommend that you ghc-pkg unregister all the non-essential packages from your global package db because: (1) cabal-dev will not bring you any benefit. (2) you will eventually run into ugly unsatisfiable dependency issues between your local and global package databases. (3) you may inadvertently cause a base package to be upgraded, which is somewhat easier to fix if it's installed to a local package db. cabal-dev ghci should be able to do what you want, but it has no control over the global db. I'd be happy to send you a list of the packages that ghc comes with, if you choose to unregister packages from the global db (assuming you're using one of the OS/arch/ghc combinations I have available :) --Rogan So, how to I load up ghci with the same package versions as selected by cabal? Thanks! -- Gracjan ___ 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] How to keep cabal and ghci package versions in sync?
On 24 April 2011 22:27, Rogan Creswick cresw...@gmail.com wrote: On Sun, Apr 24, 2011 at 11:13 AM, Gracjan Polak gracjanpo...@gmail.com wrote: I have a project with a .cabal file listing package dependencies using the usual version constraints ==X.Y.* Z.W or =K.J syntax. Standard route cabal configure; cabal build works correctly as it is able to select working set of package versions. I have also a .ghci file. When I run GHCi it uses all latest installed packages in the system. This prevents the project from loading. I tried to use 'cabal-dev ghci', but this still selects latest global packages. This should only arise for the base ghc packages, which are tied closely enough to ghc that you should probably switch ghc versions if you want to work with different versions of those core packages. If you're installing additional packages globally, my only advice is: Beware, there be dragons! I strongly recommend that you ghc-pkg unregister all the non-essential packages from your global package db because: I'll second this; I had the same problem and just uninstalled the global package and went ahead and uninstalled them all, no problems since. All my projects are under cabal-dev so it's not a problem. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More ideas for controlled mutation
Edward Z. Yang ezy...@mit.edu writes: I've been toying around with some ideas where we do alternative forms of controlled mutation. One such idea has to do with memoization. [..] Hash tables take advantage of this fact by simply chaining together values in a linked list if they land in the same bucket. [...] An obvious way to do this is to use unsafePerformIO to read out an IORef stating the value currently being looked up, and have the thunk evaluate to the pair of that key and the result. There are some synchronization concerns, of course: Seen this? http://augustss.blogspot.com/2011/04/ugly-memoization-heres-problem-that-i.html -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
Re: [Haskell-cafe] More ideas for controlled mutation
Yep. It harkens to my days of forcing impure, non-thread-safe C libraries into nice, pure, Haskell FFI bindings. I suppose what I'd like to do here is work in the unsafe IO much more closely with GHC's existing facilities, so that we spend as much time as possible /not/ in unsafePerformIO. A kind of hybrid approach, if you will. P.S. Don Stewart points out that Edward Kmett has can access GHC's pointer tags http://hackage.haskell.org/package/tag-bits, thus allowing us to approximate evaluated/not evaluated. Maybe I'll hack up a prototype next time round. Excerpts from Ketil Malde's message of Sun Apr 24 17:41:23 -0400 2011: Edward Z. Yang ezy...@mit.edu writes: I've been toying around with some ideas where we do alternative forms of controlled mutation. One such idea has to do with memoization. [..] Hash tables take advantage of this fact by simply chaining together values in a linked list if they land in the same bucket. [...] An obvious way to do this is to use unsafePerformIO to read out an IORef stating the value currently being looked up, and have the thunk evaluate to the pair of that key and the result. There are some synchronization concerns, of course: Seen this? http://augustss.blogspot.com/2011/04/ugly-memoization-heres-problem-that-i.html -k ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] generics and sql
Not that it solves your problem, but you may want to take a look at persistent [1]. Cheers, [1] http://hackage.haskell.org/package/persistent -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A parallelization problem
Hello all, I have some loopy code I'd like to make parallel, but I'm not sure the best way to go about it. Everywhere else in this program I'm using STM, but that seems pretty heavy-handed for this task, and it looks like the perfect place for `par` and friends. So the 10,000ft view of the code is something like: foldl' step (0,state0) xs step (n,stateN) x = (n+1, k stateN) where k = case lookup n stateN of Nothing- error oh noes Just substateN - insert (n+1) $ foldl' maybeInsert empty (views substateN x) maybeInsert state (k,v) | p (k,v) = state | otherwise = insert k v state That is, for each x that comes in we add a bunch of things to a map datastructure. The thing that makes the inner loop parallelizable is that we happen to know that none of the new keys will (a) conflict with old keys (as indicated by the fact that we're nesting maps), (b) conflict with the other new keys, nor (c) depend on the other new key/value pairs. Thus, we know that we can reassociate the order of insertions without changing the semantics. So the question is, how do I do it? One issue not apparent in this high-level look at the code is that I'm actually using ST for doing the inner loop efficiently, which is why I'm not just using fromList. So far I'm using an IntMap for storing the state. The STM approach would be to store the IntMap in a TMVar and fire off threads to compute and insert each one of the views. But even as lightweight as Haskell's threads are, I worry that the overhead would swamp the benefits. (Of course, it may be viable to push the ST down far enough to use (fromList . catMaybes). Then we could just construct the list and call par on all the elements. That wouldn't do much to parallelize the insertions themselves, but that shouldn't matter too much I hope. Perhaps I've just answered my own question; any other ideas?) -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Posix IO Unicode lookup exception
Hi, I wanted to see if anyone had an idea about why the following program results in an exception. The issue seems to be related to stdin to a POSIX file descriptors for a subprocess, and GHC's Unicode encoding lookup. I've tried to make the program as simple as possible to make the issue obvious. Consider: module Pipe where import System.Process import System.IO import System.Posix.IO main = sequence_ $ replicate 10 f f = do (Just hin, _, _, prc) - createProcess (shell ./pipe_c.out) { std_in = CreatePipe , std_out = UseHandle stdout , std_err = UseHandle stderr} pin - handleToFd hin _ - fdWrite pin (h\n) closeFd pin waitForProcess prc and a trivial C program to read in the data (but doing nothing with it): --- #include stdio.h #define SIZE 10 int main(void) { char in[SIZE]; if(fgets(in, SIZE , stdin) != NULL); return 0; } and executing gcc -Wall -o pipe_c.out pipe_c.c ghci Pipe.hs main ... *** Exception: malloc: resource exhausted (out of memory) iconvOpen (UTF-8,UTF-8): resource exhausted (Cannot allocate memory) My best guess is that the GHC is calling iconv_open() http://www.kernel.org/doc/man-pages/online/pages/man3/iconv_open.3.html, but not making a subsequent call to iconv_close() http://www.kernel.org/doc/man-pages/online/pages/man3/iconv_close.3.html. (Actually, my best guess is I'm making a silly mistake, but I'm having trouble seeing it. :) ) I am running 2.6.35-28-generic (Ubuntu) and GHC 7.0.2, but I've observed the same issues with GHC 6.12.3. Lee ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe