[Haskell-cafe] Hackage down

2010-01-06 Thread Daniel Fischer
Just a heads up, hackage is down, doesn't respond to ping even, cabal update 
says 
cabal: socket: 3: resource vanished
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage down

2010-01-06 Thread Roel van Dijk
If you are desperate for some hackage you can at least browse packages
on my reverse dependencies thingie:

http://bifunctor.homelinux.net/~roel/hackage/packages/hackage.html

The last update was the 4th of january. But it doesn't have the actual
packages, so it is probably not so useful in this case.

On Wed, Jan 6, 2010 at 11:50 AM, Daniel Fischer
daniel.is.fisc...@web.de wrote:
 Just a heads up, hackage is down, doesn't respond to ping even, cabal update
 says

 cabal: socket: 3: resource vanished
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Reminder: ZuriHac - Haskell hackathon in Zurich, March 19-21

2010-01-06 Thread Johan Tibell
Hi all!

This is to remind you that we're organizing ZuriHac, a Haskell
hackathon/get-together, to be held March 19-21 at the Google Office in
Zurich, Switzerland. Lots of people have already registered but we
still have space for more!

If you plan on coming, please register [1] so we can make sure there's
seating for everyone.  Registration, travel, lodging and many other
details will soon be available on the ZuriHac wiki [2]. If you have
any questions don't hesitate to drop Christophe or me an email (or
email addresses can be found on the wiki.)

WHEN
Friday March 19 2:30pm to 6:30pm
Saturday March 20 10am to 6pm
Sunday March 21 10am to 6pm

WHERE
We will be in the TechTalk area of the Google Office at
Brandschenkestrasse 110. Please see the wiki [3] for directions.

ORGANIZERS
Johan Tibell
Christophe Poucet

Hope to see you in Zurich!

- The ZuriHac team

[1] http://haskell.org/haskellwiki/ZuriHac/Register
[2] http://haskell.org/haskellwiki/ZuriHac
[3] http://haskell.org/haskellwiki/ZuriHac#Getting_to_the_Google_Office
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage down

2010-01-06 Thread Roel van Dijk
I have downloaded the torrent with the hackage archive from 19 oktober
2009 and put it on my server. This means you can now download all the
packages contained in that archive (only the latest versions at that
date).

Happy hacking,
Roel

On Wed, Jan 6, 2010 at 11:57 AM, Roel van Dijk vandijk.r...@gmail.com wrote:
 If you are desperate for some hackage you can at least browse packages
 on my reverse dependencies thingie:

 http://bifunctor.homelinux.net/~roel/hackage/packages/hackage.html

 The last update was the 4th of january. But it doesn't have the actual
 packages, so it is probably not so useful in this case.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] darcs 2.4 beta 1 release

2010-01-06 Thread Ivan Lazar Miljenovic
I really feel that bug 1720 [1] is a show-stopping bug for darcs,
especially since it means that building Haddock for darcs with
GHC-6.12.* isn't possible.

[1] http://bugs.darcs.net/issue1720

I tried to make a fix, but didn't know enough of how darcs is documented
to be able to do anything.


Reinier Lamers tux_roc...@reinier.de writes:

 Hi all,

 The darcs team would like to announce the immediate availability of darcs 2.4
 beta 1. darcs 2.4 will contain many improvements and bugfixes compared to
 darcs 2.3.1. Highlights are the fast index-based diffing which is now used by
 all darcs commands, and the interactive hunk-splitting in darcs record. This 
 beta is your chance to test-drive these improvements and make darcs even 
 better.

 If you have installed the Haskell Platform or cabal-install, you can install
 this beta release by doing:

   $ cabal update
   $ cabal install --reinstall darcs-beta

 Alternatively, you can download the tarball from 
 http://darcs.net/releases/darcs-2.3.98.1.tar.gz , and build it by hand as 
 explained in the README file. 

 A list of important changes since 2.3.1 is as follows (please let me know if 
 there's something you miss!):

* Use fast index-based diffing everywhere (Petr)
* Interactive patch splitting (Ganesh)
* An 'optimize --upgrade' option to convert  to hashed format in-place 
  (Eric)
* Hunk matching (Kamil Dworakowski, tat.wright)
* Progress reporting is no longer deceptive (Roman Plášil)
* A 'remove --recursive' option to remove a directory tree from revision
  control (Roman Plášil)
* A '--remote-darcs' flag for pushing to a host where darcs isn't called
  darcs
* Many miscellaneous Windows improvements (Salvatore, Petr and others)
* 'darcs send' now mentions the repository name in the email body (Joachim)
* Handle files with boring names in the repository correctly (Petr)
* Fix parsing of .authorspellings file (Tomáš Caitt)
* Various sane new command-line option names (Florent)
* Remove the '--checkpoint' option (Petr)
* Use external libraries for all UTF-8 handling (Eric, Reinier)
* Use the Haskell zlib package exclusively for compression (Petr)

 Kind Regards,
 the darcs release manager,
 Reinier Lamers
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Miguel Mitrofanov

Is there any kind of ST monad that allows to know if some STRef is no longer 
needed?

The problem is, I want to send some data to an external storage over a network 
and get it back later, but I don't want to send unnecessary data.

I've managed to do something like that with weak pointers, System.Mem.performGC 
and unsafePerformIO, but it seems to me that invoking GC every time is an 
overkill.

Oh, and I'm ready to trade the purity of runST for that, if necessary.

Thanks.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Dan Doel
On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:
 Is there any kind of ST monad that allows to know if some STRef is no
  longer needed?
 
 The problem is, I want to send some data to an external storage over a
  network and get it back later, but I don't want to send unnecessary data.
 
 I've managed to do something like that with weak pointers,
  System.Mem.performGC and unsafePerformIO, but it seems to me that invoking
  GC every time is an overkill.
 
 Oh, and I'm ready to trade the purity of runST for that, if necessary.

You may be able to use something like Oleg's Lightweight Monadic Regions to 
get this effect. I suppose it depends somewhat on what qualifies a reference 
as no longer needed.

  http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf

I'm not aware of anything out-of-the-box that does what you want, though.

-- Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: FASTER primes

2010-01-06 Thread Will Ness
Will Ness will_n48 at yahoo.com writes:

 
 Daniel Fischer daniel.is.fischer at web.de writes:
 
  Am Dienstag 05 Januar 2010 14:49:58 schrieb Will Ness:
  
 euler ks@(p:rs) = p : euler (rs `minus` map (*p) ks)
 primes = 2:euler [3,5..]
  
  
 
 Re-write:
 
  primes  = euler $ rollFrom [2] 1
   = 2:euler ( rollFrom [3] 1 `minus` map(2*) (rollFrom [2] 1)) )
   rollFrom [3,4] 2 `minus` rollFrom [4] 2
 -- rollFrom [3] 2 --
   = 2:3:euler (rollFrom [5] 2 `minus` map(3*) (rollFrom [3] 2))
