Re: [Haskell-cafe] GHC Error: FATAL:Symbol _XJv_srt already defined.

2008-07-21 Thread Austin Seipp
I can replicate this err with 6.8.3 on my macbook (os 10.5.4.) It also
appears to fail with a copy of the GHC HEAD as well:

$ uname -a
Darwin existential.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun  9
19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.3
$ ~/ghc-head/bin/ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.9.20080615
$ ghc --make DerivingError.hs
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )

/var/folders/27/27CWjmd8HK8wG5FT3nu3pk+++TI/-Tmp-//ghc39082_0/ghc39082_0.s:6080:0:
FATAL:Symbol _XxH_srt already defined.
$ rm DerivingError.hi
$ ~/ghc-head/bin/ghc --make DerivingError.hs
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )

/var/folders/27/27CWjmd8HK8wG5FT3nu3pk+++TI/-Tmp-/ghc39116_0/ghc39116_0.s:6207:0:
FATAL:Symbol _XyQ_srt already defined.
$

However, things get even wackier because I *can* get it to build on
the HEAD, only through a very odd compilation step (I figured this out
while trying to examine the ASM output from the -S flag):

$ ~/ghc-head/bin/ghc --version   
The Glorious Glasgow Haskell Compilation System, version 6.9.20080615
$  ~/ghc-head/bin/ghc --make DerivingError.hs 
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )

/var/folders/27/27CWjmd8HK8wG5FT3nu3pk+++TI/-Tmp-/ghc44257_0/ghc44257_0.s:6207:0:
FATAL:Symbol _XyP_srt already defined.
$ rm DerivingError.hi  
$ ~/ghc-head/bin/ghc -S DerivingError.hs 
$ ~/ghc-head/bin/ghc --make DerivingError.hs
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )
$ 

Although in 6.8.3 it doesn't work regardless; but if we make it build
the object file through this odd step, we can then link it with a main
stub:

$ cat  main.hs 
main = putStrLn hello world
$ ~/ghc-head/bin/ghc --make main.hs DerivingError.o
[1 of 1] Compiling Main ( main.hs, main.o )
Linking main ...
$ 

In particular the issue appears to be related to generics (duh,) since
if we search through the .s file generated when using -S, we can see
what it's referring to (6.8.3):

.align 2
_Xxn_srt:  ;; line 5757
.long   _base_DataziGenericsziBasics_mkDataType_closure
.long   _s1Zg_closure
.long   _s1Zi_closure
.const_data
.align 2
_Xw9_srt:
.long   _Xxn_closure
...

_Xxn_srt: ;; line 6080
.long   _base_DataziGenericsziBasics_mkDataType_closure
.long   _s1Zs_closure
.long   _s1Zu_closure
.data
.align 2
...

So it seems like a bug in the native code generator for generics.

The ghc-6.9 version was actually a snapshot of the head a few weeks
back as you can see, I'm building the latest HEAD from darcs as we speak,
but in the mean time I would file a bug report with the code attached:

http://hackage.haskell.org/trac/ghc/newticket?type=bug

If you do, I'll be sure to post what I've done here so the devs might
be able to track it easier. If the latest HEAD turns out to work I'll
get back to you as well.

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


Re: [Haskell-cafe] Haskell code contributions

2008-07-21 Thread Austin Seipp
From the looks of the User Accounts page on hackage, Ross Patterson
seems to be responsible, you can contact him here:

[EMAIL PROTECTED]

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


Re: [Haskell-cafe] GHC Error: FATAL:Symbol _XJv_srt already defined.

2008-07-21 Thread Austin Seipp
Status update: after checking out the latest HEAD and building it, the
above error does not occur:

$ ~/ghc-head/bin/ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.9.20080720
$ ~/ghc-head/bin/ghc --make DerivingError.hs 

no location info:
Warning: -fallow-overlapping-instances is deprecated: Use the
OverlappingInstances language instead
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )
$ 

However, this doesn't exactly help your immediate problem, and it
likely won't until 6.10.1 is released, as 6.8.3 is going to be the
last release of the 6.8 branch.

Truly sorry I couldn't have helped you more.

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


Re: [Haskell-cafe] Re: Profiling nested case

2008-07-21 Thread Ryan Ingram
I had similar experiences as you when attempting to write high
performance Haskell; the language makes you want to use high-level
abstracted functions but the optimizer (while amazing, to be honest)
seems to miss a few cases that it seems like it should hit.

The problem seems to be that the compiler is extremely good at
optimizing systems-level code, but that any control-structure
function needs to be extremely inlined to be successful.  You might
try re-writing sequence or foldM a few different ways using the
same test function and see what you can get.

