Re: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Ryan Ingram
Thanks to everyone, especially Bulat Ziganshin. In http://haskell.org/haskellwiki/Modern_array_libraries there is enough information to do what I want. It specifically mentions that it's OK to pass ByteArray# and MutableByteArray# to an unsafe foreign procedure as long as that procedure doesn't

Re: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Stefan O'Rear
On Mon, Aug 20, 2007 at 11:03:45PM -0700, Ryan Ingram wrote: Thanks to everyone, especially Bulat Ziganshin. In http://haskell.org/haskellwiki/Modern_array_libraries there is enough information to do what I want. It specifically mentions that it's OK to pass ByteArray# and

Re: [Haskell-cafe] Dynamic thread management?

2007-08-21 Thread Hugh Perkins
On 8/11/07, Neil Bartlett [EMAIL PROTECTED] wrote: You're absolutely right that a dynamic/adaptive approach is the only one that will work when the tasks are of unknown size. Whether this approach is as easy as you think is open for you to prove. I look forward to testing your VM

Re: [Haskell-cafe] Dynamic thread management?

2007-08-21 Thread Tim Chevalier
On 8/21/07, Hugh Perkins [EMAIL PROTECTED] wrote: On 8/11/07, Neil Bartlett [EMAIL PROTECTED] wrote: You're absolutely right that a dynamic/adaptive approach is the only one that will work when the tasks are of unknown size. Whether this approach is as easy as you think is open for you to

Re: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Donald Bruce Stewart
ryani.spam: Your code is broken in a most evil and insidious way. Interesting. This is for a toy project, so I'm not too worried, but lets say I wanted to do this correctly and I was set on using IOUArray for some reason. (The Haskell wiki claims that StorableArray is

Re: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Stefan O'Rear
On Mon, Aug 20, 2007 at 11:47:06PM -0700, Ryan Ingram wrote: Your code is broken in a most evil and insidious way. Interesting. This is for a toy project, so I'm not too worried, but lets say I wanted to do this correctly and I was set on using IOUArray for some reason. Heh, I'm a lot