rollFrom [5,7,9] 6 `minus` rollFrom [9] 6
 -- rollFrom [5,7] 6 --
   = 2:3:5:euler (rollFrom [7,11] 6 `minus` rollFrom [25,35] 30)
[7,11, 13,17, 19,23, 25,29, 31,35] 30
  -- rollFrom [7,11,13,17,19,23,29,31] 30 --
   = .
 

correction:

where
  rollOnce (x:xs) by = (x, xs ++ [x+by])
  rollFrom xs by = concat $ iterate (map (+ by)) (xs)
  multRoll xs@(x:_) by p = takeWhile ( (x+p*by)) $ rollFrom xs by

 
 so, reifying, we get
 
  data Roll a = Roll [a] a
 
  rollOnce (Roll (x:xs) by) = (x,Roll (xs ++ [x+by]) by)
  rollFrom (Roll xs by) = concat $ iterate (map (+ by)) (xs)
  multRoll r@(Roll (x:_) by) p 
   = Roll (takeWhile ( (x+p*by)) $ rollFrom r) (by*p)
 
  primes  = euler $ Roll [2] 1
  euler r@(Roll xs _)
 = x:euler (Roll (mxs `minus` map (x*) xs)  mby)
   where  
(x,r') = rollOnce r
(Roll mxs mby) = multRoll r' x
 

There's much extra primes pre-calculated inside the Roll, of course.

For any (Roll xs@(x:_) _),  (takeWhile ( x*x) xs) are all primes too.

When these are used, the code's complexity is around O(n^1.5), and it runs 
about 1.8x slower than Postponed Filters.

The faithful sieve's empirical complexity is above 2.10..2.25 and rising. So 
it might not be exponential, bbut is worse than power it seems anyway.





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Miguel Mitrofanov

I'll take a look at them.

I want something like this:

refMaybe b dflt ref = if b then readRef ref else return dflt
refIgnore ref = return blablabla
refFst ref =
   do
  (v, w) - readRef ref
  return v
test =
   do
  a - newRef x
  b - newRef 1
  c - newRef ('z', Just 0)
  performLocalGC -- if necessary
  x - isStillNeeded a
  y - isStillNeeded b
  z - isStillNeeded c
  u - refMaybe y t a -- note that it wouldn't actually read a,
-- but it won't be known until runtime.
  w - refIgnore b
  v - refFst c
  return (x, y, z)

so that run test returns (True, False, True).

Dan Doel wrote:

On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:

Is there any kind of ST monad that allows to know if some STRef is no
 longer needed?

The problem is, I want to send some data to an external storage over a
 network and get it back later, but I don't want to send unnecessary data.

I've managed to do something like that with weak pointers,
 System.Mem.performGC and unsafePerformIO, but it seems to me that invoking
 GC every time is an overkill.

Oh, and I'm ready to trade the purity of runST for that, if necessary.


You may be able to use something like Oleg's Lightweight Monadic Regions to 
get this effect. I suppose it depends somewhat on what qualifies a reference 
as no longer needed.


  http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf

I'm not aware of anything out-of-the-box that does what you want, though.

-- Dan
___
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] darcs 2.4 beta 1 release

2010-01-06 Thread Sittampalam, Ganesh
Obviously source code documentation would be nice, but why is it 
show-stopping?