One thing that I notice about this code is that if you switch Right
and Left you will get the default behavior for the Either monad:

worldSceneSwitch point = case redSphere (0,50,0) 50 point of
   v@(Left _) - v
   Right d1 - case greenSphere (25,-250,0) 50 point of
 v@(Left _) - v
 Right d2 - Right $ d1 `min` d2

is the same as

worldSceneSwitch point = do
d1 - redSphere (0, 50, 0) 50 point
d2 - greenSphere (25, -250, 0) 50 point
Right (d1 `min` d2)

Here is the same concept using foldM:

minimumM (x : xs) = do
v0 - x
foldM (return . min) v0 xs

worldSceneSwitch point = minimumM [
redSphere (0, 50, 0) 50 point,
greenSphere (25, -250, 0) 50 point
  ]

However, the performance here will be terrible if minimumM and foldM
do not get sufficiently inlined; you do not want to be allocating list
thunks just to execute them shortly thereafter.

  -- ryan

On Sat, Jul 19, 2008 at 6:48 AM, Mitar [EMAIL PROTECTED] wrote:
 Hi!

 I had to change code somewhat. Now I have a function like:

 worldScene point = case redSphere (0,50,0) 50 point of
  v@(Right _) - v
  Left d1 - case greenSphere (25,-250,0) 50 point of
v@(Right _) - v
Left d2 - Left $ d1 `min` d2

 (Of course there could be more objects.)

 Any suggestion how could I make this less hard-coded? Something which
 would take a list of objects (object functions) and then return a
 Right if any object function return Right or a minimum value of all
 Lefts. But that it would have similar performance? If not on my GHC
 version (6.8.3) on something newer (which uses fusion or something).
 Is there some standard function for this or should I write my own
 recursive function to run over a list of object functions? But I am
 afraid that this will be hard to optimize for compiler.

 (It is important to notice that the order of executing object
 functions is not important so it could be a good candidate for
 parallelism.)


 Mitar
 ___
 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] Building NDP with latest GHC

2008-07-21 Thread Austin Seipp
Hi,

After my last issue with GHC's HEAD, I tried checking it out again and
getting the patches for the libraries and lo and behold, it worked. So
now I'm up to date with the latest libraries and the compiler, but it
appears that building NDP itself is proving to be troublesome.

(This is on GHC 6.9.20080720, btw)

I've pulled the latest ndp package from
http://darcs.haskell.org/packages/ndp into ./libraries.

Instructions that are listed in [1]:

 % cd libraries
 % darcs get http://darcs.haskell.org/packages/ndp/
 % make make.library.ndp
 % cd ndp/examples
 % make

This fails on step 3; the Makefile in the libraries subdirectory
doesn't recognize 'make.library.ndp' as a valid target.

Instructions in the actual README that comes with package ndp:

 cd ndp
 make boot
 make
 cd examples
 make

This fails on the 'make boot' step, because if you look at the
Makefile, it thinks the top of the GHC source tree is at '..', when
it's actually '../..' in relation to ./libraries/ndp:

 TOP=..
 include $(TOP)/mk/boilerplate.mk
 include ndp.mk
 ... rest of makefile ...