Re[2]: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Bulat Ziganshin
Hello Stefan, Tuesday, August 21, 2007, 10:08:59 AM, you wrote: Your code is broken in a most evil and insidious way. and this code, too? :) freezeSTUArray :: Ix i = STUArray s i e - ST s (UArray i e) freezeSTUArray (STUArray l u marr#) = ST $ \s1# - case sizeofMutableByteArray# marr# of

Re: Re[2]: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Ryan Ingram
Ah, sneaky. That code is fine because it uses unsafeCoerce# on memcpy, changing memcpy from whatever type it is, into MutableByteArray# s# - MutableByteArray# s# - Int# - s# - (# s#, () #) So as long as the GC understands MutableByteArray# it's safe; it's relying on the C calling convention

Re: [Haskell-cafe] Tying the knot with unknown keys

2007-08-21 Thread ajb
G'day all. Quoting David Ritchie MacIver [EMAIL PROTECTED]: I was playing with some code for compiling regular expressions to finite state machines and I ran into the following problem. I've solved it, but I'm not terribly happy with my solution and was wondering if someone could come up with

Re: Re[2]: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Stefan O'Rear
On Tue, Aug 21, 2007 at 12:50:22AM -0700, Ryan Ingram wrote: Ah, sneaky. That code is fine because it uses unsafeCoerce# on memcpy, changing memcpy from whatever type it is, into MutableByteArray# s# - MutableByteArray# s# - Int# - s# - (# s#, () #) So as long as the GC understands

Re[2]: [Haskell-cafe] How can I pass IOUArrays to FFI functions?

2007-08-21 Thread Bulat Ziganshin
Hello Ryan, Tuesday, August 21, 2007, 10:47:06 AM, you wrote: Your code is broken in a most evil and insidious way.   Interesting.  This is for a toy project, so I'm not too worried, but lets say I wanted to do this correctly and I was set on using IOUArray for some reason. (The Haskell

Re: [Haskell-cafe] can't build haxml under ghc 6.7, says HughesPJ is hidden... but ghc-pkg doesn't say it's hidden...

2007-08-21 Thread Malcolm Wallace
I wrote: Just for information, the HaXml darcs repo has recently adopted the solution of containing two .cabal files, one for ghc-6.6.x, and the other for the split-base packages (=ghc-6.7). Thomas Hartman [EMAIL PROTECTED] wrote: $ runghc Setup.hs configure Setup.hs: Multiple description

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Philip Armstrong
On Mon, Aug 20, 2007 at 09:57:38PM +0100, Simon Peyton-Jones wrote: GHC does some constant folding, but little by way of strength reduction, or using shifts instead of multiplication. It's pretty easy to add more: it's all done in a single module. Look at primOpRules in the module PrelRules.

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Donald Bruce Stewart
phil: On Mon, Aug 20, 2007 at 09:57:38PM +0100, Simon Peyton-Jones wrote: GHC does some constant folding, but little by way of strength reduction, or using shifts instead of multiplication. It's pretty easy to add more: it's all done in a single module. Look at primOpRules in the module

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Rodrigo Queiro
On my system, the C version runs about 9x faster than the haskell version (with -O3 and -O2 -fvia-c -optc-O3 respectively). However, GCC seems to produce about 70 lines of assembly for the main loop, compared to about 10 from GHC. I suspect the speed difference is the result of some heavy

[Haskell-cafe] Re: Tying the knot with unknown keys

2007-08-21 Thread ChrisK
David Ritchie MacIver wrote: I was playing with some code for compiling regular expressions to finite state machines and I ran into the following problem. I've solved it, but I'm not terribly happy with my solution and was wondering if someone could come up with a better one. :-)

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Stefan O'Rear
On Tue, Aug 21, 2007 at 01:14:20PM +0100, Rodrigo Queiro wrote: On my system, the C version runs about 9x faster than the haskell version (with -O3 and -O2 -fvia-c -optc-O3 respectively). However, GCC seems to produce about 70 lines of assembly for the main loop, compared to about 10 from GHC.

Re: [Haskell-cafe] Dynamic thread management?

2007-08-21 Thread Hugh Perkins
On 8/21/07, Tim Chevalier [EMAIL PROTECTED] wrote: I don't think you have to worry too much about the political obstacles. People want automatic multithreading, and in a year or two we'll all have multicore boxen. In any case, if you don't solve the technical problems, the political ones will

Re: [Haskell-cafe] Re: Bi-directional Maps

2007-08-21 Thread Hugh Perkins
Exactly. For this to work there needs to be the constraint that there's a one-to-one mapping in each direction. The Bimap should have the uniqueness promise that Set (k, v) gives. Yet you should be able to search on either tuple value. Or... have the possibility of returning a list of values.

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Philip Armstrong
On Tue, Aug 21, 2007 at 05:25:49AM -0700, Stefan O'Rear wrote: On Tue, Aug 21, 2007 at 01:14:20PM +0100, Rodrigo Queiro wrote: On my system, the C version runs about 9x faster than the haskell version (with -O3 and -O2 -fvia-c -optc-O3 respectively). However, GCC seems to produce about 70 lines

[Haskell-cafe] Re: I'm stuck in my thought experiment