Ivan Lazar Miljenovic wrote:
 I really feel that bug 1720 [1] is a show-stopping bug for darcs,
 especially since it means that building Haddock for darcs with
 GHC-6.12.* isn't possible. 
 
 [1] http://bugs.darcs.net/issue1720
 
 I tried to make a fix, but didn't know enough of how darcs is
 documented to be able to do anything. 
 
 
 Reinier Lamers tux_roc...@reinier.de writes:
 
 Hi all,
 
 The darcs team would like to announce the immediate availability of
 darcs 2.4 beta 1. darcs 2.4 will contain many improvements and
 bugfixes compared to darcs 2.3.1. Highlights are the fast index-based
 diffing which is now used by all darcs commands, and the interactive
 hunk-splitting in darcs record. This beta is your chance to
 test-drive 
 these improvements and make darcs even better.
 
 If you have installed the Haskell Platform or cabal-install, you can
 install this beta release by doing:
 
   $ cabal update
   $ cabal install --reinstall darcs-beta
 
 Alternatively, you can download the tarball from
 http://darcs.net/releases/darcs-2.3.98.1.tar.gz , and build it by
 hand 
 as explained in the README file.
 
 A list of important changes since 2.3.1 is as follows (please let me
 know if there's something you miss!):
 
* Use fast index-based diffing everywhere (Petr)
* Interactive patch splitting (Ganesh)
* An 'optimize --upgrade' option to convert  to hashed format
 in-place  (Eric) 
* Hunk matching (Kamil Dworakowski, tat.wright)
* Progress reporting is no longer deceptive (Roman Plášil)
* A 'remove --recursive' option to remove a directory tree from
 revision  control (Roman Plášil) 
* A '--remote-darcs' flag for pushing to a host where darcs isn't
 called  darcs 
* Many miscellaneous Windows improvements (Salvatore, Petr and
 others) 
* 'darcs send' now mentions the repository name in the email body
 (Joachim) 
* Handle files with boring names in the repository correctly
 (Petr) 
* Fix parsing of .authorspellings file (Tomáš Caitt)
* Various sane new command-line option names (Florent)
* Remove the '--checkpoint' option (Petr)
* Use external libraries for all UTF-8 handling (Eric, Reinier)
* Use the Haskell zlib package exclusively for compression (Petr)
 
 Kind Regards,
 the darcs release manager,
 Reinier Lamers
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


=== 
 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


[Haskell-cafe] Re: FASTER primes

2010-01-06 Thread Will Ness
Daniel Fischer daniel.is.fischer at web.de writes:

 
 
 Am Mittwoch 06 Januar 2010 00:09:07 schrieb Will Ness:
  Daniel Fischer daniel.is.fischer at web.de writes:
   Am Montag 04 Januar 2010 22:25:28 schrieb Daniel Fischer:
   Fix rfold:
  
   rfold f [x] = x
   rfold f xs = rfold f (pairwise f xs)
  
   and it's faster also for those.
 
 
 The memory is almost completely due to the tree-merging of the multiples for
 the fastest runner. While it produces faster than flat merging, the
 exponential growth of the trees makes  a bad memory citizen.


Isn't the number of nodes the same in any two trees with the same number of 
leafs?

BTW using

 compos ps = fst $ tfold mergeSP $ nwise 1 mergeSP $ map pmults ps

instead of 

 compos ps = fst $ tfold mergeSP $ nwise 1 mergeSP 
 $ pairwise mergeSP $ map pmults ps

brings down memory consumption further by 25%..45% on 1..8 mln primes produced, 
while slowing it down by about 0%..2% (that's after eliminating the lazy 
pattern in tfold as per your advice).


  'pairwise' puts odd leafs higher on the right. It might be better if it was
  so on the left, for the frequency of production is higher.
 
 Maybe. But how would you do it? I tried passing the length to rfold, so when
 there was an odd numberof trees in the list, it would move the first out of
 the recursion. Any possible gains in production have been more than eaten up
 by the control code (not a big difference, but it was there).


yes I've seen this too now. BTW, at a price of further slowing down, memory can 
be lowered yet more with


 compos ps = fst $ tfold mergeSP $ nwise 1 0.4 mergeSP $ map pmults ps
 nwise k d f xs = let (ys,zs) = splitAt (round k) xs 
  in rfold f ys : nwise (k+d) d f zs


It really looks like the nearer the structure is to linear list, the lower the 
memory consumption becomes. Of course using 0.0 in place of 0.4 would make it 
into a plain list.





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Significant slow-down in parallel code?

2010-01-06 Thread Neil Mitchell
There was a paper at the Haskell Symposium 2009, and the video is
online: http://www.vimeo.com/6680185

Thanks, Neil

On Tue, Jan 5, 2010 at 2:23 AM, Jamie Morgenstern
cantthinkthinkp...@gmail.com wrote:
 I am using 6.12... are there any good pointers as to how one uses
 threadscope?

 On Mon, Jan 4, 2010 at 3:14 PM, Neil Mitchell ndmitch...@gmail.com wrote:

 Hi Jamie,

 First question, what version of GHC are you using? There are
 significant performance improvements to parallel code in GHC 6.12, so
 it's worth an upgrade. Once you've upgraded you might want to try out
 threadscope which is designed to help track down these sorts of
 problems.

 If you are using 6.10, I recommend turning off parallel garbage
 collection with the RTS flags (see the manual) as that can cause
 slowdowns.

 Thanks, Neil

 2010/1/4 Jamie Morgenstern cantthinkthinkp...@gmail.com:
  Hello;
 
   I have a piece of code in which I employ the `par` construct to add
  some implicit parallelism
  to a theorem prover. However, when running the *same* code with
 
  +RTS -N1
  +RTS -N5
  +RTS -N10
 
  I see a huge slowdown (a factor of 50 with 5 processes and a factor of
  100 for 10 on an 8-core machine).
 
  Very little time is being spent using the garbage collector. Any
  suggestions?
 
  Thanks,
  -Jamie
 
  ___
  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] Explicit garbage collection

2010-01-06 Thread Edward Kmett
You probably just want to hold onto weak references for your 'isStillNeeded'
checks.

Otherwise the isStillNeeded check itself will keep you from garbage
collecting!

http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html

-Edward Kmett

On Wed, Jan 6, 2010 at 9:39 AM, Miguel Mitrofanov miguelim...@yandex.ruwrote:

 I'll take a look at them.

 I want something like this:

 refMaybe b dflt ref = if b then readRef ref else return dflt
 refIgnore ref = return blablabla
 refFst ref =
   do
  (v, w) - readRef ref
  return v
 test =
   do
  a - newRef x
  b - newRef 1
  c - newRef ('z', Just 0)
  performLocalGC -- if necessary
  x - isStillNeeded a
  y - isStillNeeded b
  z - isStillNeeded c
  u - refMaybe y t a -- note that it wouldn't actually read a,
-- but it won't be known until runtime.
  w - refIgnore b
  v - refFst c
  return (x, y, z)

 so that run test returns (True, False, True).


 Dan Doel wrote:

 On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:

 Is there any kind of ST monad that allows to know if some STRef is no
  longer needed?

 The problem is, I want to send some data to an external storage over a
  network and get it back later, but I don't want to send unnecessary
 data.

 I've managed to do something like that with weak pointers,
  System.Mem.performGC and unsafePerformIO, but it seems to me that
 invoking
  GC every time is an overkill.

 Oh, and I'm ready to trade the purity of runST for that, if necessary.


 You may be able to use something like Oleg's Lightweight Monadic Regions
 to get this effect. I suppose it depends somewhat on what qualifies a
 reference as no longer needed.

  
 http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdfhttp://www.cs.rutgers.edu/%7Eccshan/capability/region-io.pdf

 I'm not aware of anything out-of-the-box that does what you want, though.

 -- Dan
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Miguel Mitrofanov


On 6 Jan 2010, at 23:21, Edward Kmett wrote:

You probably just want to hold onto weak references for your  
'isStillNeeded' checks.


That's what I do now. But I want to minimize the network traffic, so I  
want referenced values to be garbage collected as soon as possible -  
and I couldn't find anything except System.Mem.performIO to do the job  
- which is a bit too global for me.


Otherwise the isStillNeeded check itself will keep you from garbage  
collecting!


Not necessary. What I'm imagining is that there is essentially only  
one way to access the value stored in the reference - with readRef.  
So, if there isn't any chance that readRef would be called, the value  
can be garbage collected; isStillNeeded function only needs the  
reference, not the value.


Well, yeah, that's kinda like weak references.



http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html

-Edward Kmett

On Wed, Jan 6, 2010 at 9:39 AM, Miguel Mitrofanov miguelim...@yandex.ru 
 wrote:

I'll take a look at them.