No big deal in this case, just a fix of changing TOP to '../..'
Having done that, however, now it fails because it it cannot correctly
parse bootstrapping.conf which is located in ./libraries:

 $ make boot
 ../../mk/target.mk:454: warning: overriding commands for target `libHSndp'
 ../../mk/package.mk:249: warning: ignoring old commands for target `libHSndp'
 ../../mk/target.mk:454: warning: overriding commands for target `ghc-prim.a'
 ../../mk/package.mk:249: warning: ignoring old commands for target 
 `ghc-prim.a'
 /Users/austinseipp/src/ghc-head/ghc/stage1-inplace/bin/ghc -M
 -optdep-f -optdep.depend  -osuf o -package-conf
 /Users/austinseipp/src/ghc-head/libraries/bootstrapping.conf-H32m
 -O -fasm -Rghc-timing -package-name ndp ghc-prim-0.1 -O -fgenerics
 -package base -XGenerics -fglasgow-exts -fbang-patterns -O2
 -funbox-strict-fields -fdicts-cheap -fno-method-sharing
 -fno-spec-constr-threshold -fmax-simplifier-iterations20 -threaded
 -XTypeFamilies -fcpr-off
 
 ... lots of files trying to get compiled here ...
 
 no location info:
 Warning: -fgenerics is deprecated: Use the Generics language
 instead
 
 no location info:
 Warning: -fbang-patterns is deprecated: Use the BangPatterns
 language instead
 ghc:
 /Users/austinseipp/src/ghc-head/libraries/bootstrapping.conf:1:62:
 parse error on input `'
 ghc: 41436660 bytes, 4 GCs, 118784/118784 avg/max bytes residency (1
 samples), 31M in use, 0.00 INIT (0.00 elapsed), 0.08 MUT (0.12
 elapsed), 0.01 GC (0.02 elapsed) :ghc
 make: *** [depend] Error 1

For the record, the thing it fails on is the *first* occurance of a
quotation mark, and that's here in bootstrapping.conf:

 [InstalledPackageInfo {package = PackageIdentifier {pkgName =
 filepath, pkgVersion = ...

So it's failing when it sees the quote at the start of filepath

I have also attempted to follow the instructions at the top
./libraries/Makefile, which are:

 # To do a fresh build:
 #
 #   make clean
 #   make boot
 #   make
 #
 # To rebuild a particular library package:
 #
 #   make clean.library.package
 #   make make.library.package
 #
 # or the following is equivalent:
 #
 #   make remake.library.package
 #
 # To add a new library to the tree, do
 #
 #   darcs get http://darcs.haskell.org/packages/foo
 #   [ -e foo/configure.ac ]  ( cd foo  autoreconf )
 #   make make.library.foo

As said above, 'make.library.ndp' does not work, doing a full clean,
boot and then make again doesn't pick up NDP either, and in the last
case (adding a new library,) it doesn't matter because there is no
configure.ac at the top level of ./libraries/ndp

I think I might simply have a *lot* of outdated information. For the
record, this is what I want to try and compile:

 {-# OPTIONS_GHC -fglasgow-exts -fparr -fvectorise #-}
 module Main where
 import GHC.PArr
 
 dotp :: Num a = [:a:] - [:a:] - a
 dotp xs ys = sumP [:x * y | x - xs, y - ys :]
 
 main = print $ dotp [:1..5:] [:6..10:]

Naturally when trying, it fails because DPH isn't there:

 $ ~/ghc-head/bin/ghc --make dotp.hs
 
 no location info:
 Warning: -fparr is deprecated: Use the PArr language instead
 [1 of 1] Compiling Main ( dotp.hs, dotp.o )
 GHC error in desugarer lookup in main:Main:
   Failed to load interface for `Data.Array.Parallel.Lifted.PArray':
 no package matching dph-par was found
 ghc: panic! (the 'impossible' happened)
   (GHC version 6.9.20080720 for i386-apple-darwin):
   initDs user error (IOEnv failure)
 
 Please report this as a GHC bug:
 http://www.haskell.org/ghc/reportabug

