[Haskell-cafe] Re: [Haskell] ANN: Hipmunk 0.1 and HipmunkPlayground 0.1

2008-07-27 Thread Felipe Lessa
On Sun, Jul 27, 2008 at 12:34 AM, Felipe Lessa [EMAIL PROTECTED] wrote:
 On Sun, Jul 27, 2008 at 12:29 AM, Antoine Latter [EMAIL PROTECTED] wrote:
 I'm getting the following error trying to cabal-install HipmunkPlayground:
 [duplicate symbol _deRefStablePtr]

 Well, I guess this isn't a random problem then. I had this in one of
 the Linux boxes but the first thing I tried to solve it worked so
 dismissed it as something not so important. Now dons had this problem
 as well.

I've filled a GHC ticket at http://hackage.haskell.org/trac/ghc/ticket/2469 .

Thanks,

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


[Haskell-cafe] ANN: Yi 0.4.1

2008-07-27 Thread Jean-Philippe Bernardy
I'm very pleased to announce the 0.4.1 release of the Yi editor.

== Yi ==
Yi is a text editor written and extensible in Haskell. The
long-term goal of the Yi project is to provide the editor of
choice for Haskell programmers. In the meantime, we have fun by
hacking an editor in a decent language :)

Yi is not a finished product. This is an alpha-quality release.
However, Yi has become a lot more accessible than
previously, so if you feel like testing it, now might be a good time
to take a look.

== Installation ==

Using cabal install:

  cabal install yi-0.4.1

If you want gtk support, first install gtk2hs 0.9.13.
If you want vty support, pass the -fvty option to cabal install.

== Features ==
* A purely functional editor core;
* Key-bindings written as parsers of the input;
* Emacs, Vim and (partial) Cua emulations provided by default;
* Vty, Gtk2Hs, and (experimental) Cocoa front-ends;
* Static configuration (XMonad style) for fast load;
* Simple Haskell support:
* Syntax highlighting
* Auto-indentation
* Call cabal-build within the editor

== Links ==
* download: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/yi
* FAQ: http://haskell.org/haskellwiki/Yi/FAQ
* homepage: http://haskell.org/haskellwiki/Yi
* check and report issues: http://code.google.com/p/yi-editor/issues/list 
* darcs repository: http://code.haskell.org/yi
* get involved: mailto:[EMAIL PROTECTED]
* release notes: http://code.google.com/p/yi-editor/wiki/ReleaseNotes0o4

== Acks ==

This release is brought to you by:

Allan Clark
Andrew Birkett
Corey O'Connor
Duncan Coutts
Evan Martin
Fraser Wilson
Gustav Munkby
Gwern Branwen
Jean-Philippe Bernardy
Krasimr Angelov
Nicolas Pouillard
Sean Leather
Thomas Schilling

and all the contributors to the previous versions.

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


[Haskell-cafe] library for zip compression?

2008-07-27 Thread John MacFarlane
Haskellers,

Is there a library for compressing and uncompressing zip archives? I see
zlib and bzlib on HackageDB, but unless I'm mistaken these won't help
with a .zip archive. (See http://zlib.net/zlib_faq.html#faq11.) Any help
here would be appreciated.

John

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


Re: [HOpenGL] Re: [Haskell-cafe] Fw: patch applied (ghc): Remove the OpenGL familyof libraries fromextralibs

2008-07-27 Thread Christopher Lane Hinson


There is a section Projects using the OpenGL bindings 
(http://www.haskell.org/haskellwiki/OpenGL) on the wiki that is pretty 
bare.


A quick search of HCAR lists five projects using OpenGL.

--L

On Sat, 26 Jul 2008, Jefferson Heard wrote:

It would be nice to know, though, how many people are using it and what 
they're using it for.  I'm using it for information visualization, and 
slowly evolving/cribbing together something like the Processing

(http://www.processing.org) framework for Haskell as I do more things.

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


[Haskell-cafe] Exceptions

2008-07-27 Thread Adrian Neumann

Hello,

I think it'd be nice if the compiler could warn me if there are any  
exceptions which I'm not catching, similar to checked exceptions in  
Java. Does anyone know of a possibility to do that in Haskell?


Adrian


PGP.sig
Description: Signierter Teil der Nachricht
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Exceptions

2008-07-27 Thread Krzysztof Skrzętnicki
I don't really think this is possible: consider asynchronous
exceptions and throwTo.

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html#v%3AthrowTo

Since it can throw just *any* exception into thread. And this thread
might not be aware that anyone can throw him anything. Therefore it is
not possible to catch it while compiling it's code.

But Maybe I'm Just wrong.

Christopher Skrzętnicki

2008/7/27 Adrian Neumann [EMAIL PROTECTED]:
 Hello,

 I think it'd be nice if the compiler could warn me if there are any
 exceptions which I'm not catching, similar to checked exceptions in Java.
 Does anyone know of a possibility to do that in Haskell?

 Adrian

 ___
 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] ANN: Yi 0.4.1

2008-07-27 Thread Paulo Tanimoto
Fantastic release, thank you!  It's never been so easy to start
playing with Yi.  : )

Paulo

On Sun, Jul 27, 2008 at 10:08 AM, Jean-Philippe Bernardy
[EMAIL PROTECTED] wrote:
 I'm very pleased to announce the 0.4.1 release of the Yi editor.

 == Yi ==
 Yi is a text editor written and extensible in Haskell. The
 long-term goal of the Yi project is to provide the editor of
 choice for Haskell programmers. In the meantime, we have fun by
 hacking an editor in a decent language :)

 Yi is not a finished product. This is an alpha-quality release.
 However, Yi has become a lot more accessible than
 previously, so if you feel like testing it, now might be a good time
 to take a look.

 == Installation ==

 Using cabal install:

  cabal install yi-0.4.1

 If you want gtk support, first install gtk2hs 0.9.13.
 If you want vty support, pass the -fvty option to cabal install.

 == Features ==
* A purely functional editor core;
* Key-bindings written as parsers of the input;
* Emacs, Vim and (partial) Cua emulations provided by default;
* Vty, Gtk2Hs, and (experimental) Cocoa front-ends;
* Static configuration (XMonad style) for fast load;
* Simple Haskell support:
* Syntax highlighting
* Auto-indentation
* Call cabal-build within the editor

 == Links ==
* download: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/yi
* FAQ: http://haskell.org/haskellwiki/Yi/FAQ
* homepage: http://haskell.org/haskellwiki/Yi
* check and report issues: http://code.google.com/p/yi-editor/issues/list
* darcs repository: http://code.haskell.org/yi
* get involved: mailto:[EMAIL PROTECTED]
* release notes: http://code.google.com/p/yi-editor/wiki/ReleaseNotes0o4

 == Acks ==

 This release is brought to you by:

 Allan Clark
 Andrew Birkett
 Corey O'Connor
 Duncan Coutts
 Evan Martin
 Fraser Wilson
 Gustav Munkby
 Gwern Branwen
 Jean-Philippe Bernardy
 Krasimr Angelov
 Nicolas Pouillard
 Sean Leather
 Thomas Schilling

 and all the contributors to the previous versions.

 ___
 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] Exceptions

2008-07-27 Thread Don Stewart
aneumann:
 Hello,
 
 I think it'd be nice if the compiler could warn me if there are any  
 exceptions which I'm not catching, similar to checked exceptions in  
 Java. Does anyone know of a possibility to do that in Haskell?
 
 Adrian

You could provide exception-safe wrappers for the functions you use,
that catch any exception and flatten it to an Either type (or something
similar). Then GHC's usual coverage checking will enforce the handling.


import qualified System.IO
import Control.Exception

maybeReadFile :: FilePath - IO (Maybe String)
maybeReadFile f = handle (\_ - return Nothing)
 (Just `fmap` System.IO.readFile f)

{-
*A maybeReadFile /tmp/DOESNOTEXIST
Nothing
-}

main = do
mf - maybeReadFile DOESNOTEXIST
case mf of
 Nothing - return ()
 Just s  - print s


The ability to control exceptions seems like something we should have more 
solutions for.

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


Re: [Haskell-cafe] Cabal files on Windows

2008-07-27 Thread Henk-Jan van Tuyl

On Sun, 27 Jul 2008 03:23:09 +0200, John Lato [EMAIL PROTECTED] wrote:


Hello,

Can anyone point me to a method for including path names with spaces
in a cabal file?  I would like to add a line similar to the following:
include-dirs:  C:\Program Files\program\include
and of course a corresponding library as well.
[...]


Have you tried replacing Program Files with PROGRA~1? This is the old  
MS-Dos version of the directory name; you can find the old name with  
command

  dir /x C:\
, this displays the old version next to the new version of the name.


--
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--

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


Re: [Haskell-cafe] Cabal files on Windows

2008-07-27 Thread Duncan Coutts

On Sat, 2008-07-26 at 20:23 -0500, John Lato wrote:
 Hello,
 
 Can anyone point me to a method for including path names with spaces
 in a cabal file?  I would like to add a line similar to the following:
 include-dirs:  C:\Program Files\program\include
 and of course a corresponding library as well.

Use Haskell String syntax for paths that contain spaces:

include-dirs:  C:\\Program Files\\program\\include


Duncan

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


Re: [Haskell-cafe] ANN: Yi 0.4.1

2008-07-27 Thread Niklas Broberg
Hi Jean-Philippe,

  Using cabal install:

   cabal install yi-0.4.1

when I do this on my Windows machine, cabal-install tries to download
the unix-2.3.0.0 package, which clearly won't work. How do I get yi to
install on Windows?

Cheers,

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


Re: [Haskell-cafe] ANN: Yi 0.4.1

2008-07-27 Thread Don Stewart
jeanphilippe.bernardy:
 I'm very pleased to announce the 0.4.1 release of the Yi editor.
 
 == Yi ==
 Yi is a text editor written and extensible in Haskell. The
 long-term goal of the Yi project is to provide the editor of
 choice for Haskell programmers. In the meantime, we have fun by
 hacking an editor in a decent language :)
 
 Yi is not a finished product. This is an alpha-quality release.
 However, Yi has become a lot more accessible than
 previously, so if you feel like testing it, now might be a good time
 to take a look.

While the vty frontend is working, the gtk / pango frontends are erroring
for me with,

$ yi -f pango
Launching custom yi: /home/dons/.yi/yi-x86_64-linux
yi: exception :: System.Glib.GError.GError

Anyone seen this?

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


[Haskell-cafe] Re: ANN: Yi 0.4.1

2008-07-27 Thread Jean-Philippe Bernardy
Niklas Broberg niklas.broberg at gmail.com writes:

 
 Hi Jean-Philippe,
 
   Using cabal install:
 
cabal install yi-0.4.1
 
 when I do this on my Windows machine, cabal-install tries to download
 the unix-2.3.0.0 package, which clearly won't work. How do I get yi to
 install on Windows?


Vty frontend does not work on win32, so you must install gtk2hs (latest)
beforehand. 

Additionally, I recommend to use

cabal install yi-0.4.1 -f-vty -fgtk

to force choosing the right options.

Cheers,
JP.

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


[Haskell-cafe] Re: ANN: Yi 0.4.1

2008-07-27 Thread Jean-Philippe Bernardy
Don Stewart dons at galois.com writes:


 $ yi -f pango
 Launching custom yi: /home/dons/.yi/yi-x86_64-linux
 yi: exception :: System.Glib.GError.GError
 
 Anyone seen this?

Consistently on x64. The pango stuff is generally unstable anyway. I'm not sure
what's to blame.