I want something like this:

refMaybe b dflt ref = if b then readRef ref else return dflt
refIgnore ref = return blablabla
refFst ref =
  do
 (v, w) - readRef ref
 return v
test =
  do
 a - newRef x
 b - newRef 1
 c - newRef ('z', Just 0)
 performLocalGC -- if necessary
 x - isStillNeeded a
 y - isStillNeeded b
 z - isStillNeeded c
 u - refMaybe y t a -- note that it wouldn't actually read a,
   -- but it won't be known until runtime.
 w - refIgnore b
 v - refFst c
 return (x, y, z)

so that run test returns (True, False, True).


Dan Doel wrote:
On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:
Is there any kind of ST monad that allows to know if some STRef is  
no

 longer needed?

The problem is, I want to send some data to an external storage over a
 network and get it back later, but I don't want to send unnecessary  
data.


I've managed to do something like that with weak pointers,
 System.Mem.performGC and unsafePerformIO, but it seems to me that  
invoking

 GC every time is an overkill.

Oh, and I'm ready to trade the purity of runST for that, if necessary.

You may be able to use something like Oleg's Lightweight Monadic  
Regions to get this effect. I suppose it depends somewhat on what  
qualifies a reference as no longer needed.


 http://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf

I'm not aware of anything out-of-the-box that does what you want,  
though.


-- Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with cabal install zlib

2010-01-06 Thread Ozgur Akgun
Just to check, anyone running Snow Leopard and *CAN* install zlib-0.5.2.0
using cabal install zlib?

I'm trying to make sure whether I am the only one having this problem or I
have some companion.

Best,


2009/12/22 Duncan Coutts duncan.cou...@googlemail.com

 On Tue, 2009-12-22 at 21:48 +, Ozgur Akgun wrote:
  What about this part:
 
  -o dist/build/Codec/Compression/
  Zlib/Stream.hs Codec/Compression/Zlib/Stream.hsc
 
  Isn't it passing multiple (two in this case) output parameters? Or am
  I missing sth?

 No, that's one -o flag and a single additional non-flag argument which
 is the input file. It's like:

 $ command input -o output

 but with the order reversed as:

 $ command -o output input


 Duncan




-- 
Ozgur Akgun
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with cabal install zlib

2010-01-06 Thread Gregory Collins
Ozgur Akgun ozgurak...@gmail.com writes:

 Just to check, anyone running Snow Leopard and *CAN* install
 zlib-0.5.2.0 using cabal install zlib?

 I'm trying to make sure whether I am the only one having this problem
 or I have some companion.

$ cabal install --reinstall zlib
Resolving dependencies...
Configuring zlib-0.5.2.0...
Preprocessing library zlib-0.5.2.0...
Building zlib-0.5.2.0...
[1 of 5] Compiling Codec.Compression.Zlib.Stream ( 
dist/build/Codec/Compression/Zlib/Stream.hs, 
dist/build/Codec/Compression/Zlib/Stream.o )
[2 of 5] Compiling Codec.Compression.Zlib.Internal ( 
Codec/Compression/Zlib/Internal.hs, 
dist/build/Codec/Compression/Zlib/Internal.o )
[3 of 5] Compiling Codec.Compression.Zlib.Raw ( 
Codec/Compression/Zlib/Raw.hs, dist/build/Codec/Compression/Zlib/Raw.o )
[4 of 5] Compiling Codec.Compression.Zlib ( Codec/Compression/Zlib.hs, 
dist/build/Codec/Compression/Zlib.o )
[5 of 5] Compiling Codec.Compression.GZip ( Codec/Compression/GZip.hs, 
dist/build/Codec/Compression/GZip.o )
ar: creating archive dist/build/libHSzlib-0.5.2.0.a
Installing library in /Users/greg/.cabal/lib/zlib-0.5.2.0/ghc-6.10.4
Registering zlib-0.5.2.0...
Reading package info from dist/installed-pkg-config ... done.
Writing new package config file... done.

No problem here. Please ensure you've patched /usr/bin/ghc,
/usr/bin/ghci, /usr/bin/runhaskell, /usr/bin/runghc, and /usr/bin/hsc2hs
according to the instructions on http://haskell.org/haskellwiki/OSX .

The next release of the Haskell Platform installer should fix this
issue.

G
-- 
Gregory Collins g...@gregorycollins.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ghc -e

2010-01-06 Thread Tony Morris
Can I import a module when using ghc -e?

e.g. ghc -e import Control.Monad; forM [[1,2,3]] reverse

-- 
Tony Morris
http://tmorris.net/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Gwern Branwen
On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris tonymor...@gmail.com wrote:
 ghc -e import Control.Monad; forM [[1,2,3]] reverse

As of 6.10.2, the bug whereby the GHC API lets you use functions from
anywhere just by naming them (Java-style) has not been fixed:

$ ghc -e Control.Monad.forM [[1,2,3]] reverse
package flags have changed, resetting and loading new packages...

interactive:1:25:
Warning: Defaulting the following constraint(s) to type `Integer'
 `Num t' arising from the literal `3' at interactive:1:25
In the expression: 3
In the expression: [1, 2, 3]
In the first argument of `forM', namely `[[1, 2, 3]]'

interactive:1:25:
Warning: Defaulting the following constraint(s) to type `Integer'
 `Num t' arising from the literal `3' at interactive:1:25
In the expression: 3
In the expression: [1, 2, 3]
In the first argument of `forM', namely `[[1, 2, 3]]'
[[3],[2],[1]]
it :: [[Integer]]
(0.01 secs, 1710984 bytes)

-- 
gwern
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Tony Morris
Gwern Branwen wrote:
 On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris tonymor...@gmail.com wrote:
   
 ghc -e import Control.Monad; forM [[1,2,3]] reverse
 

 As of 6.10.2, the bug whereby the GHC API lets you use functions from
 anywhere just by naming them (Java-style) has not been fixed:

 $ ghc -e Control.Monad.forM [[1,2,3]] reverse
 package flags have changed, resetting and loading new packages...

 interactive:1:25:
 Warning: Defaulting the following constraint(s) to type `Integer'
  `Num t' arising from the literal `3' at interactive:1:25
 In the expression: 3
 In the expression: [1, 2, 3]
 In the first argument of `forM', namely `[[1, 2, 3]]'

 interactive:1:25:
 Warning: Defaulting the following constraint(s) to type `Integer'
  `Num t' arising from the literal `3' at interactive:1:25
 In the expression: 3
 In the expression: [1, 2, 3]
 In the first argument of `forM', namely `[[1, 2, 3]]'
 [[3],[2],[1]]
 it :: [[Integer]]
 (0.01 secs, 1710984 bytes)

   