(This leads me to believe I actually want
http://darcs.haskell.org/packages/dph, but it's not mentioned. Anywhere.)

If I'm just doing everything wrong, I'd really appreciate knowing and
I'd be *more* than happy to update the wiki pages so that more people
can try it and have it build successfuly, because as it stands I'm
coming to the conclusion that basically 

[Haskell-cafe] Trouble with non-exhaustive patterns

2008-07-21 Thread Fernando Rodriguez


Hi,

I defiend the  following function to get the last element of a list:

final [a] = a
final (_:t) = final t

and it works as expected. Since I didn't want to have a non exhaustive pattern, 
I added the following case:


final []  = [] - I consider that the end of an empty list is the empty list
final [a] = a
final (_:t) = final t

Suddenly, the function stoped working with a rather cryptic (for a newbie 
at least) error message:


*Temp final [4,5]

interactive:1:9:
   No instance for (Num [a])
 arising from the literal `5' at interactive:1:9
   Possible fix: add an instance declaration for (Num [a])
   In the expr*Temp ession: 5
   In the first argument of `final', namely `[4, 5]'
   In the expression: final [4, 5]

What have I done so wrong?

Thanks in advance,
Fernando



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


Re: [Haskell-cafe] Trouble with non-exhaustive patterns

2008-07-21 Thread Janis Voigtlaender

Fernando Rodriguez wrote:


Hi,

I defiend the  following function to get the last element of a list:

final [a] = a
final (_:t) = final t

and it works as expected. Since I didn't want to have a non exhaustive 
pattern, I added the following case:


final []  = [] - I consider that the end of an empty list is the empty list
final [a] = a
final (_:t) = final t

Suddenly, the function stoped working with a rather cryptic (for a 
newbie at least) error message:


*Temp final [4,5]

interactive:1:9:
No instance for (Num [a])
  arising from the literal `5' at interactive:1:9
Possible fix: add an instance declaration for (Num [a])
In the expr*Temp ession: 5
In the first argument of `final', namely `[4, 5]'
In the expression: final [4, 5]

What have I done so wrong?


You probably want final to have type

 final :: [a] - a

But the equation

 final [] = []

conflicts with this.

BTW, you might want to have this kind of discussion at 
[EMAIL PROTECTED] instead. See the announcement:


http://thread.gmane.org/gmane.comp.lang.haskell.general/16345

Ciao, Janis.

--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble with non-exhaustive patterns

2008-07-21 Thread C.M.Brown
Hi Fernando,

I hope you don't mind, but I've moved this over to the Haskell-beginners
mailing list, where I think this kind of question will be more
appropriate.

In Haskell, it helps to think of functions in terms of an input and an
output, that is, what is the thing that is going into the function; and
what is the thing that is coming out of the function?

In your function, final, the input is clearly a list of something (we can
denote this by the Haskell type [a] which means a list of some type,
a). Its return type is clearly an element of the list, so that must be the
something type (the 'a' from the [a]). This gives the Haskell
type:

final :: [a] - a

(final takes a list of 'a' and gives back a single 'a'. The 'a' is a
type variable, and it is used to denote that anything can be put in its
place, so we can give final a list of integers, characters, whatever).

Now, let's take a look at your definition of final. If we take a closer
look, in fact only two equations satisfy this type:

final [a] = a
final (_:t) = final t

The other takes a list and returns a list. The equation,

final [] = []

takes an empty list and returns an empty list (its type is therefore
[a] - [a]).

This is why you got an error, as Haskell doesn't know how what
to do with the conflicting equation. What we need is the final element of
the list. How do we do that?

Let's think of the simple cases first. The final element of a list
containing a single element is just that element,

final [a] = a

But what about if the list contains more elements? Or is an empty list?
The empty list may be confusing, as an empty list contains no elements, so
in effect, we can't return anything. We can, however, return an error
message.

fun [] = error empty List

And the final element of any list, must be the final element of its tail:

final (_:t) = final t

this gives us:

final :: [a] - a
final [] = error Empty List
final [a] = a
final (_:t) = final t

I hope that gives some insight.

Kind regards,
Chris.



On Mon, 21 Jul 2008, Fernando Rodriguez wrote:


 Hi,

 I defiend the  following function to get the last element of a list:

 final [a] = a
 final (_:t) = final t

 and it works as expected. Since I didn't want to have a non exhaustive 
 pattern,
 I added the following case:

 final []  = [] - I consider that the end of an empty list is the empty list
 final [a] = a
 final (_:t) = final t

 Suddenly, the function stoped working with a rather cryptic (for a newbie
 at least) error message:

 *Temp final [4,5]

 interactive:1:9:
 No instance for (Num [a])
   arising from the literal `5' at interactive:1:9
 Possible fix: add an instance declaration for (Num [a])
 In the expr*Temp ession: 5
 In the first argument of `final', namely `[4, 5]'
 In the expression: final [4, 5]

 What have I done so wrong?

 Thanks in advance,
 Fernando



 ___
 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] Trouble with non-exhaustive patterns

2008-07-21 Thread Chaddaï Fouché
2008/7/21 Fernando Rodriguez [EMAIL PROTECTED]:
 Suddenly, the function stoped working with a rather cryptic (for a newbie at
 least) error message:

 *Temp final [4,5]

 interactive:1:9:
   No instance for (Num [a])
 arising from the literal `5' at interactive:1:9
   Possible fix: add an instance declaration for (Num [a])
   In the expr*Temp ession: 5
   In the first argument of `final', namely `[4, 5]'
   In the expression: final [4, 5]

 What have I done so wrong?

As Janis said final [] = [] conflicts with the signature you want for
final BUT the definition of final is still typeable, it just don't
have the type you think it have... and combined with the way Haskell
handle number literals you get this confusing error.

final's type is [[a]] - [a] because final [] = [] imply that the
return type should be a list and thus (final [a] = a) imply that the
input list elements should themselves be lists (because a should be a
list since it is returned in this case)...

So final wants a list of list. All is well until now and if you try
for example :
 final [True, False]
you'll get a slightly better error message (maybe hard for newbies but
very understandable with a little bit of experience) :
Couldn't match expected type `[a]' against inferred type `Bool'
In the expression: True
In the first argument of `final', namely `[True, False]'
In the expression: final [True, False]

