[Haskell-cafe] some newbie FFI questions

2004-07-01 Thread John Kozak
I'm trying to experiment with image processing in haskell (with which I haven't much experience). I've written some FFI code to talk to the ImageMagick library which provokes a few questions (environment is ghc 6.2.1 on debian): 1. Speed: I'm reading in a 2000x1500 pixel image, and have defined

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread Ketil Malde
John Kozak [EMAIL PROTECTED] writes: data Pixel a = Pixel !a !a !a deriving Show I use ImageMagick to load the image, then build an Array of Pixel Floats. Building the array takes 45 seconds on a 2.5Ghz P4 with code compiled -O2, which seems slow to me - are my expectations

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread MR K P SCHUPKE
If you are using GHC the fastest way I know to do this is to build the array using a mutable-unboxed array in the state-monad. Then freeze the array and return an unboxed immutable array. This is a lot faster than building the array by copying (every time you set a value in an immutable array the

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread MR K P SCHUPKE
Oh... also when using unboxed arrays you may well have to have a separate array for each colour plane (r,g,b,a) as I think unboxed arrays can only contain primitive types - although I am not certain about this - it may be enough to have the contents strict. Keean.

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread Duncan Coutts
On Thu, 2004-07-01 at 12:34, MR K P SCHUPKE wrote: Oh... also when using unboxed arrays you may well have to have a separate array for each colour plane (r,g,b,a) as I think unboxed arrays can only contain primitive types - although I am not certain about this - it may be enough to have the

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread MR K P SCHUPKE
Yes, deriving unboxable would be nice... I think for images though it is not too much of a problem to work with a record of arrays rather that an array of records. Keean. ___ Haskell-Cafe mailing list [EMAIL PROTECTED]

RE: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread Simon Marlow
On 01 July 2004 11:53, John Kozak wrote: I'm trying to experiment with image processing in haskell (with which I haven't much experience). I've written some FFI code to talk to the ImageMagick library which provokes a few questions (environment is ghc 6.2.1 on debian): 1. Speed: I'm

[Haskell-cafe] Newbie questions

2004-07-01 Thread Crypt Master
Hi I consider myself a pretty good imperative programmer, been at it for decades, and am tryibng my hand at Haskell now. Unfrituantly I am not getting it all that quickly despite having the multimedia haskell book. To start ghetting some hands on, I thought iI owuld do something which i have

[Haskell-cafe] Newbie questions

2004-07-01 Thread Crypt Master
Hi I consider myself a pretty good imperative programmer, been at it for decades, and am tryibng my hand at Haskell now. Unfrituantly I am not getting it all that quickly despite having the multimedia haskell book. To start ghetting some hands on, I thought iI owuld do something which i have

Re: [Haskell-cafe] Newbie questions

2004-07-01 Thread Duncan Coutts
On Thu, 2004-07-01 at 17:01, Crypt Master wrote: I consider myself a pretty good imperative programmer, been at it for decades, and am tryibng my hand at Haskell now. Unfrituantly I am not getting it all that quickly despite having the multimedia haskell book. [snip] The take operator

[Haskell-cafe] Re: Newbie questions

2004-07-01 Thread Ferenc Wagner
Crypt Master [EMAIL PROTECTED] writes: -- gaSolutionSpace :: [a] - [a] gaSolutionSpace x = x : gaSolutionSpace (evolvepopulation x) Stop deceiving yourself until it's too late. :) Why did you comment out the type annotation? -- Feri. ___

[Haskell-cafe] My old chess player

2004-07-01 Thread paolo veronelli
Ok Crypt Master give the hint to pronounce something ,because I feel a complete stupid in front of Functional Programming' though I'm a trained imperative one. I've read the nice paper www.cs.chalmers.se/~rjmh/Papers/whyfp.html and remember may years ago the hard job done to make my chess

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread Alastair Reid
1. Speed: I'm reading in a 2000x1500 pixel image, and have defined a Pixel type like this: data Pixel a = Pixel !a !a !a deriving Show [with a==Float being a typical instantiation] For images of this size, I'd recommend using a different datatype because: 1) Each Pixel Float will take

Re: [Haskell-cafe] some newbie FFI questions

2004-07-01 Thread John Kozak
Alastair Reid writes: [...] Overall, I'd probably use an unboxed Haskell array. This would let you get a memory layout (and memory consumption) close to the normal C layout. I'd use access functions to hide the boxing/unboxing and I'd write some map/fold/scan-like functions to