I see the same on GHC 6.10.4.
$ ghc -e Control.Monad.forM [[1,2,3]] reverse
[[3],[2],[1]]


What would it be fixed to? What is wrong with how it is?

-- 
Tony Morris
http://tmorris.net/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Value classes

2010-01-06 Thread Henning Thielemann

Mads Lindstrøm schrieb:

Hi

A function inc5

  inc5 :: Float - Float
  inc5 x = x + 5

can only be a member of a type class A, if we make all functions from
Float - Float members of type class A. Thus, I assume, that _type_
class is named type class, as membership is decided by types.

However, it makes no sense to say that all functions from Float - Float
are invertible or continuous. We would want to specifically say that
inc5 is continuous, not all Float - Float functions. Thus, we could
have another abstraction, lets call it _value_ class, where we could say
that an individual value (function) could be member. We could say
something like:

  class Invertible (f :: a - a) where
invert :: f - (a - a)

  instance Invertible inc5 where
invert _ = \x - x - 5

In many cases this would be too specific. We would like to say, that
applying the first argument to `+` returns an invertible function.
Something like:

  instance Invertible (`+` x) where
invert (x +) = \y - y - x

We would properly also like to say, that composing two invertible
functions results in another invertible function. I guess there are many
more examples.
  

Maybe you could define types like

newtype InvertibleFunction a b = InvertibleFunction (a - b)
newtype ContinuousFunction a b = ContinuousFunction (a - b)
or
newtype AttributedFunction attr a b = AttributedFunction a b
where attr can be Invertible, Continuous, or (Invertible, Continuous).
Then you may define a type class that provides a functional inverse, if 
attr shows invertibility.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Reid Barton
On Thu, Jan 07, 2010 at 10:23:35AM +1000, Tony Morris wrote:
 Can I import a module when using ghc -e?
 
 e.g. ghc -e import Control.Monad; forM [[1,2,3]] reverse

One option is to create a file imports.hs which contains the text
import Control.Monad, and then run

ghc -e forM [[1,2,3]] reverse imports.hs

I use this method in a short shell script interact so that I can
apply Haskell functions to files from the command line and don't have
to type the full qualified names of things in modules I use frequently.

Regards,
Reid Barton
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Gwern Branwen
On Wed, Jan 6, 2010 at 7:35 PM, Tony Morris tonymor...@gmail.com wrote:
 Gwern Branwen wrote:
 On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris tonymor...@gmail.com wrote:

 ghc -e import Control.Monad; forM [[1,2,3]] reverse


 As of 6.10.2, the bug whereby the GHC API lets you use functions from
 anywhere just by naming them (Java-style) has not been fixed:

 $ ghc -e Control.Monad.forM [[1,2,3]] reverse
 package flags have changed, resetting and loading new packages...

 interactive:1:25:
     Warning: Defaulting the following constraint(s) to type `Integer'
              `Num t' arising from the literal `3' at interactive:1:25
     In the expression: 3
     In the expression: [1, 2, 3]
     In the first argument of `forM', namely `[[1, 2, 3]]'

 interactive:1:25:
     Warning: Defaulting the following constraint(s) to type `Integer'
              `Num t' arising from the literal `3' at interactive:1:25
     In the expression: 3
     In the expression: [1, 2, 3]
     In the first argument of `forM', namely `[[1, 2, 3]]'
 [[3],[2],[1]]
 it :: [[Integer]]
 (0.01 secs, 1710984 bytes)


 I see the same on GHC 6.10.4.
 $ ghc -e Control.Monad.forM [[1,2,3]] reverse
 [[3],[2],[1]]


 What would it be fixed to? What is wrong with how it is?

Presumably one then have to use some sort of flag to ask for
Control.Monad specifically to be visible.

What's wrong with it is that this is not merely GHCi behavior, this is
universal GHC API behavior and wildly insecure:
http://hackage.haskell.org/trac/ghc/ticket/2452

-- 
gwern
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Jason Dagit
On Wed, Jan 6, 2010 at 6:15 PM, Reid Barton rwbar...@math.harvard.eduwrote:

 On Thu, Jan 07, 2010 at 10:23:35AM +1000, Tony Morris wrote:
  Can I import a module when using ghc -e?
 
  e.g. ghc -e import Control.Monad; forM [[1,2,3]] reverse

 One option is to create a file imports.hs which contains the text
 import Control.Monad, and then run

 ghc -e forM [[1,2,3]] reverse imports.hs

 I use this method in a short shell script interact so that I can
 apply Haskell functions to files from the command line and don't have
 to type the full qualified names of things in modules I use frequently.


Did you know you can put commands in $HOME/.ghci that will be loaded every
time you run ghci?

So, if you have modules that you commonly use put something like:
:m + Control.Monad

In your $HOME/.ghci file and then you can use ghci instead of this ghc -e
trick.

HTH,
Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Edward Kmett
I don't believe you can get quite the semantics you want. However, you can
get reasonably close, by building a manual store and backtracking.