Now your error message is particularly nasty because all integer
literals like 5 are treated in the following fashion in Haskell :
they're implicitly translated to fromInteger 5, fromInteger being a
function of the Num typeclass that for an instance Num a take an
Integer and translate it to the a type. This translation is normally
pretty obvious with some bound checking (for Int type) and simple
translation (to Double or Float) but you could in theory have some
pretty crazy instances of Num, [a] for example.
For example here Haskell complains that there are no Num instances for
the [a] type since that's what he want to translate the 5 into

I hope you understood this explanation, even if it's a little bit
crazy and blury for now, just remember, most of the time if you have
an error like :
No instance for (Num X)
   arising from the literal `5' at interactive:1:9
you can more or less translate it to :
Couldn't match expected type `X' against inferred type `Integer'

(This is only true for the Num typeclass, since this is the only case
of polymorphic literals you'll meet for now).

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


Re: [Haskell-cafe] Trouble with non-exhaustive patterns

2008-07-21 Thread Austin Seipp
Hi Fernando,

 final []  = [] - I consider that the end of an empty list is the empty list
 final [a] = a
 final (_:t) = final t
 
 Suddenly, the function stoped working with a rather cryptic (for a newbie 
 at least) error message:
 
 *Temp final [4,5]
 
 interactive:1:9:
 No instance for (Num [a])
   arising from the literal `5' at interactive:1:9
 Possible fix: add an instance declaration for (Num [a])
 In the expr*Temp ession: 5
 In the first argument of `final', namely `[4, 5]'
 In the expression: final [4, 5]


The problem is that final has the type [a] - a, so you cannot have a
pattern match that simply returns the empty list; this makes the
function partial because taking the tail of an empty list is
undefined.

If you wish to avoid it, you can wrap it in a Maybe:

final :: [a] - Maybe a
final []= Nothing
final [a]   = Just a
final (_:t) = final t

$ cat  final.hs
final :: [a] - Maybe a
final []= Nothing
final [a]   = Just a
final (_:t) = final t
$ ghci final.hs 
GHCi, version 6.8.3: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( final.hs, interpreted )
Ok, modules loaded: Main.
*Main final [1,2]
Just 2
*Main final []
Nothing
*Main 

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


Re: [Haskell-cafe] Re: Help using Network.Curl

2008-07-21 Thread Chaddaï Fouché
2008/7/19 Jim Burton [EMAIL PROTECTED]:
 opts = [CurlEncoding text/xml
   , CurlHttpHeaders [X-EBAY-API-COMPATIBILITY-LEVEL=++compatLevel
 , X-EBAY-API-DEV-NAME=++devName
 , X-EBAY-API-APP-NAME=++appName
 , X-EBAY-API-CERT-NAME=++certName
 , X-EBAY-API-CALL-NAME=GeteBayOfficialTime
 , X-EBAY-API-SITEID=0]]

Isn't it : rather than = ? Just saying... (Don't know enough to be
sure I'm thinking about the right thing)

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


Re: [Haskell-cafe] Re: Help using Network.Curl

2008-07-21 Thread Jim Burton
At Mon, 21 Jul 2008 13:21:06 +0100,
=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?= wrote:
 
 2008/7/19 Jim Burton [EMAIL PROTECTED]:
  opts = [CurlEncoding text/xml
, CurlHttpHeaders [X-EBAY-API-COMPATIBILITY-LEVEL=++compatLevel
  , X-EBAY-API-DEV-NAME=++devName
  , X-EBAY-API-APP-NAME=++appName
  , X-EBAY-API-CERT-NAME=++certName
  , X-EBAY-API-CALL-NAME=GeteBayOfficialTime
  , X-EBAY-API-SITEID=0]]
 
 Isn't it : rather than = ? Just saying... (Don't know enough to be
 sure I'm thinking about the right thing)

Is is indeed, thanks very much. I also had to change to using
`perform' rather than curlPost before it would work.

Cheers,

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


[Haskell-cafe] Keeping a set of ForeignPtr's alive

2008-07-21 Thread Felipe Lessa
Hi!

-- Background: --
I have some foreign objects that are mapped to ForeignPtr's, say

newtype Obj = O (ForeignPtr Obj)

and a foreign collection where those objects are added. The adding
is something on the lines of

addObj, removeObj :: Collection - Obj - IO ()

id est, the C code of the collection maintains a reference to all
objects added. That means I have to keep all the ForeignPtr's added
alive and that I must not prevent garbage collection of those removed.
Of course the 'Collection' isn't just a simple collection, otherwise I
would be using normal Haskell counterparts.


-- Question: --
What is the best way to keep the added objects alive? Using a list
will keep the addition cheap and a low memory overhead, while a
Data.Set will make removeObj work in sublinear time (on the Haskell
side). Are there any other options? I'm currently heading towards

data Collection = C !(ForeignPtr Collection) !(IORef [Obj])

like ForeignPtr itself (although in the case of ForeignPtr's there is
no way to remove finalizers).


Thanks!

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


[Haskell-cafe] A good sign: languages used at Google Code Jam

2008-07-21 Thread Don Stewart
http://www.go-hero.net/jam/lang

Haskell as the highest ranked FP language in the Google Code Jam, 
with more submissions than Lisp, Scheme, SML and OCaml put together :)

# C++ (used by 2875 people)
# Java (used by 1747 people)
# Python (used by 691 people)
# C# (used by 609 people)
# C (used by 453 people)
# Perl (used by 193 people)
# Ruby (used by 124 people)
# PHP (used by 119 people)
# Pascal (used by 90 people)
# Haskell (used by 46 people)

# Visual Basic (used by 43 people)
# Objective-C (used by 24 people)
# Lisp (used by 15 people)
# Javascript (used by 13 people)
# Scheme (used by 11 people)
# Lua (used by 10 people)
# Objective CAML (used by 10 people)
# Basic (used by 9 people)
# Bourne Shell (bash) (used by 5 people)
# D (used by 4 people)

# Groovy (used by 4 people)
# J (used by 4 people)
# Scala (used by 4 people)
# ActionScript (used by 3 people)
# Clojure (used by 2 people)
# Eiffel (used by 2 people)
# Erlang (used by 2 people)
# SQL (used by 2 people)
# Shell Script (sh) (used by 2 people)
# Visual Basic Script (used by 2 people)

# AWK (used by 1 people)
# Arc (Lisp) (used by 1 people)
# AutoIt Ver. 3 Script (used by 1 people)
# Brainfuck (used by 1 people)
# GNU Data Language (used by 1 people)
# Informix 4GL (used by 1 people)
# K (used by 1 people)
# Maple (used by 1 people)
# Standard ML (used by 1 people)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Linux kernel/library question

2008-07-21 Thread Galchin, Vasili
Hello,
I am working on POSIX stuff. I have used Linux as my POSIX OS and have
read source when I could find it. Does anybody in this
group of Linux newsgroup where one can ask Linux-related implementation
questions?

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


[Haskell-cafe] beginners mailing list should be beginner's choice

2008-07-21 Thread Dan Weston

Just to avoid any misunderstanding...

I am certain that C.M. Brown meant to say CC'ed the Haskell-beginners 
mailing list instead of moved, but I think it's worth emphasizing 
that the new beginners list was ostensibly created for various discussed 
reasons, but all to provide a more tailored forum for beginners, not to 
restrict participation on haskell-cafe. Words like move could sound to 
a beginner like a dismissal or demotion.


(This policy is clearly different from the haskell list, which has a 
much stronger collegially-enforced moderation policy limited to 
announcements.)


I would hate to think that people on the beginners list might worry that 
their questions were not good enough to join the grown-ups on 
haskell-cafe. I think CC'ing to beginners is hint enough, and soon 
enough people will choose the best forum for their comfort level.


Dan

C.M.Brown wrote:

Hi Fernando,

I hope you don't mind, but I've moved this over to the Haskell-beginners
mailing list, where I think this kind of question will be more
appropriate.



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


[Haskell-cafe] Optimizing 'sequence'

2008-07-21 Thread Gracjan Polak

Hi all,

On the other day I noticed that we could optimize 'sequence' more.
I needed it for my monadic parser. Below is my small experiment.
Sequence from standard library needs 2.3s to finish (and additional
stack space), my version uses only 0.65s and default stack.

Is my version better or am I missing something obvious?

-- standard
sequence1   :: Monad m = [m a] - m [a]
sequence1 ms = foldr k (return []) ms
where
  k m m' = do { x - m; xs - m'; return (x:xs) }

-- accumulator version
sequence2   :: Monad m = [m a] - m [a]
sequence2 ms = sequence' [] ms
where
sequence' vs [] = return (reverse vs)
sequence' vs (m:ms) = m = (\v - sequence' (v:vs) ms)

main = do
let l = map return [1..100]
w - sequence1 l
print (sum w)
return ()

[EMAIL PROTECTED]:~/some_faster time ./Some1 +RTS -K100M
5050

real0m2.318s
user0m2.284s
sys 0m0.032s


[EMAIL PROTECTED]:~/some_faster time ./Some2
5050

real0m0.652s
user0m0.592s
sys 0m0.052s

--
Gracjan


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


Re: [Haskell-cafe] Linux kernel/library question

2008-07-21 Thread frantisek kocun
Hi Vasili,
try one of Linux groups at http://www.nabble.com/Linux-f252.html or maybe
Linux kernel group http://www.nabble.com/linux-kernel-f49.html . But I don't
know if there are people working with Haskell in Linux as well. But if you
would like to ask something only about POSIX, I think they may help.

Fero

2008/7/21 Galchin, Vasili [EMAIL PROTECTED]:

 Hello,
 I am working on POSIX stuff. I have used Linux as my POSIX OS and have
 read source when I could find it. Does anybody in this
 group of Linux newsgroup where one can ask Linux-related implementation
 questions?

 Regards, Vasili

 ___
 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] Optimizing 'sequence'

2008-07-21 Thread Antoine Latter
On Mon, Jul 21, 2008 at 1:54 PM, Gracjan Polak [EMAIL PROTECTED] wrote:

 Hi all,

 On the other day I noticed that we could optimize 'sequence' more.
 I needed it for my monadic parser. Below is my small experiment.
 Sequence from standard library needs 2.3s to finish (and additional
 stack space), my version uses only 0.65s and default stack.

 Is my version better or am I missing something obvious?


How does your version compare with the library version in the following tests:

test1 = do
   (x:_) - sequence [return 5, undefined]
   return x

test2 = do
   (x:_) - sequence $ return 5 : undefined
   return x

main = do
   print $ runIdentity test1
   print $ runIdentity test2


The function runIdentity is found in Control.Monad.Identity in the
mtl package.

(I haven't tried this code yet, so it may not really be syntactically
correct, but hopefully you get the idea.)

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


Re: [Haskell-cafe] Linux kernel/library question

2008-07-21 Thread sylvain nahas
Hi Vasili,

Please have a look at http://vger.kernel.org/vger-lists.html

The main list is linux-kernel. Depending on the level of your questions,
you may also check
linux-newbiehttp://vger.kernel.org/vger-lists.html#linux-newbie.

If it concerns a defined subsystem/architecture, there is often a relevant
mailing-list.

Hope it helps and happy hacking,
Sylvain

2008/7/21 Galchin, Vasili [EMAIL PROTECTED]:

 Hello,
 I am working on POSIX stuff. I have used Linux as my POSIX OS and have
 read source when I could find it. Does anybody in this
 group of Linux newsgroup where one can ask Linux-related implementation
 questions?

 Regards, Vasili

 ___
 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] carry state around ....

2008-07-21 Thread John Meacham
On Mon, Jul 21, 2008 at 01:05:48PM +1200, Richard A. O'Keefe wrote:
 I think it may be time for a little clarity about aoicb's.
 From the Single Unix Specification:
  The aio.h header shall define the aiocb structure
   which shall include AT LEAST the following members:
 int aio_fildes File descriptor.
 off_t   aio_offset File offset.
 volatile void  *aio_bufLocation of buffer.
 size_t  aio_nbytes Length of transfer.
 int aio_reqprioRequest priority offset.struct  
 sigevent aio_sigevent   Signal number and value.
 int aio_lio_opcode Operation to be performed.
  
 The AT LEAST here means that
  - a portable program may rely on these members being present
  - a portable program MUST assume that an unknown number of
additional members are also present
  - a portable program may freely copy such a record, but may
only pass it to a library function if that function is
expecting to initialise it

 For asynchronous I/O, this means that
  - you can allocate an aiocb object
  - an aiocb passed to aio_suspend, aio_error,
aio_return, or aio_cancel should have been
filled in by aio_read or aio_write and should
be EXACTLY THE SAME object, not a copy of it.

Yes. This is pretty standard as far as what you can count on in terms of
standard C structures. The method I use in the RSA.hsc module I posted
is compatible with these assumptions. Generally this is pretty much
exactly the thing hsc2hs was made to solve. 

Just a note, if you are doing manual explicit frees of the aiocb
structure then you only need a 'Ptr', if you want the structure to be
automatically garbage collected when all haskell references to it
disappear, then you need to use 'ForeignPtr'.

John

-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Extending the GSoC model

2008-07-21 Thread Neil Mitchell
Hi

Suggested by Andrew Wager on libraries@, moving to haskell-cafe@ since
its a really interesting idea and libraries is probably not the best
place for it.

  Not sure if this is the best place to suggest this, but I was
  wondering about the possibility of extending the model that we
  currently use for Google's Summer of Code.

  The benefits:
  1.) A place to make suggestions for code you would never be able to
  write, and somebody else might not think of
  2.) A place to see what's being worked on, but not yet done
  3.) A way for people who are less confident in their haskell-foo to find 
 mentors
  4.) A way for people who are more confident in their haskell-foo to
  contribute without spending a ton of time hacking up actual code
  5.) Overall, more (and higher-quality) libraries

And my thoughts:

1) I think as long as the suggestions are small improvements to
existing projects it could work really well. New projects are probably
less likely to work without the original author having the original
motivation. I have one of these for some of my projects:
http://code.google.com/p/ndmitchell/issues/list - a bug tracker works
quite well.

2) Bug trackers do this.

3, 4) Fantastic idea, coordinating via the IRC channel already gives
some of this, but it could be made more direct. Also having a specific
person to talk to, and to review/commit/integrate the work makes the
work more useful.

5) Always a great idea.

So I think these things could be achieved by integrating various bug
trackers, ensuring lots of projects on hackage have bug trackrs, and
some mailing list for people working on this to allow people to ask
for mentors and mentors to be available to respond. My guess that if
there are the people who want mentors, then mentors could be found -
but the other way round won't happen.

Thanks

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


Re: [Haskell-cafe] Optimizing 'sequence'

2008-07-21 Thread Don Stewart
If you can demonstrate the required laziness/strictness properties
are identical, looks like a nice idea.

gracjanpolak:
 
 Hi all,
 
 On the other day I noticed that we could optimize 'sequence' more.
 I needed it for my monadic parser. Below is my small experiment.
 Sequence from standard library needs 2.3s to finish (and additional
 stack space), my version uses only 0.65s and default stack.
 
 Is my version better or am I missing something obvious?
 
 -- standard
 sequence1   :: Monad m = [m a] - m [a]
 sequence1 ms = foldr k (return []) ms
 where
   k m m' = do { x - m; xs - m'; return (x:xs) }
 
 -- accumulator version
 sequence2   :: Monad m = [m a] - m [a]
 sequence2 ms = sequence' [] ms
 where
 sequence' vs [] = return (reverse vs)
 sequence' vs (m:ms) = m = (\v - sequence' (v:vs) ms)
 
 main = do
 let l = map return [1..100]
 w - sequence1 l
 print (sum w)
 return ()
 
 [EMAIL PROTECTED]:~/some_faster time ./Some1 +RTS -K100M
 5050
 
 real0m2.318s
 user0m2.284s
 sys 0m0.032s
 
 
 [EMAIL PROTECTED]:~/some_faster time ./Some2
 5050
 
 real0m0.652s
 user0m0.592s
 sys 0m0.052s
 
 --
 Gracjan
 
 
 ___
 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] Trees (Rose Trees?)

2008-07-21 Thread Ryan Bloor
hi
 
I was curious as to whether my implementation of a Rose Tree and a sumTree 
function was correct. The aumTree adds up the elements of a tree.
 
data Tree a = Leaf a | Node [Tree a]
 
sumTree :: Tree Int - Int
sumTree (Node []) = 0
sumTree (Node xs) = sum (map sumTree xs)
 
The problem with this is I get a pattern matching error. Am I representing 
trees right... see below.
 
Also, would an empty tree be represented by ... Node [] with this 
implementation?
How would I represent a tree of the form... Tree (Node 2(Node 6 Empty Empty) 
Empty) taken from a binary one.
Like this? Node [ [Leaf 2], Node [ Leaf 6,Node[],Node[] ], Node[] ] 
 
Ryan
 
 
_
Find the best and worst places on the planet
http://clk.atdmt.com/UKM/go/101719807/direct/01/___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trees (Rose Trees?)

2008-07-21 Thread Andrew Wagner
There are a few different kinds of trees, but if you only need to
store data on the leaves, that representation will work. As for your
sumTree function, you are indeed missing a case...consider sumTree
(Leaf 3)! Once you deal with that case, the other two can actually be
combined (since sum [] = 0).

2008/7/21 Ryan Bloor [EMAIL PROTECTED]:
 hi

 I was curious as to whether my implementation of a Rose Tree and a sumTree
 function was correct. The aumTree adds up the elements of a tree.

 data Tree a = Leaf a | Node [Tree a]

 sumTree :: Tree Int - Int
 sumTree (Node []) = 0
 sumTree (Node xs) = sum (map sumTree xs)

 The problem with this is I get a pattern matching error. Am I representing
 trees right... see below.

 Also, would an empty tree be represented by ... Node [] with this
 implementation?
 How would I represent a tree of the form... Tree (Node 2(Node 6 Empty Empty)
 Empty) taken from a binary one.
 Like this? Node [ [Leaf 2], Node [ Leaf 6,Node[],Node[] ], Node[] ]

 Ryan



 
 Find out how to make Messenger your very own TV! Try it Now!
 ___
 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