2007-08-21 Thread Al Falloon
Levi Stephen wrote: Al Falloon wrote: This code seems to indicate that you want to be able to extend the widget types without changing this source file. This is a good goal, but it may not be worth the extra complexity. Ideally, I'd like Widgets to be added through hs-plugins or similar.

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Philip Armstrong
Don's reply didn't reach me for some reason, but pulling it out of the previous response: On 21/08/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote: phil: The generated assembler suggests (if I've read it correctly) that gcc is spotting that it can replace the tail call with a jump in the C

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Hugh Perkins
On 8/21/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Currently, it's never worse. GHC's backend is about as good as GCC; most of the optimiations it doesn't do are not possible for GCC because of various lack-of-information problems (the stack pointer never aliases the heap pointer, stuff like

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Neil Mitchell
Hi Wait, you're saying that ghc can produce pure c-code, that doesnt contain any assembly code, and that runs as fast as ghc code that does contain assembly? No. It can produce pure C code (unregistered), but to get high performance it processes the output assembly afterwards (registered).

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Stefan O'Rear
On Tue, Aug 21, 2007 at 09:39:32PM +0800, Hugh Perkins wrote: On 8/21/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Currently, it's never worse. GHC's backend is about as good as GCC; most of the optimiations it doesn't do are not possible for GCC because of various lack-of-information

[Haskell-cafe] Re: Bi-directional Maps

2007-08-21 Thread apfelmus
Hugh Perkins wrote: Exactly. For this to work there needs to be the constraint that there's a one-to-one mapping in each direction. The Bimap should have the uniqueness promise that Set (k, v) gives. Yet you should be able to search on either tuple value. Or... have the possibility of

[Haskell-cafe] ANN: SF Bay Area Functional Programmers Group

2007-08-21 Thread Keith Fahlgren
Hi All, I'd like to announce the formation of the Bay Area Functional Programmers group. This group is for anyone using or interested in functional programming and functional programming languages, particularly strongly typed languages such as Haskell, OCaml, SML, etc. The first meeting will be

[Haskell-cafe] Generic data constructor in pattern?

2007-08-21 Thread Peter Verswyvelen
Consider the following example code: data Vector = V Float Float data Matrix = M Vector Vector liftV1 f (V x y) = V (f x) (f y) liftV2 f (V x1 y1) (V x2 y2) = V (f x1 x2) (f y1 y2) liftM1 f (M x y) = M (f x) (f y) liftM2 f (M x1 y1) (M x2 y2) = M (f

Re: [Haskell-cafe] Generic data constructor in pattern?

2007-08-21 Thread Neil Mitchell
Hi Peter, liftV1 f (V x y) = V (f x) (f y) liftV2 f (V x1 y1) (V x2 y2) = V (f x1 x2) (f y1 y2) liftM1 f (M x y) = M (f x) (f y) liftM2 f (M x1 y1) (M x2 y2) = M (f x1 x2) (f y1 y2) Both pairs of lift functions have almost identical implementations. Can I

Re: [Haskell-cafe] Generic data constructor in pattern?

2007-08-21 Thread Henning Thielemann
On Tue, 21 Aug 2007, Peter Verswyvelen wrote: Consider the following example code: data Vector = V Float Float data Matrix = M Vector Vector liftV1 f (V x y) = V (f x) (f y) liftV2 f (V x1 y1) (V x2 y2) = V (f x1 x2) (f y1 y2) liftM1 f (M x y) = M (f x) (f

[Haskell-cafe] Yet another stupid question about numeric conversion

2007-08-21 Thread Peter Verswyvelen
Does a general approach exist to convert any non-constant (Num a) to a Float? Not using type annotation of course. Now I wrote a Convert class that has a toFloat function which I instantiate for all different numeric types, but as all these toFloat/toInt functions disappeared a long time ago from

Re: [Haskell-cafe] Yet another stupid question about numeric conversion

2007-08-21 Thread Lennart Augustsson
How can you hope to convert an arbitrary Num to a Float? Num contains things like complex numbers that don't have any reasonable translation to a Float. But anyway, realToFrac is a good conversion function. -- Lennart On 8/21/07, Peter Verswyvelen [EMAIL PROTECTED] wrote: Does a general

Re: [Haskell-cafe] Newbie question: Where is StackOverflow on the Wiki?

2007-08-21 Thread Andrew Coppin
Stefan O'Rear wrote: sum = sum' 0 sum' k [] = k sum' k (x:xs) = (sum' $! (k+x)) xs enum x y | x = y= 0 | otherwise = x : enum (x+1) y sum (enum 1 10) = sum' 0 (enum 1 10) = sum' 0 (1 : enum (1+1) 10) = (sum' $! (0+1)) (enum (1+1) 10) = sum' 1

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Andrew Coppin
Simon Peyton-Jones wrote: GHC does some constant folding, but little by way of strength reduction, or using shifts instead of multiplication. It's pretty easy to add more: it's all done in a single module. Look at primOpRules in the module PrelRules. Patches welcome! But please also supply

Re: [Haskell-cafe] #haskell irc channel reaches 400 users

2007-08-21 Thread Andrew Coppin
Donald Bruce Stewart wrote: This puts the channel at around the 13th largest community of the 5500 freenode channels. For comparision, a sample of the state of the other language communities: #php 485 #perl472 ##c++457 ##c 445 #python

Re: [Haskell-cafe] Dynamic thread management?

2007-08-21 Thread Andrew Coppin
Tim Chevalier wrote: Anyone can submit a paper to a CS journal or conference. While most people who do so are affiliated with universities, research labs, or (more rarely) non-research companies, there are independent researchers out there, and sometimes you'll notice a paper where someone is

RE: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Simon Peyton-Jones
| GHC does some constant folding, but little by way of strength | reduction, or using shifts instead of multiplication. It's pretty easy | to add more: it's all done in a single module. Look at primOpRules in | the module PrelRules. | | Patches welcome! But please also supply test-suite

[Haskell-cafe] Re: Newbie question: Where is StackOverflow on the Wiki?

2007-08-21 Thread apfelmus
Stefan O'Rear wrote: sum (enum 1 10) = sum' 0 (enum 1 10) = ... sum' 36 (9 : enum (9+1) 10) = (sum' $! (36+9)) (enum (9+1) 10) = sum' 45 (enum (9+1) 10) = sum' 45 [] = 45 (I need to find some way to automate making these trails

Re: [Haskell-cafe] Yet another stupid question about numeric conversion

2007-08-21 Thread Henk-Jan van Tuyl
On Tue, 21 Aug 2007 18:53:43 +0200, Peter Verswyvelen [EMAIL PROTECTED] wrote: Does a general approach exist to convert any non-constant (Num a) to a Float? Not using type annotation of course. Instances of class Integral (Int and Integer) can be converted with fromIntegral. -- Met

RE: [Haskell-cafe] Yet another stupid question about numeric conversion

2007-08-21 Thread Peter Verswyvelen
Yes indeed, I realized that. I oversimplified my question. I'm basically trying to model 4D CG/HLSL operations (pixel/vertex shaders) in Haskell. I tried realToFrac, but that did not work. Then I tried splitting the instances into Fractional and Integral, but I kept getting errors. Maybe because

Re: [Haskell-cafe] Re: Newbie question: Where is StackOverflow on the Wiki?

2007-08-21 Thread Neil Mitchell
Hi sum (enum 1 10) = sum' 0 (enum 1 10) = ... sum' 36 (9 : enum (9+1) 10) = (sum' $! (36+9)) (enum (9+1) 10) = sum' 45 (enum (9+1) 10) = sum' 45 [] = 45 (I need to find some way to automate making these trails

Re: [Haskell-cafe] Re: Newbie question: Where is StackOverflow on the Wiki?

2007-08-21 Thread Andrew Coppin
Neil Mitchell wrote: Hi (I need to find some way to automate making these trails :) ) Yes! We'd need such an automatic tool for the wikibook, too. The problem is that Haskell is ridiculously complex, and the small step interpretation is much harder than you'd think. For

Re: [Haskell-cafe] Re: Bi-directional Maps

2007-08-21 Thread Albert Y. C. Lai
apfelmus wrote: Hugh Perkins wrote: Arguably there are two possible implementations, one that enforces one-to-one mapping, and one which allows multiple values, in either direction. Terminology reminder :) - the latter is called (binary) relation http://en.wikipedia.org/wiki/Binary_relation

Re: [Haskell-cafe] #haskell irc channel reaches 400 users

2007-08-21 Thread Albert Y. C. Lai
Andrew Coppin wrote: ...does this mean Haskell is officially harder to understand than Lisp, Java, Perl and O'Caml? :-} (OTOH, does this mean Haskell is easier to understand than PHP or C++?) Or, Haskell is the easiest to understand of them all. Reason: Extremely large channel means so hard

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Isaac Dupree
Simon Peyton-Jones wrote: | GHC does some constant folding, but little by way of strength | reduction, or using shifts instead of multiplication. It's pretty easy | to add more: it's all done in a single module. Look at primOpRules in | the module PrelRules. | | Patches welcome! But please

[Haskell-cafe] Re: I'm stuck in my thought experiment

2007-08-21 Thread Levi Stephen
If I wanted to develop the widgets themselves separately from the layout, I would probably do something like this: class Widget a where render :: a - Html bbox :: a - Size type Layout = forall a. Widget a = Widget a | Rows Spacing [Layout] | Columns Spacing [Layout] |

Re: [Haskell-cafe] Parsing binary data.

2007-08-21 Thread Tony Finch
On Sun, 19 Aug 2007, Peter Cai wrote: My duty is writing a network server which talks to another server through a binary based private protocol. Haskell needs something like Erlang's bit syntax. http://erlang.org/doc/reference_manual/expressions.html#6.16

Re: [Haskell-cafe] Parsing binary data.

2007-08-21 Thread Donald Bruce Stewart
dot: On Sun, 19 Aug 2007, Peter Cai wrote: My duty is writing a network server which talks to another server through a binary based private protocol. Haskell needs something like Erlang's bit syntax. http://erlang.org/doc/reference_manual/expressions.html#6.16

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Twan van Laarhoven
Isaac Dupree wrote: Simon Peyton-Jones wrote: ... No, constant folding is part of the compiler, I'm afraid, in the module PrelRules. Simon _Constant_ folding is, but in GHC.Base there are rules like (unboxed) multiplying by zero or one, or adding or subtracting zero, from an unknown

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Brandon S. Allbery KF8NH
On Aug 21, 2007, at 22:13 , Twan van Laarhoven wrote: Other rules that could be interesting are: forall a b. fromInteger a + fromInteger b = fromInteger (a + b) I don't think this will work, a and b have to be the same type. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Twan van Laarhoven
Brandon S. Allbery KF8NH wrote: On Aug 21, 2007, at 22:13 , Twan van Laarhoven wrote: Other rules that could be interesting are: forall a b. fromInteger a + fromInteger b = fromInteger (a + b) I don't think this will work, a and b have to be the same type. They are of the same type,

Re: [Haskell-cafe] Dynamic thread management?

2007-08-21 Thread Hugh Perkins
On 8/21/07, Andrew Coppin [EMAIL PROTECTED] wrote: I highly doubt that automatic threading will happen any time this decade - but I just learned something worth while from reading this email. ;-) That's an interesting observation. I cant say I dont believe it, but I'm interested to know why

Re: [Haskell-cafe] GHC optimisations

2007-08-21 Thread Hugh Perkins
Thank-you for the information. It was very useful. Couple of reactions FWIW: On 8/21/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Sooo if I was feeling evil, could I take this c-code and pipe it into something that turns it into C#??? Yes. You could do the same with the original

Re: [Haskell-cafe] Re: Haskell vs GC'd imperative languages, threading, parallelizeability (is that a word? :-D )

2007-08-21 Thread Brandon S. Allbery KF8NH
On Aug 21, 2007, at 23:27 , Hugh Perkins wrote: Hmmm, that's interesting. I'd never considered lack of typing to be a good thing for system robustness before! The old watchphrase (before Netscape and Microsoft abused it beyond anyone's expectation) for Internet protocols was be liberal in