{-# LANGUAGE Rank2Types #-}
-- lets define an Oracle that tracks whether or not you might need the
reference, by backtracking.
module Oracle
( Oracle, Ref
, newRef, readRef, writeRef, modifyRef, needRef
) where

import Control.Applicative
import Control.Arrow (first)
import Control.Monad
import Data.IntMap (IntMap)
import qualified Data.IntMap as M
import Unsafe.Coerce (unsafeCoerce)
import GHC.Prim (Any)

-- we need to track our own worlds, otherwise we'd have to build over ST,
change optimistically, and track how to backtrack the state of the Store.
Much uglier.
-- values are stored as 'Any's for safety, see GHC.Prim for a discussion on
the hazards of risking the storage of function types using unsafeCoerce as
anything else.
data World s = World { store :: !(IntMap Any), hwm :: !Int }

-- references into our store
newtype Ref s a = Ref Int deriving (Eq)

-- our monad that can 'see the future' ~ StateT (World s) []
newtype Oracle s a = Oracle { unOracle :: World s - [(a, World s)] }

-- we rely on the fact that the list is always non-empty for any oracle you
can run. we are only allowed to backtrack if we thought we wouldn't need the
reference, and wound up needing it, so head will always succeed.
runOracle :: (forall s. Oracle s a) - a
runOracle f = fst $ head $ unOracle f $ World M.empty 1


instance Monad (Oracle s) where
return a = Oracle $ \w - [(a,w)]
Oracle m = k = Oracle $ \s - do
(a,s') - m s
unOracle (k a) s'

-- note: you cannot safely define fail here without risking a crash in
runOracle
-- Similarly, we're not a MonadPlus instance because we always want to
succeed eventually.

instance Functor (Oracle s) where
fmap f (Oracle g) = Oracle $ \w - first f $ g w

instance Applicative (Oracle s) where
pure = return
(*) = ap

-- new ref allocates a fresh slot and inserts the value into the store. the
type level brand 's' keeps us safe, and we don't export the Ref constructor.
newRef :: a - Oracle s (Ref s a)
newRef a = Oracle $ \(World w t) -
[(Ref t, World (M.insert t (unsafeCoerce a) w) (t + 1))]

-- readRef is the only thing that ever backtracks, if we try to read a
reference we claimed we wouldn't need, then we backtrack to when we decided
we didn't need the reference, and continue with its value.
readRef :: Ref s a - Oracle s a
readRef (Ref slot) = Oracle $ \world -
maybe [] (\a - [(unsafeCoerce a, world)]) $ M.lookup slot (store world)

-- note, writeRef dfoesn't 'need' the ref's current value, so needRef will
report False if you writeRef before you read it after this.
writeRef :: a - Ref s a - Oracle s a
writeRef a (Ref slot) = Oracle $ \world -
[(a, world { store = M.insert slot (unsafeCoerce a) $ store world
})]

{-
-- alternate writeRef where writing 'needs' the ref.
writeRef :: a - Ref s a - Oracle s a
writeRef a (Ref slot) = Oracle $ \World store v - do
(Just _, store') - return $ updateLookupWithKey replace slot store
[(a, World store' v)]
  where
replace _ _ = Just (unsafeCoerce a)
-}

-- modifying a reference of course needs its current value.
modifyRef :: (a - a) - Ref s a - Oracle s a
modifyRef f r = do
a - readRef r
writeRef (f a) r

-- needRef tries to continue executing the world without the element in the
store in question. if that fails, then we'll backtrack to here, and try
again with the original world, and report that the element was in fact
needed.
needRef :: Ref s a - Oracle s Bool
needRef (Ref slot) = Oracle $ \world -
[ (False, world { store = M.delete slot $ store world })
, (True, world)
]

-- test case:
refMaybe b dflt ref = if b then readRef ref else return dflt
refIgnore ref = return blablabla
refFst ref = fst $ readRef ref
test = do
 a - newRef x
 b - newRef 1
 c - newRef ('z', Just 0)
 -- no performLocalGC required
 x - needRef a
 y - needRef b
 z - needRef c
 u - refMaybe y t a -- note that it wouldn't actually read a,
   -- but it won't be known until runtime.
 w - refIgnore b
 v - refFst c
 return (x, y, z)

-- This will disagree with your desired answer, returning:

*Oracle runOracle test
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.1 ... linking ... done.
(False,False,True)

rather than (True, False, True), because the oracle is able to see into the
future (via backtracking) to see that refMaybe doesn't use the reference
after all.

This probably won't suit your needs, but it was a fun little exercise.

-Edward Kmett

On Wed, Jan 6, 2010 at 4:05 PM, Miguel Mitrofanov miguelim...@yandex.ruwrote:


 On 6 Jan 2010, at 23:21, Edward Kmett wrote:

  You probably just want to hold onto weak references for your
 'isStillNeeded' checks.


 That's what I do now. But I want to minimize 

[Haskell-cafe] ANNOUNCE: tuntap-0.0.1

2010-01-06 Thread John Van Enk
Hi All,

As some of you have requested, I've extracted the code from my (under work)
VPN which talks to the TUN/TAP device under Linux (/dev/net/tun).

Some things to note:
1) I've only tested this under Linux.
2) The help-win.c file under cbits HAS allowed similar code to talk to the
TUN/TAP driver used by the OpenVPN project, but I haven't implemented this
functionality yet.
3) The help-bsd.c file under cbits HAS allowed Mac/BSD flavors to talk to a
TUN/TAP driver, but I've never tested this and haven't implemented this
functionality yet.

I don't have a whole lot there right now, but keep a lookout for more
releases with some examples and better docs (as I get around to it).

For a very verbose example, you can look at how I use the Network.TUNTAP
module in this project: http://github.com/sw17ch/Scurry, specifically
http://github.com/sw17ch/Scurry/blob/master/src/Scurry/TAPTask.hs.

Hackage: http://hackage.haskell.org/package/tuntap
GitHub: http://github.com/sw17ch/tuntap

John Van Enk

PS: Thanks to Matthew Isleb and Job Vranish for their help on the C code
used.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Edward Kmett
Here is a slightly nicer version using the Codensity monad of STM.

Thanks go to Andrea Vezzosi for figuring out an annoying hanging bug I was
having.

-Edward Kmett

{-# LANGUAGE Rank2Types, GeneralizedNewtypeDeriving, DeriveFunctor
#-}module STMOracle( Oracle, Ref, newRef, readRef, writeRef,
modifyRef, needRef) whereimport Control.Applicativeimport
Control.Monadimport Control.Concurrent.STMinstance Applicative STM
wherepure = return(*) = apnewtype Ref s a = Ref (TVar (Maybe
a))newtype Oracle s a = Oracle { unOracle :: forall r. (a - STM r) -
STM r } deriving (Functor)instance Monad (Oracle s) where  return x =
Oracle (\k - k x)  Oracle m = f = Oracle (\k - m (\a - unOracle
(f a) k))mkOracle m = Oracle (m =)runOracle :: (forall s. Oracle s
a) - IO arunOracle t = atomically (unOracle t return)newRef :: a -
Oracle s (Ref s a)newRef a = mkOracle $ Ref $ newTVar (Just
a)readRef :: Ref s a - Oracle s areadRef (Ref r) = mkOracle $ dom
- readTVar rmaybe retry return mwriteRef :: a - Ref s a -
Oracle s awriteRef a (Ref r) = mkOracle $ dowriteTVar r (Just a)
 return amodifyRef :: (a - a) - Ref s a - Oracle s amodifyRef f r =
doa - readRef rwriteRef (f a) rneedRef :: Ref s a - Oracle s
BoolneedRef (Ref slot) = Oracle $ \k - (writeTVar slot
Nothing  k False)`orElse` k True-- test case:

 refMaybe b dflt ref = if b then
readRef ref else return dfltrefIgnore ref = return blablablarefFst
ref = fst `fmap` readRef reftest = do a - newRef x b -
newRef 1 c - newRef ('z', Just 0) -- no performLocalGC
required
 x - needRef a y
- needRef b z - needRef c u - refMaybe y t a -- note that
it wouldn't actually read a,
 -- but it
won't be known until runtime.
  w - refIgnore b v - refFst
c return (x, y, z)




On Wed, Jan 6, 2010 at 10:28 PM, Edward Kmett ekm...@gmail.com wrote:

 I don't believe you can get quite the semantics you want. However, you can
 get reasonably close, by building a manual store and backtracking.

 {-# LANGUAGE Rank2Types #-}
 -- lets define an Oracle that tracks whether or not you might need the
 reference, by backtracking.
 module Oracle
 ( Oracle, Ref
 , newRef, readRef, writeRef, modifyRef, needRef
 ) where

 import Control.Applicative
 import Control.Arrow (first)
 import Control.Monad
 import Data.IntMap (IntMap)
 import qualified Data.IntMap as M
 import Unsafe.Coerce (unsafeCoerce)
 import GHC.Prim (Any)

 -- we need to track our own worlds, otherwise we'd have to build over ST,
 change optimistically, and track how to backtrack the state of the Store.
 Much uglier.
 -- values are stored as 'Any's for safety, see GHC.Prim for a discussion on
 the hazards of risking the storage of function types using unsafeCoerce as
 anything else.
 data World s = World { store :: !(IntMap Any), hwm :: !Int }

 -- references into our store
 newtype Ref s a = Ref Int deriving (Eq)

 -- our monad that can 'see the future' ~ StateT (World s) []
 newtype Oracle s a = Oracle { unOracle :: World s - [(a, World s)] }

 -- we rely on the fact that the list is always non-empty for any oracle you
 can run. we are only allowed to backtrack if we thought we wouldn't need the
 reference, and wound up needing it, so head will always succeed.
 runOracle :: (forall s. Oracle s a) - a
 runOracle f = fst $ head $ unOracle f $ World M.empty 1


 instance Monad (Oracle s) where
 return a = Oracle $ \w - [(a,w)]
 Oracle m = k = Oracle $ \s - do
 (a,s') - m s
 unOracle (k a) s'

 -- note: you cannot safely define fail here without risking a crash in
 runOracle
 -- Similarly, we're not a MonadPlus instance because we always want to
 succeed eventually.

 instance Functor (Oracle s) where
 fmap f (Oracle g) = Oracle $ \w - first f $ g w

 instance Applicative (Oracle s) where
 pure = return
 (*) = ap

 -- new ref allocates a fresh slot and inserts the value into the store. the
 type level brand 's' keeps us safe, and we don't export the Ref constructor.
 newRef :: a - Oracle s (Ref s a)
 newRef a = Oracle $ \(World w t) -
 [(Ref t, World (M.insert t (unsafeCoerce a) w) (t + 1))]

 -- readRef is the only thing that ever backtracks, if we try to read a
 reference we claimed we wouldn't need, then we backtrack to when we decided
 we didn't need the reference, and continue with its value.
 readRef :: Ref s a - Oracle s a
 readRef (Ref slot) = Oracle $ \world -
 maybe [] (\a - [(unsafeCoerce a, world)]) $ M.lookup slot (store
 world)

 -- note, writeRef dfoesn't 'need' the ref's current value, so needRef will
 report False if you writeRef before you read it after this.
 writeRef :: a - Ref s a - Oracle s a
 writeRef a (Ref slot) = Oracle $ \world -
 [(a, world { store = M.insert slot (unsafeCoerce a) $ store world
 

Re: [Haskell-cafe] Explicit garbage collection

2010-01-06 Thread Miguel Mitrofanov

Seems very nice. Thanks.

On 7 Jan 2010, at 08:01, Edward Kmett wrote:


Here is a slightly nicer version using the Codensity monad of STM.

Thanks go to Andrea Vezzosi for figuring out an annoying hanging bug  
I was having.


-Edward Kmett

{-# LANGUAGE Rank2Types, GeneralizedNewtypeDeriving, DeriveFunctor #-}
module STMOracle
( Oracle, Ref
, newRef, readRef, writeRef, modifyRef, needRef
) where

import Control.Applicative
import Control.Monad
import Control.Concurrent.STM

instance Applicative STM where
pure = return
(*) = ap

newtype Ref s a = Ref (TVar (Maybe a))
newtype Oracle s a = Oracle { unOracle :: forall r. (a - STM r) -  
STM r } deriving (Functor)


instance Monad (Oracle s) where
  return x = Oracle (\k - k x)
  Oracle m = f = Oracle (\k - m (\a - unOracle (f a) k))

mkOracle m = Oracle (m =)

runOracle :: (forall s. Oracle s a) - IO a
runOracle t = atomically (unOracle t return)

newRef :: a - Oracle s (Ref s a)
newRef a = mkOracle $ Ref $ newTVar (Just a)

readRef :: Ref s a - Oracle s a
readRef (Ref r) = mkOracle $ do
m - readTVar r
maybe retry return m

writeRef :: a - Ref s a - Oracle s a
writeRef a (Ref r) = mkOracle $ do
writeTVar r (Just a)
return a

modifyRef :: (a - a) - Ref s a - Oracle s a
modifyRef f r = do
a - readRef r
writeRef (f a) r

needRef :: Ref s a - Oracle s Bool
needRef (Ref slot) = Oracle $ \k -
 (writeTVar slot Nothing  k False)
`orElse` k True

-- test  
case 
:
refMaybe b dflt ref = if b then readRef ref else return dflt

refIgnore ref = return blablabla
refFst ref = fst `fmap` readRef ref
test = do
 a - newRef x
 b - newRef 1
 c - newRef ('z', Just 0)
 -- no performLocalGC required
 x - needRef a
 y - needRef b
 z - needRef c
 u - refMaybe y t a -- note that it wouldn't actually read a,
   -- but it won't be known until runtime.
 w - refIgnore b
 v - refFst c
 return (x, y, z)



On Wed, Jan 6, 2010 at 10:28 PM, Edward Kmett ekm...@gmail.com  
wrote:
I don't believe you can get quite the semantics you want. However,  
you can get reasonably close, by building a manual store and  
backtracking.


{-# LANGUAGE Rank2Types #-}
-- lets define an Oracle that tracks whether or not you might need  
the reference, by backtracking.

module Oracle
( Oracle, Ref
, newRef, readRef, writeRef, modifyRef, needRef
) where

import Control.Applicative
import Control.Arrow (first)
import Control.Monad
import Data.IntMap (IntMap)
import qualified Data.IntMap as M
import Unsafe.Coerce (unsafeCoerce)
import GHC.Prim (Any)

-- we need to track our own worlds, otherwise we'd have to build  
over ST, change optimistically, and track how to backtrack the state  
of the Store. Much uglier.
-- values are stored as 'Any's for safety, see GHC.Prim for a  
discussion on the hazards of risking the storage of function types  
using unsafeCoerce as anything else.

data World s = World { store :: !(IntMap Any), hwm :: !Int }

-- references into our store
newtype Ref s a = Ref Int deriving (Eq)

-- our monad that can 'see the future' ~ StateT (World s) [] 
newtype Oracle s a = Oracle { unOracle :: World s - [(a, World s)] }


-- we rely on the fact that the list is always non-empty for any  
oracle you can run. we are only allowed to backtrack if we thought  
we wouldn't need the reference, and wound up needing it, so head  
will always succeed.

runOracle :: (forall s. Oracle s a) - a
runOracle f = fst $ head $ unOracle f $ World M.empty 1


instance Monad (Oracle s) where
return a = Oracle $ \w - [(a,w)]
Oracle m = k = Oracle $ \s - do
(a,s') - m s
unOracle (k a) s'

-- note: you cannot safely define fail here without risking a crash  
in runOracle
-- Similarly, we're not a MonadPlus instance because we always want  
to succeed eventually.


instance Functor (Oracle s) where
fmap f (Oracle g) = Oracle $ \w - first f $ g w

instance Applicative (Oracle s) where
pure = return
(*) = ap

-- new ref allocates a fresh slot and inserts the value into the  
store. the type level brand 's' keeps us safe, and we don't export  
the Ref constructor.

newRef :: a - Oracle s (Ref s a)
newRef a = Oracle $ \(World w t) -
[(Ref t, World (M.insert t (unsafeCoerce a) w) (t + 1))]

-- readRef is the only thing that ever backtracks, if we try to read  
a reference we claimed we wouldn't need, then we backtrack to when  
we decided we didn't need the reference, and continue with its value.

readRef :: Ref s a - Oracle s a
readRef (Ref slot) = Oracle $ \world -
maybe [] (\a - [(unsafeCoerce a, world)]) $ M.lookup slot  
(store world)


-- note, writeRef dfoesn't 'need' the ref's current value, so  
needRef will report False if you writeRef before you read it after  
this.

writeRef :: a - Ref s a - Oracle s a

Re: [Haskell-cafe] darcs 2.4 beta 1 release

2010-01-06 Thread Ivan Lazar Miljenovic
Sittampalam, Ganesh ganesh.sittampa...@credit-suisse.com writes:

 Obviously source code documentation would be nice, but why is it
 show-stopping?

I consider it show-stopping in the sense that I keep having people on
#gentoo-haskell asking me why they can't compile darcs 2.3.1 because
that error comes up, and I have to explain to either disable
documentation or downgrade Cabal (if they're still using GHC-6.11).

 Ivan Lazar Miljenovic wrote:
 I really feel that bug 1720 [1] is a show-stopping bug for darcs,
 especially since it means that building Haddock for darcs with
 GHC-6.12.* isn't possible. 
 
 [1] http://bugs.darcs.net/issue1720
 
 I tried to make a fix, but didn't know enough of how darcs is
 documented to be able to do anything. 
 
 
 Reinier Lamers tux_roc...@reinier.de writes:
 
 Hi all,
 
 The darcs team would like to announce the immediate availability of
 darcs 2.4 beta 1. darcs 2.4 will contain many improvements and
 bugfixes compared to darcs 2.3.1. Highlights are the fast index-based
 diffing which is now used by all darcs commands, and the interactive
 hunk-splitting in darcs record. This beta is your chance to
 test-drive 
 these improvements and make darcs even better.
 
 If you have installed the Haskell Platform or cabal-install, you can
 install this beta release by doing:
 
   $ cabal update
   $ cabal install --reinstall darcs-beta
 
 Alternatively, you can download the tarball from
 http://darcs.net/releases/darcs-2.3.98.1.tar.gz , and build it by
 hand 
 as explained in the README file.
 
 A list of important changes since 2.3.1 is as follows (please let me
 know if there's something you miss!):
 
* Use fast index-based diffing everywhere (Petr)
* Interactive patch splitting (Ganesh)
* An 'optimize --upgrade' option to convert  to hashed format
 in-place  (Eric) 
* Hunk matching (Kamil Dworakowski, tat.wright)
* Progress reporting is no longer deceptive (Roman Plášil)
* A 'remove --recursive' option to remove a directory tree from
 revision  control (Roman Plášil) 
* A '--remote-darcs' flag for pushing to a host where darcs isn't
 called  darcs 
* Many miscellaneous Windows improvements (Salvatore, Petr and
 others) 
* 'darcs send' now mentions the repository name in the email body
 (Joachim) 
* Handle files with boring names in the repository correctly
 (Petr) 
* Fix parsing of .authorspellings file (Tomáš Caitt)
* Various sane new command-line option names (Florent)
* Remove the '--checkpoint' option (Petr)
* Use external libraries for all UTF-8 handling (Eric, Reinier)
* Use the Haskell zlib package exclusively for compression (Petr)
 
 Kind Regards,
 the darcs release manager,
 Reinier Lamers
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


 ===
  
  Please access the attached hyperlink for an important electronic 
 communications disclaimer: 
  http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
  
 ===
  
  

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe