Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Keean Schupke
What about using a StablePtr? If you're dealing with hardware you would get the end-of-sample interrupt to free the buffer... Either way you either have to delay GC until the sample playback has finished... (well technically until the soundcard DMA has transferred the sample to the soundcards on

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Sebastian Sylvan
On Thu, 16 Dec 2004 08:46:58 +, Ben Rudiak-Gould <[EMAIL PROTECTED]> wrote: > Sebastian Sylvan wrote: > > >If there was a way to simply defer GC (like you attatch a function to > >an object which can simply deny the GC the right to remove it > >depending on its state) then I wouldn't have t

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Sebastian Sylvan
On Thu, 16 Dec 2004 09:46:34 +, Keean Schupke <[EMAIL PROTECTED]> wrote: > What about using a StablePtr? If you're dealing with hardware you would > get the > end-of-sample interrupt to free the buffer... Either way you either have > to delay GC > until the sample playback has finished... (well

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Jules Bean
On 16 Dec 2004, at 06:57, Sebastian Sylvan wrote: Here's the problem though. If the SamplePlaybackRaw is currently playing sound when it gets garbage collected, I want to keep the sound resource (SoundSample) alive until the playback has finished. I probably haven't understood the details correctly

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Keean Schupke
Okay, you want to poll to see if the sound is still playing... This is not very easy to do... You really want to use the low-buffer callback from the soundcard driver to load the next sample into the buffer using DMA. (IE you can pass a function to the driver to call when you sample has been copi

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Udo Stenzel
Robert Dockins <[EMAIL PROTECTED]> schrieb am 16.12.04 14:56:49: > This is exactly the guarantee you _don't_ have. The only guarantee you > have is that it _won't_ be run if the Ptr _is_ being referenced. >From the GHC library documentation: newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Robert Dockins
1) Finalizers are not (some say cannot) be guaranteed to run, even on normal program termination, even if you force GC before exiting. I only need a guarantee that it will be run if the Ptr is no longer being referenced. This is exactly the guarantee you _don't_ have. The only guarantee you hav

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Robert Dockins
This is exactly the guarantee you _don't_ have. The only guarantee you have is that it _won't_ be run if the Ptr _is_ being referenced. From the GHC library documentation: newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a) [...] The only guarantee is that the finaliser runs

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Keean Schupke
Udo Stenzel wrote: Robert Dockins <[EMAIL PROTECTED]> schrieb am 16.12.04 14:56:49: This is exactly the guarantee you _don't_ have. The only guarantee you have is that it _won't_ be run if the Ptr _is_ being referenced. From the GHC library documentation: newForeignPtr :: FinalizerPtr

[Haskell-cafe] Re: Haskell problem please help

2004-12-16 Thread Christian Maeder
N.B. if you want a faster answer such questions are best posted to [EMAIL PROTECTED] My answer: I asume that your function all_rotations somehow needs to be called recursively for the rest of the input list xs. Cheers Christian imranazad wrote: Hi, im not very good with haskell, i barely know t

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Robert Dockins
-- play a sample samplePlay :: SoundSample -> IO SamplePlayback samplePlay sample = do ch <- withForeignPtr sample (fsound_PlaySound (-1)) let spb = SP ch sample -- SamplePlaybackRaw mkWeakPtr spb (Just (samplePlaybackFinalizer spb)) From the System.Me

[Haskell-cafe] Determining all rotations (Was: Haskell problem please help)

2004-12-16 Thread Henning Thielemann
> imranazad wrote: > > Hi, > > > > im not very good with haskell, i barely know the basics, my coursework > > requires me to genereate a vigenere square... > > well anyway at the moment im trying to define a functin all_rotations > > which for any list returns the list of all its rotations, s

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Robert Dockins
Sebastian Sylvan wrote: On Thu, 16 Dec 2004 08:56:15 -0500, Robert Dockins <[EMAIL PROTECTED]> wrote: Return the high level value to the user; when the enclosed ForeignPtr is garbage collected deRefWeak on the weak pointer will return Nothing. Then the clean-up thread can begin polling the song o

Re: [Haskell-cafe] Determining all rotations (Was: Haskell problem please help)

2004-12-16 Thread Jon Fairbairn
On 2004-12-16 at 17:00+0100 Henning Thielemann wrote: > > > imranazad wrote: > > > Hi, > > > > > > im not very good with haskell, i barely know the > > > basics, my coursework requires me to genereate a > > > vigenere square... well anyway at the moment im > > > trying to define a functin al

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Keean Schupke
In which case I would assume the whole sample is copied to the sound cards buffer before the play call returns, so you don't have to worry and just let it be garbage collected. Keean Sebastian Sylvan wrote: On Thu, 16 Dec 2004 12:35:55 +, Keean Schupke <[EMAIL PROTECTED]> wrote: Okay,

[Haskell-cafe] Seeking comments on this IO proposal

2004-12-16 Thread John Goerzen
Hello, One of my favorite features from Python is its notion of "file-like objects". For those of you unfamiliar with Python, here's a quick backgrounder: anything can present a file-like interface. It could be a file, socket, an interface to a gzip/gunzip processor, character set codecs, in-me

[Haskell-cafe] Question regarding theis mailing list and Google Groups

2004-12-16 Thread Arjun Guha
Does anybody out there use Google Groups Beta to post to the `fa.haskell' group? I am directly subscribed to the email list, however I was trying some new things and it seemed like `fa.haskell' was vaguely related to the Haskell Café list. However, my post has not shown up on Haskell Café. D

Re: [Haskell-cafe] Seeking comments on this IO proposal

2004-12-16 Thread Ben Rudiak-Gould
John Goerzen wrote: >My proposal is here: > > http://www.complete.org/~jgoerzen/t/MissingH.IO.HVIO.html > >I'm aware that others have been working on IO proposals; specifically, >Simon Marlow's here: > > http://www.haskell.org/~simonmar/io/System.IO.html The proposal on Simon M's page was origina

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Ben Rudiak-Gould
Sebastian Sylvan wrote: >If there was a way to simply defer GC (like you attatch a function to >an object which can simply deny the GC the right to remove it >depending on its state) then I wouldn't have to do anything >significant in the finalizer. Why not spawn a thread which starts the playback,

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Ben Rudiak-Gould
Sebastian Sylvan wrote: >Ben Rudiak-Gould wrote: >>Why not spawn a thread which starts the playback, waits for it to >>finish, and then exits, and wrap the whole thread in a call to >>withForeignPtr? Then your finalizer won't be called prematurely. > >Well I could do this, but for one it would be c

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Sebastian Sylvan
On Thu, 16 Dec 2004 12:38:26 +, Jules Bean <[EMAIL PROTECTED]> wrote: > > On 16 Dec 2004, at 06:57, Sebastian Sylvan wrote: > > > Here's the problem though. If the SamplePlaybackRaw is currently > > playing sound when it gets garbage collected, I want to keep the sound > > resource (SoundSamp

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Sebastian Sylvan
On Thu, 16 Dec 2004 12:35:55 +, Keean Schupke <[EMAIL PROTECTED]> wrote: > Okay, you want to poll to see if the sound is still playing... This is > not very > easy to do... > > You really want to use the low-buffer callback from the soundcard > driver to load the next sample into the buffer us

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Jules Bean
On 16 Dec 2004, at 15:20, Sebastian Sylvan wrote: I really don't want to poll the sound sample all the time since it uses up resources needlessly. If it comes to that, though, it's pretty much guaranteed that it will get the job done. A thread which polls once per second (and sleeps otherwise) is a

Re: [Haskell-cafe] FFI woes!

2004-12-16 Thread Sebastian Sylvan
On Thu, 16 Dec 2004 08:56:15 -0500, Robert Dockins <[EMAIL PROTECTED]> wrote: > Return the high level value to the user; when the enclosed > ForeignPtr is garbage collected deRefWeak on the weak pointer will > return Nothing. Then the clean-up thread can begin polling the song > object to see if

[Haskell-cafe] Re: Haskell problem please help

2004-12-16 Thread M . I . Azad1
imranazad wrote: > > Hi, > > > > im not very good with haskell, i barely know the basics, my coursework > > requires me to genereate a vigenere square... > > well anyway at the moment im trying to define a functin all_rotations > > which for any list returns the list of all its rotations, so fa