-- JP 




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


Re[2]: [Haskell-cafe] Cabal files on Windows

2008-07-27 Thread Bulat Ziganshin
Hello Henk-Jan,

Sunday, July 27, 2008, 11:36:32 PM, you wrote:

 Can anyone point me to a method for including path names with spaces
 in a cabal file?  I would like to add a line similar to the following:
 Have you tried replacing Program Files with PROGRA~1? This is the old

i don't followed discussion but if this meant for distributable
packages, the following problems exist:

1. it may be progra~2 or ~3
2. it's possible to entirely disable short names generation on ntfs




-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Re: ANN: Yi 0.4.1

2008-07-27 Thread Niklas Broberg
Thanks, after installing gtk2hs and using the flags you told me I
managed to install it just fine. However...

   $ yi -f pango
   Launching custom yi: /home/dons/.yi/yi-x86_64-linux
   yi: exception :: System.Glib.GError.GError
  
   Anyone seen this?


 Consistently on x64. The pango stuff is generally unstable anyway. I'm not 
 sure
  what's to blame.

... I got this error too, and I'm on Win32. :-(

Cheers,

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


[Haskell-cafe] Re: ANN: Yi 0.4.1

2008-07-27 Thread Jean-Philippe Bernardy
Niklas Broberg niklas.broberg at gmail.com writes:

 
 Thanks, after installing gtk2hs and using the flags you told me I
 managed to install it just fine. However...

Good :)

 The pango stuff is generally unstable anyway. I'm not sure
   what's to blame.
 
 ... I got this error too, and I'm on Win32. 


The gtk frontend should not suffer from this:

yi -fgtk

-- JP.



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


Re: [Haskell-cafe] Re: ANN: Yi 0.4.1

2008-07-27 Thread Niklas Broberg
 The gtk frontend should not suffer from this:

  yi -fgtk

C:\Documents and Settings\Niklas Brobergyi -fgtk
yi: exception :: System.Glib.GError.GError

:-(

Cheers,

/Niklas

ps. If I installed it with -f-vty -fgtk, shouldn't gtk be the default
when running? :-)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: Yi 0.4.1

2008-07-27 Thread stefan kersten
On Sun, Jul 27, 2008 at 03:08:04PM +, Jean-Philippe Bernardy wrote:
 I'm very pleased to announce the 0.4.1 release of the Yi editor.

great, i can't wait to check it out ...

i get the following error when installing via hackage/cabal (ghc 6.8.1, cabal
1.4.0.1):

Yi/Buffer.hs:253:0:
No instance for (Typeable4 RWS)
  arising from the 'deriving' clause of a data type declaration
   at Yi/Buffer.hs:(253,0)-(254,101)
Possible fix: add an instance declaration for (Typeable4 RWS)
When deriving the instance for (Typeable1 BufferM)

Yi/Buffer.hs:256:0:
Can't make a derived instance of `Typeable4 RWS'
  (even with cunning newtype deriving:
   the representation type has wrong kind)
In the stand-alone deriving instance for `Typeable4 RWS'

any ideas what's going wrong? is it finally time to upgrade my ghc
installation?

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


[Haskell-cafe] Re: ANN: Hayoo! beta 0.2

2008-07-27 Thread Ben Franksen
Timo B. Hübel wrote:
 we are pleased to announce the second beta release of Hayoo!, a Haskell
 API search engine providing advanced features like suggestions,
 find-as-you-type, fuzzy queries and much more.
 
 Visit Hayoo! here: http://holumbus.fh-wedel.de/hayoo
 
 The major change is the inclusion of all packages available on Hackage,
 i.e. the documentation of the latest versions of all packages is included
 in the index.
 
 Unfortunately we had to drop the direct links to the source code, as the
 documentation on Hackage is currently generated without source code. But
 as soon as this changes, we will include these links again.
 
 Additionally, we added some tweaks to the interface which make the browser
 history/the back button work (at least in Firefox).
 
 Please bear in mind that this is still a beta release and we are
 continuously working on further improvements.
 
 Any suggestions and feedback is highly welcomed.

Well, it is currently not in a usable state: the page randomly inserts funny
characters into the text input field. (I'm using Konqueror)

Cheers
Ben

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


Re: Re[2]: [Haskell-cafe] Cabal files on Windows

2008-07-27 Thread Duncan Coutts

On Mon, 2008-07-28 at 00:27 +0400, Bulat Ziganshin wrote:
 Hello Henk-Jan,
 
 Sunday, July 27, 2008, 11:36:32 PM, you wrote:
 
  Can anyone point me to a method for including path names with spaces
  in a cabal file?  I would like to add a line similar to the following:
  Have you tried replacing Program Files with PROGRA~1? This is the old
 
 i don't followed discussion but if this meant for distributable
 packages, the following problems exist:
 
 1. it may be progra~2 or ~3
 2. it's possible to entirely disable short names generation on ntfs

None of this is necessary. Paths with spaces are just fine if you use
the Haskell String syntax.

Duncan

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


Re: [Haskell-cafe] Cabal files on Windows

2008-07-27 Thread John Lato
On Sun, Jul 27, 2008 at 3:25 PM, Duncan Coutts
[EMAIL PROTECTED] wrote:

 On Sat, 2008-07-26 at 20:23 -0500, John Lato wrote:
 Hello,

 Can anyone point me to a method for including path names with spaces
 in a cabal file?  I would like to add a line similar to the following:
 include-dirs:  C:\Program Files\program\include
 and of course a corresponding library as well.

 Use Haskell String syntax for paths that contain spaces:

 include-dirs:  C:\\Program Files\\program\\include

Hi Duncan,

Thanks, this worked (mostly).  Although I had to change the line to

include-dirs: \C:\\Program Files\\program\\include\

so that the path would be passed properly to cpp through c2hs.

Is this documented anywhere?  I've been poring over the cabal guide
trying to find this, with no success.

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


[Haskell-cafe] Control.Concurrent.forkIO versus Control.Parallel.par

2008-07-27 Thread Mario Blažević

Hello. I have a question about parallel computation in Haskell. After 
browsing the GHC library documentation, I was left with impression that there 
are two separate mechanisms for expressing concurrency: Control.Parallel.par 
for pure computations and Control.Concurrent.forkIO for computations in IO 
monad.

This dichotomy becomes a problem when one tries to use concurrency from a 
monad transformer, though I'm sure that's not the only such situation. One 
cannot assume that the base monad is IO so forkIO cannot be used, while 
Control.Parallel.par won't run monads. My first solution was to replace the 
base monad class for the monad transformer by the following ParallelizableMonad 
class:


class Monad m = ParallelizableMonad m where
   parallelize :: m a - m b - m (a, b)
   parallelize ma mb = do a - ma
  b - mb
  return (a, b)

instance ParallelizableMonad Identity where
   parallelize (Identity a) (Identity b) = Identity (a `par` (b `pseq` (a, b)))

instance ParallelizableMonad IO where
   parallelize ma mb = do va - newEmptyMVar
  vb - newEmptyMVar
  forkIO (ma = putMVar va)
  forkIO (mb = putMVar vb)
  a - takeMVar va
  b - takeMVar vb
  return (a, b)


I tested this solution, and it worked for IO computations in the sense that 
they used both CPUs. The test also ran slower on two CPUs that on one, but 
that's beside the point.

Then I realized that par can, in fact, be used on any monad, it just needs a 
little nudge:


parallelize :: m a - m b - m (a, b)
parallelize ma mb = let a = ma = return
b = mb = return
in a `par` (b `pseq` liftM2 (,) a b)


However, in this version the IO monadic computations still appear to use only 
one CPU. I cannot get par to parallelize monadic computations. I've used the 
same command-line options in both examples: -O -threaded and +RTS -N2. What am 
I missing?


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


[Haskell-cafe] multicore programming ...

2008-07-27 Thread Galchin, Vasili
Hello,

   I have written quite a bit of multi-threaded code in ANSI C and C++
using mainly Posix threads and some using Win32 API threads.  IMO now seems
to be a huge opportunity for FPLs to shine .. In any case, now there seems
to be an emerging crisis in the computer industry in multithread scalability
over large multicore:
http://www.hackinthebox.org/modules.php?op=modloadname=Newsfile=articlesid=27292mode=threadorder=0thold=0.
This is kind of a wrag quote. Do others have more substantial URLs on
programming large multi-cores?

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


Re: [Haskell-cafe] Control.Concurrent.forkIO versus Control.Parallel.par

2008-07-27 Thread Sterling Clover
I think a better way to look at it is that Haskell has two separate  
mechanisms for different *notions* of concurrency -- forkIO for  
actual concurrent computation which needs explicit threads and  
communication (and within that, either semaphore-based communication  
with MVars or transactional control with TVars and STM), and par for  
parallelism which is to express computations that are innately  
parallel. See, e.g. the GHC users manual which defines them as such:


* Parallelism means running a Haskell program on multiple processors,  
with the goal of improving performance. Ideally, this should be done  
invisibly, and with no semantic changes.


* Concurrency means implementing a program by using multiple I/O- 
performing threads. While a concurrent Haskell program can run on a  
parallel machine, the primary goal of using concurrency is not to  
gain performance, but rather because that is the simplest and most  
direct way to write the program. Since the threads perform I/O, the  
semantics of the program is necessarily non-deterministic.


(http://www.haskell.org/ghc/docs/latest/html/users_guide/lang- 
parallel.html)


In any case, I suspect that your second parallelize function doesn't  
work right because \x - x = return is an effective no-op, modulo  
strictness characteristics of =. And in any case, it can't be  
evaluated until it is called in a particular monadic environment  
which is provided, sequencing and all, via liftM2. One can't  
parallelize in an arbitrary monad in any case, at least without  
making a number of decisions. E.g., what's the resultant state after  
two parallel computations are run in a state monad?


So if you're using concurrency with a monad transformer, you probably  
might want to start by stripping back the layers of the concurrent  
part of your algorithm to the minimum possible, and then explicitly  
managing passing state into the various forked computations, which  
can then be wrapped in as many runReaderT or such calls as necessary.


On another, general, note, unless you're very careful, mixing IO into  
your algorithm will probably result in very underperformant parallel  
code, since it will be IO rather than processor bound. Again the  
point from the GHC manual that the primary goal of using concurrency  
is not to gain performance, but rather because that is the simplest  
and most direct way to write the program seems appropriate.  
Additionally, many have found it easier at this stage to get good  
performance out of writing parallel code with concurrent mechanisms  
rather than `par`, because careless use of `par` will tend to add as  
much overhead in spark creation as is saved with multiprocessing,  
while an explicit work queue can be easier to reason about.


Regards,
S.

On Jul 27, 2008, at 10:49 PM, Mario Blažević wrote:



Hello. I have a question about parallel computation in Haskell.  
After browsing the GHC library documentation, I was left with  
impression that there are two separate mechanisms for expressing  
concurrency: Control.Parallel.par for pure computations and  
Control.Concurrent.forkIO for computations in IO monad.


This dichotomy becomes a problem when one tries to use  
concurrency from a monad transformer, though I'm sure that's not  
the only such situation. One cannot assume that the base monad is  
IO so forkIO cannot be used, while Control.Parallel.par won't run  
monads. My first solution was to replace the base monad class for  
the monad transformer by the following ParallelizableMonad class:


-- 
--

class Monad m = ParallelizableMonad m where
   parallelize :: m a - m b - m (a, b)
   parallelize ma mb = do a - ma
  b - mb
  return (a, b)

instance ParallelizableMonad Identity where
   parallelize (Identity a) (Identity b) = Identity (a `par` (b  
`pseq` (a, b)))


instance ParallelizableMonad IO where
   parallelize ma mb = do va - newEmptyMVar
  vb - newEmptyMVar
  forkIO (ma = putMVar va)
  forkIO (mb = putMVar vb)
  a - takeMVar va
  b - takeMVar vb
  return (a, b)
-- 
--


I tested this solution, and it worked for IO computations in the  
sense that they used both CPUs. The test also ran slower on two  
CPUs that on one, but that's beside the point.


Then I realized that par can, in fact, be used on any monad, it  
just needs a little nudge:


-- 
--

parallelize :: m a - m b - m (a, b)
parallelize ma mb = let a = ma = return
b = mb = return
in a `par` (b `pseq` liftM2 (,) a b)
-- 

Re: [Haskell-cafe] Control.Concurrent.forkIO versus Control.Parallel.par

2008-07-27 Thread Luke Palmer
On Mon, Jul 28, 2008 at 2:49 AM, Mario Blažević [EMAIL PROTECTED] wrote:
 parallelize :: m a - m b - m (a, b)
 parallelize ma mb = let a = ma = return
b = mb = return
in a `par` (b `pseq` liftM2 (,) a b)

See Sterling's reply for an actual answer to your question, but note
that one of the monad laws is:

   m = return = m

(i.e. return is a right identity of bind)

That means your code can be reduced to:

   parallelize ma mb = ma `par` (mb `pseq` liftM2 (,) ma mb)

Which, as Sterling points out, is *not* doing what you think it is.

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


Re: [Haskell-cafe] carry state around ....

2008-07-27 Thread Galchin, Vasili
Hi Duncan and Brandon,

 I am  moving to the ForeignPtr strategy. However, I always try to learn
from where I am before going to a new approach. I have discovered by
debugging that the AIOCB peek is working; however, passing the peeked
AIOCB back to the caller(i.e. the test program) is not working .. please let
me try to demonstrate below. I have been staring at my Haskell code many,
many times  sigh ...


0)


IN PEEK CODE .. aioErrorCode = 115
IN PEEK CODE .. aioReturnValue = 0
aioWrite after aio_write
IN PEEK CODE .. aioErrorCode = 115
IN PEEK CODE .. aioReturnValue = 0
*aiocb dump***
fd = 3
opcode = 1
prio = 0
offset = 0
nbytes = 20
next = 0x
absprio = 0
policy = 0
errocode = 115   correct ... INPROGRESS errno
return value = 0

return from call of Haskell function aioWrite here
... below errocode has changed from 115 to 0 ... somehow my return AIOCB
is corrupting the state/value of AIOCB 

*aioWrite dumpAIOCB
*aiocb dump***
fd = 3
opcode = 0
prio = 0
offset = 0
nbytes = 20
next = 0x
absprio = 0
policy = 0
errocode = 0  incorrect Errno ... should
still be IN PROGRESS.
return value = 0

1) aioWrite ... the function marshalling(poke) and unmarshalling(peek) an
AIOCB:


aioWrite :: AIOCB - IO AIOCB
aioWrite aiocb = do
   allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb - do
  poke p_aiocb aiocb

  putStrLn aioWrite before aio_write
  aiocb1 - peek p_aiocb
  dumpAIOCB aiocb1

  throwErrnoIfMinus1 aioWrite (c_aio_write  p_aiocb)
  aiocb - peek p_aiocb

  putStrLn aioWrite after aio_write
  aiocb - peek p_aiocb
  dumpAIOCB aiocb

--  putStrLn aioWrite after aio_write
--  aiocb1 - peek p_aiocb
--  dumpAIOCB aiocb1

  return (aiocb)

foreign import ccall safe aio.h aio_write
c_aio_write :: Ptr AIOCB - IO CInt


2) an AIOCB:

data LioOps = LioRead | LioWrite | LioNop


data AIOCB = AIOCB {

aioFd :: Fd,

aioLioOpcode :: Int,

aioReqPrio :: Int,

aioOffset :: FileOffset,

aioBuf :: Ptr Word8,

aioBytes :: ByteCount,

aioSigevent :: Sigevent,


-- Internal members

aioNext :: Ptr AIOCB,

aioAbsPrio :: Int,

aioPolicy :: Int,

aioErrorCode :: Int,

aioReturnValue :: ByteCount
}


3) poke/peek

instance Storable AIOCB where

sizeOf _ = (#const sizeof (struct aiocb))

alignment _ = 1

poke p_AIOCB (AIOCB aioFd aioLioOpcode aioReqPrio aioOffset aioBuf
aioBytes aioSigevent aioNext aioAbsPrio aioPolicy aioErrorCode
aioReturnValue) = do

   (#poke struct aiocb, aio_fildes) p_AIOCB aioFd

   (#poke struct aiocb, aio_lio_opcode) p_AIOCB aioLioOpcode

   (#poke struct aiocb, aio_reqprio) p_AIOCB aioReqPrio

   (#poke struct aiocb, aio_offset) p_AIOCB aioOffset

   (#poke struct aiocb, aio_buf) p_AIOCB aioBuf

   (#poke struct aiocb, aio_nbytes) p_AIOCB aioBytes

   (#poke struct aiocb, aio_sigevent) p_AIOCB aioSigevent

   (#poke struct aiocb, __next_prio) p_AIOCB aioNext

   (#poke struct aiocb, __abs_prio) p_AIOCB aioAbsPrio

   (#poke struct aiocb, __policy) p_AIOCB aioPolicy

   (#poke struct aiocb, __error_code) p_AIOCB aioErrorCode

   (#poke struct aiocb, __return_value) p_AIOCB aioReturnValue



peek p_AIOCB = do

   aioFd - (#peek struct aiocb, aio_fildes) p_AIOCB

   aioLioOpcode - (#peek struct aiocb, aio_lio_opcode) p_AIOCB

   aioReqPrio - (#peek struct aiocb, aio_reqprio) p_AIOCB

   aioOffset - (#peek struct aiocb, aio_offset) p_AIOCB

   aioBuf - (#peek struct aiocb, aio_buf) p_AIOCB

   aioBytes - (#peek struct aiocb, aio_nbytes) p_AIOCB

   aioSigevent - (#peek struct aiocb, aio_sigevent) p_AIOCB

   aioNext - (#peek struct aiocb, __next_prio) p_AIOCB

   aioAbsPrio - (#peek struct aiocb, __abs_prio) p_AIOCB

   aioPolicy - (#peek struct aiocb, __policy) p_AIOCB

   aioErrorCode - (#peek struct aiocb, __error_code) p_AIOCB
   putStrLn (IN PEEK CODE .. aioErrorCode =  ++ (show aioErrorCode))

   aioReturnValue - (#peek struct aiocb, __return_value) p_AIOCB
   putStrLn (IN PEEK CODE .. aioReturnValue =  ++ (show
aioReturnValue))

   return (AIOCB aioFd aioLioOpcode aioReqPrio aioOffset aioBuf aioBytes
aioSigevent aioNext aioAbsPrio aioPolicy aioErrorCode aioReturnValue)

Kind regards, Vasili






On Sun, Jul 20, 2008 at 6:51 AM, Duncan Coutts
[EMAIL PROTECTED]wrote:


 On Sat, 2008-07-19 at 23:55 -0500, Galchin, Vasili wrote:
  yes Duncan I am trying to pass-by-value. I am familiar with
  ForeignPtr; however, I don't comprehend what you and Brandon are
  suggesting to do. Could either of you provide a code illustration or
  point at existing code to illustrate your approach?

 Take a look at John Meacham's RSA example.

 So at the moment you're using using Storable and a Haskell record, say:

 data