Re: [Haskell-cafe] Why do I need a 'do'?

2009-04-30 Thread Henning Thielemann


On Wed, 29 Apr 2009, michael rice wrote:


==

import System.Random

rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))

rollNDice :: Int - [IO Int]
rollNDice 0 = []
rollNDice n = rollDice : rollNDice (n-1)



replicateM n rollDice

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


Re: [Haskell-cafe] default values in a record structure

2009-04-30 Thread j.waldmann

  Is there anyway when defining a dat type record struct to indicate
 default values for some of the fields?

A bit dated, but still ...
http://article.gmane.org/gmane.comp.lang.haskell.general/2078

J.W.

-- 
View this message in context: 
http://www.nabble.com/default-values-in-a-record-structure-tp23287084p23313391.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] Getting started - help

2009-04-30 Thread applebiz89

What I need to do is build a type of database. Firstly have a few questions,
whether what I have done it right...and how to do something else. 

This is my algebraic type for the database (correct me if its wrong) 

data Film = Film String String Int String 

with this as the data. 

testDatabase :: [Film] 
testDatabase = [(Casino Royale, Martin Campbell,2006, Garry, Dave,
Zoe)] 

the last set of strings are the fans to the film. I want to be able to add a
new fan, but not sure how to specifically insert it to there 

this is what I have so far: 

becomeFan :: String - String - [Film] - [Film] 
becomeFan = do putStr Which film are you a fan of:   
filmTitle - getLine 
do putStr What is your name:  
fanName - getLine 
(if filmTitle == filmName then fanName : [Film]) 
-- 
View this message in context: 
http://www.nabble.com/Getting-started---help-tp23314466p23314466.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread Magnus Therning
First off, is this homework?

You really ought to start with passing your code to GHCi, or the
compiler, to see whether it's accepted before sending questions to the
mailing list.  At least if you are interested in getting constructive
replies.

On Thu, Apr 30, 2009 at 12:33 PM, applebiz89 applebi...@hotmail.com wrote:

 What I need to do is build a type of database. Firstly have a few questions,
 whether what I have done it right...and how to do something else.

 This is my algebraic type for the database (correct me if its wrong)

 data Film = Film String String Int String

 with this as the data.

 testDatabase :: [Film]
 testDatabase = [(Casino Royale, Martin Campbell,2006, Garry, Dave,
 Zoe)]

 the last set of strings are the fans to the film. I want to be able to add a
 new fan, but not sure how to specifically insert it to there

If the fans is a set of strings why not represent them as a list of
strings (`[String]`)?

 this is what I have so far:

 becomeFan :: String - String - [Film] - [Film]
 becomeFan = do putStr Which film are you a fan of:  
            filmTitle - getLine
            do putStr What is your name: 
            fanName - getLine
            (if filmTitle == filmName then fanName : [Film])

The type is wrong, you need to do this in the `IO` monad.

A more serious issue is that I don't understand at all what you intend
this code to do.  It isn't valid Haskell, but I think that instead of
battling Haskell you should, at this point, go back to your algorithm.
 Answer the question, given your type, what steps are needed to add a
fan to a single film?  Then you can progress to answering, what steps
are needed to add a fan to a specific film in a list of films?

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Help from C libraries experts

2009-04-30 Thread Maurício
 Do you understand very well a C library and would like
 Haskell to have a binding for it?  (...)

 Could you perhaps then summarise what design rules you're using? 

Yes. They are summarised at the main module documentation:

http://hackage.haskell.org/packages/archive/bindings/0.1/doc/html/Bindings.html

 For example, why did you pick the new 'Bindings' namespace?

The most important guideline is: users guide guidelines. If you
have a better sugestion for a base module name, please open a
ticket at development website, under 'Issues/Create new issue'
(you can do it as anonymous):

http://bitbucket.org/mauricio/bindings


 What are you doing that's different to having standalone
 small packages?

I'm trying to write canonical bindings libraries.

 One risk I see is that 'bindings' will depend on  a large number of C
 libraries (...)

Sure. I would like to have:

bindings-common
bindings-testsAndExamples
bindings-sqlite3
bindings-openusb
bindings-agar
etc.

But I thought I should not polute hackage before this package
get at least a few people understanding and agreeing with
the concept.

 Maybe this is a better discussion for librar...@?

OK. I'll repost there, with text updated after your thoughts.

Thanks,
Maurício

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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread applebiz89

firstly no it isnt homework. I havent run it through the compiler because I
know it won't compile as I havent finished the function as you can see. I
was just asking for guidance on how to understand what to do. So now I know
to put the fan's into a list, which I have done. So then I can just add the
fan's directly to the list of fans if the name of the film matches the
desired film to be a fan of.



Magnus Therning wrote:
 
 First off, is this homework?
 
 You really ought to start with passing your code to GHCi, or the
 compiler, to see whether it's accepted before sending questions to the
 mailing list.  At least if you are interested in getting constructive
 replies.
 
 On Thu, Apr 30, 2009 at 12:33 PM, applebiz89 applebi...@hotmail.com
 wrote:

 What I need to do is build a type of database. Firstly have a few
 questions,
 whether what I have done it right...and how to do something else.

 This is my algebraic type for the database (correct me if its wrong)

 data Film = Film String String Int String

 with this as the data.

 testDatabase :: [Film]
 testDatabase = [(Casino Royale, Martin Campbell,2006, Garry, Dave,
 Zoe)]

 the last set of strings are the fans to the film. I want to be able to
 add a
 new fan, but not sure how to specifically insert it to there
 
 If the fans is a set of strings why not represent them as a list of
 strings (`[String]`)?
 
 this is what I have so far:

 becomeFan :: String - String - [Film] - [Film]
 becomeFan = do putStr Which film are you a fan of:  
            filmTitle - getLine
            do putStr What is your name: 
            fanName - getLine
            (if filmTitle == filmName then fanName : [Film])
 
 The type is wrong, you need to do this in the `IO` monad.
 
 A more serious issue is that I don't understand at all what you intend
 this code to do.  It isn't valid Haskell, but I think that instead of
 battling Haskell you should, at this point, go back to your algorithm.
  Answer the question, given your type, what steps are needed to add a
 fan to a single film?  Then you can progress to answering, what steps
 are needed to add a fan to a specific film in a list of films?
 
 /M
 
 -- 
 Magnus Therning(OpenPGP: 0xAB4DFBA4)
 magnus@therning.org  Jabber: magnus@therning.org
 http://therning.org/magnus identi.ca|twitter: magthe
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

-- 
View this message in context: 
http://www.nabble.com/Getting-started---help-tp23314466p23314963.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] Re: Why do I need a 'do'?

2009-04-30 Thread Maurício
 import System.Random

 rollDice :: IO Int
 rollDice = getStdRandom (randomR (1,6))

 rollNDice :: Int - [IO Int]
 rollNDice 0 = []
 rollNDice n = rollDice : rollNDice (n-1)
 
 
 replicateM n rollDice
 
 http://www.haskell.org/haskellwiki/Avoiding_IO#State_monad

Or, if you want the original idea:

sequence (rollNDice 10)

Check the type of sequence at Control.Monad.

Maurício

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


Re: [Haskell-cafe] Re: Why do I need a 'do'?

2009-04-30 Thread Henning Thielemann


On Thu, 30 Apr 2009, Maurício wrote:


import System.Random

rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))

rollNDice :: Int - [IO Int]
rollNDice 0 = []
rollNDice n = rollDice : rollNDice (n-1)



replicateM n rollDice

http://www.haskell.org/haskellwiki/Avoiding_IO#State_monad


Or, if you want the original idea:

sequence (rollNDice 10)

Check the type of sequence at Control.Monad.


I'd still propose
  
http://www.haskell.org/haskellwiki/Haskell_programming_tips#Avoid_explicit_recursion___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help from C libraries experts

2009-04-30 Thread Tillmann Rendel

Hi,

Maurício wrote:

My goal is to have a place where one can find reliable and
comprehensive low-level bindings to foreign libraries, so that
writing higher level bindings becomes an easier task.


Like others, I think you should consider making this place not a single 
package, but a bunch of packages. For example, one could make a 
convention that a package named bindings-foo contains low-level bindings 
to a c library foo.


In your guidelines, you say:
Code should be portable and easy to build. 


Does your understanding of portable include Windows?

The problem with windows is that you usually do not have these c 
libraries installed, and no easy way to install them, so a binding is 
not enough. For example, the Haskell package zlib bundles the actual 
zlib c code for Windows users, which works not too bad. Do you plan to 
support this kind of thing in your bindings project?


I am not sure which kind of c libraries can be reasonably included in 
cabal packages. I guess the idea breaks with more complicated build 
systems for the c library, and with libraries written in other languages 
then c, and with libraries which are supposed to be linked against 
dynamically, and with complicated license situations, and in all kinds 
of other situations. Anyway, if there are more such libraries then just 
zlib, maybe a naming convention would be helpful, like:


- bundled-foois a package which contains just the c code of foo
- bindings-foo   contains the low-level bindings for foo

Now bindings-foo could use cabal configurations to depend on the c 
library directly on most systems, but depend on bundled-foo on Windows. 
This way, on all systems, you could just install bindings-foo and be 
able to use the library. If you have special needs, you could still use 
an explicit flag on Windows to configure bindings-foo not to depend on 
bundled-foo, and install the c library yourself instead.


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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread Tillmann Rendel

Hi,

applebiz89 wrote:
data Film = Film String String Int String 

with this as the data. 

testDatabase :: [Film] 
testDatabase = [(Casino Royale, Martin Campbell,2006, Garry, Dave,
Zoe)] 


Try to compile this part of the program, to get a feeling for whether 
you are on the right track. If it does not compile, try to find out 
what's wrong and correct it so that it compiles.


As you already noted in a different mail, you plan to change the 
representation of the list of fans to a list of strings (instead of a 
single string with commas). That is a good idea! So change the data 
declaration, and change the definition of testDatabase to this new 
design. Try to compile that program.



Now you can add some utility functions to work with your database. This 
will make it much easier to write a correct user interface later. For 
example, write a function


  isFan :: [Film] - String - String - Bool

which checks whether someone is a fan of a film in your database. In 
other words,


  isFan testDatabase Garry Casino Royale

should be True, but

  isFan testDatabase Peter Matrix

should be False.


Another useful utility function could be

  becomeFan :: String - String - [Film] - [Film]

which adds the information that someone is a fan of some film to an 
existing database. Note that this function does not do any user 
interaction, but gets the name of the fan and the name of the film as 
arguments.


Think about which other utility functions you could use. Try them out in 
ghci. When you have done that, you can write a user interface which asks 
for input on the command line and uses the utility functions to keep 
track of the current database.


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


[Haskell-cafe] Re: Help from C libraries experts

2009-04-30 Thread Achim Schneider
Maurício briqueabra...@yahoo.com wrote:

 bindings-agar

http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/51478


-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread applebiz89

Hey thanks, that was really helpful actually. I know it must be annoying for
you, and im sorry but ive done what you said, try and compile it to see if
it does and fix it. I have tried every possible way of using brackets in
different place's etc (as u can tell Im not good with haskell at all) but it
still isnt, it must be to do with my data type.

-- Film as datatype

data Film = String String Int [String]

-- List of films

testDatabase :: [Film]
testDatabase = [Casino Royale, Martin Campbell ,2006, [Garry, Dave,
Zoe] ]

I get this error:

*** Expression : [Casino Royale,Martin
Campbell,2006,[(Garry,Dave,Zoe)]]
*** Term   : [(Garry,Dave,Zoe)]
*** Type   : [([Char],[Char],[Char])]
*** Does not match : [Char]

Thanks alot!

applebiz



Tillmann Rendel-3 wrote:
 
 Hi,
 
 applebiz89 wrote:
 data Film = Film String String Int String 
 
 with this as the data. 
 
 testDatabase :: [Film] 
 testDatabase = [(Casino Royale, Martin Campbell,2006, Garry, Dave,
 Zoe)] 
 
 Try to compile this part of the program, to get a feeling for whether 
 you are on the right track. If it does not compile, try to find out 
 what's wrong and correct it so that it compiles.
 
 As you already noted in a different mail, you plan to change the 
 representation of the list of fans to a list of strings (instead of a 
 single string with commas). That is a good idea! So change the data 
 declaration, and change the definition of testDatabase to this new 
 design. Try to compile that program.
 
 
 Now you can add some utility functions to work with your database. This 
 will make it much easier to write a correct user interface later. For 
 example, write a function
 
isFan :: [Film] - String - String - Bool
 
 which checks whether someone is a fan of a film in your database. In 
 other words,
 
isFan testDatabase Garry Casino Royale
 
 should be True, but
 
isFan testDatabase Peter Matrix
 
 should be False.
 
 
 Another useful utility function could be
 
becomeFan :: String - String - [Film] - [Film]
 
 which adds the information that someone is a fan of some film to an 
 existing database. Note that this function does not do any user 
 interaction, but gets the name of the fan and the name of the film as 
 arguments.
 
 Think about which other utility functions you could use. Try them out in 
 ghci. When you have done that, you can write a user interface which asks 
 for input on the command line and uses the utility functions to keep 
 track of the current database.
 
Tillmann
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

-- 
View this message in context: 
http://www.nabble.com/Getting-started---help-tp23314466p23318195.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread Michael Mossey
I'm intermediate-level myself so I hesitate to say something wrong, but I'll go 
ahead and point out the obvious.


applebiz89 wrote:

Hey thanks, that was really helpful actually. I know it must be annoying for
you, and im sorry but ive done what you said, try and compile it to see if
it does and fix it. I have tried every possible way of using brackets in
different place's etc (as u can tell Im not good with haskell at all) but it
still isnt, it must be to do with my data type.

-- Film as datatype

data Film = String String Int [String]


This time you left something off what's called the constructor. (You had it 
there the first time!)


data Film = Film String String Int [String]

Because an algebraic data type can be constructed in potentially more than one 
way, you need a constructor. In this case, you have only one way of constructing 
a Film, so you just name the constructor Film also.




-- List of films

testDatabase :: [Film]
testDatabase = [Casino Royale, Martin Campbell ,2006, [Garry, Dave,
Zoe] ]



And here your problem is that (1) you need to prefix the constructor when making 
a Film, and (2) don't use commas between arguments to the constructor. (In 
Haskell commas are for lists and tuples, and not for function arguments.) So 
this would be how to make one Film:


aFilm :: Film
aFilm = Film Casino Royale Martin Campbell 2006 [Garry, Dave, Zoe]

or

testDatabase = [ Film Casino Royale Martin Campbell 2006 [Garry, Dave, 
Zoe] ]





I get this error:

*** Expression : [Casino Royale,Martin
Campbell,2006,[(Garry,Dave,Zoe)]]
*** Term   : [(Garry,Dave,Zoe)]
*** Type   : [([Char],[Char],[Char])]
*** Does not match : [Char]

Thanks alot!

applebiz

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


Re: [Haskell-cafe] Getting started - help

2009-04-30 Thread Magnus Therning
On Thu, Apr 30, 2009 at 4:04 PM, applebiz89 applebi...@hotmail.com wrote:

 Hey thanks, that was really helpful actually. I know it must be annoying for
 you, and im sorry but ive done what you said, try and compile it to see if
 it does and fix it. I have tried every possible way of using brackets in
 different place's etc (as u can tell Im not good with haskell at all) but it
 still isnt, it must be to do with my data type.

 -- Film as datatype

 data Film = String String Int [String]

Change that to

  data Film = Film String String Int [String]

that way you get a constructor called `Film` for the data type `Film`:

  casinoRoyale = Film CR MC 2006 [G, D, Z]

 -- List of films

 testDatabase :: [Film]
 testDatabase = [Casino Royale, Martin Campbell ,2006, [Garry, Dave,
 Zoe] ]

Then you can create your test database either like this:

  testDatabase = [(Film CR MC 2006 [G, D, Z])]

or if you have defined `casinoRoyale` like above the like this:

  testDatabase = [casinoRoyale]

 I get this error:

 *** Expression     : [Casino Royale,Martin
 Campbell,2006,[(Garry,Dave,Zoe)]]
 *** Term           : [(Garry,Dave,Zoe)]
 *** Type           : [([Char],[Char],[Char])]
 *** Does not match : [Char]

I think you would benefit from reading chapter 3 of RWH
http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html
it offers a good introduction to defining your own types.

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arrow preprocessor and *** combinator

2009-04-30 Thread Peter Verswyvelen
Thanks Ross.
Does anyone know how to tackle this? Combining GHC's builtin arrow processor
and rewrite rules?

On Wed, Apr 29, 2009 at 3:43 PM, Ross Paterson r...@soi.city.ac.uk wrote:

 On Wed, Apr 29, 2009 at 03:07:25PM +0200, Peter Verswyvelen wrote:
  After doing some pragmatic tests, it seems that neither the arrow
 preprocessor
  nor GHC's builtin one generate / optimize to the (***) combinator.

 Right, neither of them do that.  It might be possible to do that using
 GHC rules, but it isn't done at the moment.
 ___
 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] How to install HOpenGL to Windows?

2009-04-30 Thread Sven Panne
Am Mittwoch, 29. April 2009 11:25:31 schrieb Duncan Coutts:
 On Mon, 2009-04-27 at 19:03 +0200, Sven Panne wrote:
  [...]
  As usual, things are always a bit trickier than they appear initially: On
  non- Windows systems it is not always sufficient to link against libGL
  alone, sometimes you'll have to link against several X11 libs, too. I am
  not sure if this is still a widespread problem, but in the past it was.

 Right. It's still possible to use custom code in Setup.hs to test these
 kinds of things. It's a bit less easy however.

That's why the autoconf macros are so tricky. Re-inventing the wheel in 
Haskell is not something I'd like to do. Note: I see autoconf as a necessary 
evil, not as a glorious tool. The predefined autoconf macros contain man years 
(if not man decades) of sweat and tears from people trying to make their SW 
portable. If you only know 1 or 2 platforms, everything looks easy, but this 
is not the case at all. Good luck for everybody trying to ignore that 
accumulated knowledge...

 I didn't know that there was any working GHC for Cygwin. Or do you mean
 building a non-cygwin lib but under the cygwin shell? [...]

I don't know if GHC currently builds under Cygwin, but in former times it was 
*the* way (read: one and only way) to build it on Windows.

  On *nices you look into /usr/include and /usr/local/include, and
  that's it, unless the user tells you something different. And Apple is
  always a very creative company, so they decided to put *their* OpenGL
  headers in a completely different path where no -I flag can help...

 But you have some way of finding them right? Even if it's platform
 dependent. We can do the same in the .cabal file or the Setup.hs.
 There's also a Cabal flag users can pass to tell us about extra lib and
 include dirs.

I even have standard, well-documented, platform-independent way: Tell 
configure about it via the environment variable CPPFLAGS for headers and 
LDFLAGS for libraries. Cabal is buggy in this respect, IIRC, it passes no or 
incorrectly named variables to configure.

 Absolutely, finding headers is important. Cabal now checks at configure
 time that all header files and libs listed in the .cabal file can
 actually be found.

I don't know what Cabal does internally, but simply checking for the existence 
of a header file or a library file is *far* too naive, look into the autoconf 
docs and/or mailing lists to see why. You actually have to compile for header 
checks and link for library checks, everything else is plainly wrong, because 
you'll probably miss dependencies, pick up the wrong stuff, etc.

 One suggestion I've seen is just to improve the ffi pre-processors. The
 c2hs tool is in a position to discover if the calling convention is
 stdcall or ccall so it could generate the foreign imports correctly. [...]

This wouldn't help much: The foreign imports in OpenGL are written by hand, 
and when the OpenGL ARB ever manages to release some consistent, machine-
usable and complete API description (the current .spec files fail in almost 
all these aspects), they will be generated from that, not from C headers, 
because, not surprisingly, the latter lack a lot of information.

 In practise I've not found that most configure scripts actually do
 feature based tests. There's some, but half of it degenerates into if
 we've not got the OSX framework for this then do that. I mean they just
 end up doing platform-specific conditionals. [...]

This is often correct for hobby projects of inexperienced people, but not 
necessarily for larger or more mature projects. And in a (very) few cases, 
platform-specific conditionals are even the right thing to do, but not in the 
vast majority of cases, of course.

And this has nothing to say about autoconf itself: Seeing e.g. ugly Haskell 
code is not a reason to condemn Haskell itself, either.

 Anyway, so that's why I'd like us to look in detail at what features we
 need in Cabal to let us switch most packages from using ./configure
 scripts to using Setup.hs scripts.

As I said in another email: I'll happily review and accept patches for this, 
but I won't spend any effort on re-inventing the autoconf wheel in Haskell.

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


[Haskell-cafe] Google SoC: Space profiling reloaded

2009-04-30 Thread Patai Gergely
Hello all,

I'm one of the lucky individuals accepted for this year's Summer of
Code. Here's the abstract of my proposal:

http://socghop.appspot.com/student_project/show/google/gsoc2009/haskell/t124022468245

There's less than a month left before I'm supposed to jump into coding,
and I'd love to hear about any little idea you think would make this
project even better! I created a project page with a rough draft of what
I intend to concentrate on, but the issue tracker is obviously begging
for content, so feel encouraged to populate it. :)

http://code.google.com/p/hp2any/

I also intend to expand the description later.

Gergely

-- 
http://www.fastmail.fm - The professional email service

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


Re: [Haskell-cafe] How to install HOpenGL to Windows?

2009-04-30 Thread Duncan Coutts
On Thu, 2009-04-30 at 19:44 +0200, Sven Panne wrote:

 That's why the autoconf macros are so tricky. Re-inventing the wheel in 
 Haskell is not something I'd like to do. Note: I see autoconf as a necessary 
 evil, not as a glorious tool. The predefined autoconf macros contain man 
 years 
 (if not man decades) of sweat and tears from people trying to make their SW 
 portable. If you only know 1 or 2 platforms, everything looks easy, but this 
 is not the case at all. Good luck for everybody trying to ignore that 
 accumulated knowledge...

The thing is, it doesn't really matter if autoconf macros work fine for
every Unix ever invented. The Windows users simply cannot use packages
with configure scripts. They complain about it a lot. We can call them
foolish for not installing cygwin/mingw, but they will not do it and
instead will simply not use our software and/or continue to complain.

  But you have some way of finding them right? Even if it's platform
  dependent. We can do the same in the .cabal file or the Setup.hs.
  There's also a Cabal flag users can pass to tell us about extra lib and
  include dirs.
 
 I even have standard, well-documented, platform-independent way: Tell 
 configure about it via the environment variable CPPFLAGS for headers and 
 LDFLAGS for libraries. Cabal is buggy in this respect, IIRC, it passes no or 
 incorrectly named variables to configure.

Right then lets fix it, lets work out exactly which flags or env vars to
pass. See:
http://hackage.haskell.org/trac/hackage/ticket/458

Doing it is not hard, it's working out exactly what to pass that's the
important matter.

  Absolutely, finding headers is important. Cabal now checks at configure
  time that all header files and libs listed in the .cabal file can
  actually be found.
 
 I don't know what Cabal does internally, but simply checking for the 
 existence 
 of a header file or a library file is *far* too naive, look into the autoconf 
 docs and/or mailing lists to see why. You actually have to compile for header 
 checks and link for library checks, everything else is plainly wrong, because 
 you'll probably miss dependencies, pick up the wrong stuff, etc.

Right, that's exactly what it does. We checked used the autoconf macros
as guidance.

  One suggestion I've seen is just to improve the ffi pre-processors. The
  c2hs tool is in a position to discover if the calling convention is
  stdcall or ccall so it could generate the foreign imports correctly. [...]
 
 This wouldn't help much: The foreign imports in OpenGL are written by hand, 
 and when the OpenGL ARB ever manages to release some consistent, machine-
 usable and complete API description (the current .spec files fail in almost 
 all these aspects), they will be generated from that, not from C headers, 
 because, not surprisingly, the latter lack a lot of information.

I don't see that the two approaches are exclusive. For example with Gtk+
we also generate from an incomplete API description with manual
adjustments because of lack of info. However we generate .chs files that
then get processed by c2hs so that we can check if our binding at least
matches the C header files. Certainly the C headers are not enough (no
info about memory management) but the bindings do at least have to be
consistent with the C headers on the current platform. And the C headers
do say if the calling convention is ccall or stdcall (otherwise the C
progs would not work).

But this is not a short term fix, it'd be a complete change for the
binding so I'm not seriously suggesting it.

  Anyway, so that's why I'd like us to look in detail at what features we
  need in Cabal to let us switch most packages from using ./configure
  scripts to using Setup.hs scripts.
 
 As I said in another email: I'll happily review and accept patches for this, 
 but I won't spend any effort on re-inventing the autoconf wheel in Haskell.

I'm not asking you personally to do that. I'm asking for help from you
or others on identifying the tests that we need to do to support our
most common Haskell bindings packages.

Duncan

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


[Haskell-cafe] Re: Help from C libraries experts

2009-04-30 Thread Maurício
 My goal is to have a place where one can find reliable and
 comprehensive low-level bindings to foreign libraries, so that
 writing higher level bindings becomes an easier task.

 (...) In your guidelines, you say:

 Code should be portable and easy to build. 

 Does your understanding of portable include Windows?

My thought on that was: anyone trying to wrap a library will
have to solve this kind of problem. So, if it is possible to
write such wrap, at least one solution exist, and 'bindings'
set will try to select the best one for general use. Sometimes,
this may be adding the C code itself, as is my current attempt
on sqlite3.  Sometimes the task can be delegated to pkg-config.

Actually, that is the reason why my first post was a call for
help from libraries experts. This has to be solved on a per
library base.

Thanks,
Maurício

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


Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-30 Thread Jason Dusek
  I gather that ...making it possible to use ST code directly
  on IORef's. is what we have today?


--
Jason Dusek


 |...making it possible to use ST code directly on IORef's.|
  http://www.mail-archive.com/glasgow-haskell-b...@haskell.org/msg03568.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arrow preprocessor and *** combinator

2009-04-30 Thread Luke Palmer
On Thu, Apr 30, 2009 at 11:42 AM, Peter Verswyvelen bugf...@gmail.comwrote:

 Thanks Ross.
 Does anyone know how to tackle this? Combining GHC's builtin arrow
 processor and rewrite rules?


Another possibility is to make an optimizer arrow transformer that encodes
the rules.  Eg.

data Optimize a b c where
Arr :: (b - c) - Optimize a b c
(:) :: Optimize a b c - Optimize a c d - Optimize a b d
First :: Optimize a b c - Optimize a (b,d) (c,d)
Second :: Optimize a b c - Optimize a (b,d) (c,d)
(:***) :: Optimize a b b' - Optimize a c c' - Optimize a (b,b') (c,c')

optimize :: Optimize a b c - Optimize a b c
optimize (First f : Second g) = f :*** g
...

compile :: (Arrow a) = Optimize a b c - a b c
compile (Arr f) = arr f
compile (f : g) = compile f  compile g
...

I have of course handwaved over optimize, which will have some interesting
traversal structure; esp. if you want to take advantage of the associativity
of .

Unfortunately, Arr is not quite transparent enough to do everything one
might want with this.  e.g.,this rule cannot be encoded:

swap (x,y) = (y,x)
first f  arr swap  first g = f *** g  arr swap

If you are serious about arrow optimizations, it might be worthwhile to
modify the original preprocessor to output a richer GADT (with cases for
things like ArrSwap) with all the information it knows, so that user code
can experiment with optimizations.

Godspeed on this interesting problem.  Please publish :-)

Luke


 On Wed, Apr 29, 2009 at 3:43 PM, Ross Paterson r...@soi.city.ac.ukwrote:

 On Wed, Apr 29, 2009 at 03:07:25PM +0200, Peter Verswyvelen wrote:
  After doing some pragmatic tests, it seems that neither the arrow
 preprocessor
  nor GHC's builtin one generate / optimize to the (***) combinator.

 Right, neither of them do that.  It might be possible to do that using
 GHC rules, but it isn't done at the moment.
 ___
 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-30 Thread Ross Paterson
On Thu, Apr 30, 2009 at 12:44:49PM -0700, Jason Dusek wrote:
   I gather that ...making it possible to use ST code directly
   on IORef's. is what we have today?

No, we have stToIO :: ST RealWorld a - IO a, but STRef and IORef are
still incompatible types.  (I now think that's a good thing, because
STRefs have more equations than IORefs.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arrow preprocessor and *** combinator

2009-04-30 Thread Peter Verswyvelen

 If you are serious about arrow optimizations, it might be worthwhile to
 modify the original preprocessor to output a richer GADT (with cases for
 things like ArrSwap) with all the information it knows, so that user code
 can experiment with optimizations.

 Godspeed on this interesting problem.  Please publish :-)


Thanks for the tips Luke. I didn't think of that. But would doing these
optimizations at runtime be as efficient as using rewrite rules? I know
Yampa uses these GADTs for optimization.

No I won't be able to make such a big optimizer myself - but Paul Liu and
Paul Hudak are working on something like that I think (see the Causal
Commutative Arrows paper). But my code made use of a non-default *** and I
found it odd that it was never called, so I hoped it would be easy to add a
couple of simple rewrite rule so that *** was generated.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to install HOpenGL to Windows?

2009-04-30 Thread Claus Reinke

The thing is, it doesn't really matter if autoconf macros work fine for
every Unix ever invented. The Windows users simply cannot use packages
with configure scripts. They complain about it a lot. We can call them
foolish for not installing cygwin/mingw, but they will not do it and
instead will simply not use our software and/or continue to complain.


Windows users - that's a lot of different people to generalize over. 
From what I've heard, most complaints are about assumptions made 

by non-windows users that turn out not to hold on windows,
causing things to fail on windows. Which seems reason enough for
failure reports, otherwise known as complaints.

If someone wants to use a unix shell on an unknown platform, they 
should at least check that one exists there or -even better- provide 
one, not just assume that there'll always be one (and then be surprised 
about getting complaints from those windows users). Same for

autoconf, make  co.

If someone mixes up GCC's standard layout, they need to adjust
everything for those changes, and when that turns out to be rather
difficult, it is no surprise if GCC seems unable to pick the right 
include or library paths. This particular issue has just recently been 
fixed in GHC head, I understand (will that fix cause problems for
cabal, btw, when the existing path hacks are no longer needed?). 
http://hackage.haskell.org/trac/ghc/ticket/1502#comment:12


Apart from causing lots of other path issues (and confusing tools
like cabal, which tried to compensate by special-case code), this 
complicated the process of installing headers and libraries used 
by FFI bindings, at least for those windows users who didn't build 
their own GHCs, with the help of a full GCC install.


And so on..

Listen to the complaints, there is (usually) a real issue behind them.

A couple more examples of why installing the tools that some 
cabal packages rely on isn't straightforward: 

I like and use cygwin, but when installing it, one has to be careful to 
include all the bits that are needed, preferably leaving out the bits that 
might cause confusion when used for GHC/Cabal (such as a second 
GCC installation). I once tried to capture the list of dependencies 
needed for building GHC in a cygwin pseudo-package (no contents, 
only dependencies), which made that easy. 


http://www.haskell.org/pipermail/cvs-ghc/2005-May/025089.html
http://hackage.haskell.org/trac/ghc/wiki/Building/Windows/Cygwin

But then cygwin's installer added security signatures, and I don't
think such were ever added to the pseudo-package, the dependencies
are also not uptodate anymore (I don't have write access to where it 
was put). Nowadays, one could put the cygwin pseudo-package into 
a cabal package on hackage, including the necessary signature, and 
that cabal package could run the cygwin installer with the dependencies 
given in the cygwin package (assuming there's a commandline interface 
to the cygwin installer) or at least users could run the cygwin installers
with an updated version of that cygwin package, and get a cygwin 
setup useable for cabal packages.


Others like msys, but for some reason the msys developers hardly
ever put up a simple installer, one usually has to collect various
bits and pieces in the right version, then unpack them on top of
each other - very far from automated one-click installation. Simon
recently collected the pieces needed for building GHC, so one
could now point windows users to 


http://hackage.haskell.org/trac/ghc/wiki/Building/Preparation/Windows

for one-stop shopping. One could probably do better by 
collecting those pieces into a cabal package (assuming the

license is favourable), but I could never find documentation
for using the mingw/msys installers from the commandline,
as a cabal package would need to do. Someone familiar
with those installers might not find this difficult.

Improving Cabal to replace autoconf is a nice long-term goal,
but in the meantime, things could be made a lot easier for
those windows users. GHC using the standard layout for
its GCC is one step, packaging up the msys and cygwin
dependencies would make it straightforward to install those
correctly (someone with installer knowledge might even
be able to automate that from the cabal commandline..).

Then windows users could easily install either msys or
cygwin, and the remaining issue would be how to install
the headers and libraries for cabal packages with ffi 
bindings. Just as on other platforms.


Claus

PS. Don't think of them and they vs we and us 
   and our software. It doesn't help. Neither does

   classifying bug reports as complaints.

-- It is not that we think of other as bad,
-- it is that we think of bad as other.


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


[Haskell-cafe] swish - semantic web in Haskell

2009-04-30 Thread Vasili I. Galchin
Hello,

 http://www.ninebynine.org/Software/swish-0.2.1.html    I am trying
to get permission from the author of Swish to move it into Hackage. I will
write cabalize it get up to current Haskell standards. Before I go to this
effort is anybody attempting to do this?

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


Re: [Haskell-cafe] Google SoC: Space profiling reloaded

2009-04-30 Thread Claus Reinke

http://socghop.appspot.com/student_project/show/google/gsoc2009/haskell/t124022468245

There's less than a month left before I'm supposed to jump into coding,
and I'd love to hear about any little idea you think would make this
project even better! I created a project page with a rough draft of what
I intend to concentrate on, but the issue tracker is obviously begging
for content, so feel encouraged to populate it. :)

http://code.google.com/p/hp2any/


Hi there,

I'm sure lots of Haskellers are looking forward to profiling improvements!-)

The wxHaskell applications page

http://wxhaskell.sourceforge.net/applications.html

mentions 


http://dready.org/projects/HPView/

which seems relevant.

Shortening the song and dance needed to get profiles would be nice
(eliminating the PS viewer dependency in the process).
So would not having to select profile type in advance (and not having
to repeat the profile runs again and again, with only one view each time).

I assume you're only going to look into visualization, not semantics?-)
http://www.haskell.org/pipermail/cvs-ghc/2008-October/045981.html

Also, there is a lot of space profiling support, but I'd sometimes like
more detailed time profiling (not just end-of-run summaries, but time
sliced profiling - in this time slice, most of the time was spent in x,
in the next time slice, most of the time was spent in y, these functions
are frequented in the beginning, but are not used towards the end, etc). 
Perhaps the recent support for code coverage could be bent to support 
something like this without too much hacking?


Keep us informed!
Claus


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


Re: [Haskell-cafe] How to install HOpenGL to Windows?

2009-04-30 Thread Duncan Coutts
On Thu, 2009-04-30 at 23:31 +0100, Claus Reinke wrote:
  The thing is, it doesn't really matter if autoconf macros work fine for
  every Unix ever invented. The Windows users simply cannot use packages
  with configure scripts. They complain about it a lot. We can call them
  foolish for not installing cygwin/mingw, but they will not do it and
  instead will simply not use our software and/or continue to complain.
 
 Windows users - that's a lot of different people to generalize over.

Yes, I was generalising. There are those users who are prepared, even
happy to install cygwin, and there's everyone else.

 From what I've heard, most complaints are about assumptions made 
 by non-windows users that turn out not to hold on windows,
 causing things to fail on windows. Which seems reason enough for
 failure reports, otherwise known as complaints.
 
 If someone wants to use a unix shell on an unknown platform, they 
 should at least check that one exists there or -even better- provide 
 one, not just assume that there'll always be one (and then be surprised 
 about getting complaints from those windows users). Same for
 autoconf, make  co.

You mean that we should be shipping a haskell platform with a full copy
of mingw + all the tools to make configure scripts run? I doubt that'll
make people happy. They'll complain about it not being native.

 If someone mixes up GCC's standard layout, they need to adjust
 everything for those changes, and when that turns out to be rather
 difficult, it is no surprise if GCC seems unable to pick the right 
 include or library paths. This particular issue has just recently been 
 fixed in GHC head, I understand (will that fix cause problems for
 cabal, btw, when the existing path hacks are no longer needed?). 
 http://hackage.haskell.org/trac/ghc/ticket/1502#comment:12
 
 Apart from causing lots of other path issues (and confusing tools
 like cabal, which tried to compensate by special-case code), this 
 complicated the process of installing headers and libraries used 
 by FFI bindings, at least for those windows users who didn't build 
 their own GHCs, with the help of a full GCC install.
 
 And so on..

In principle there is no problem with finding the mingw headers on
Windows. All we need is that the rts or base package specify them in the
include-dirs in the package registration info. Cabal uses the same info.

 Listen to the complaints, there is (usually) a real issue behind them.

I don't think the problem is that we've had a messed up mingw.

 A couple more examples of why installing the tools that some 
 cabal packages rely on isn't straightforward: 

But there is a significant number of Windows users who do not care to
install these tools at all.

Making the stuff work better for people who choose to use cygwin is
great. I have no objections to that. But the majority want stuff to
work without them having to install cygwin. In this case stuff often
means random hackage packages and many of them are using configure
scripts.

 Improving Cabal to replace autoconf is a nice long-term goal,
 but in the meantime, things could be made a lot easier for
 those windows users. GHC using the standard layout for
 its GCC is one step, packaging up the msys and cygwin
 dependencies would make it straightforward to install those
 correctly (someone with installer knowledge might even
 be able to automate that from the cabal commandline..).
 
 Then windows users could easily install either msys or
 cygwin, and the remaining issue would be how to install
 the headers and libraries for cabal packages with ffi 
 bindings. Just as on other platforms.

Making them easier to install would probably convince many Windows users
to install one of them.

 PS. Don't think of them and they vs we and us 
 and our software. It doesn't help. Neither does
 classifying bug reports as complaints.

I'm not complaining about people complaining. :-) I'd like to see things
work better on windows.

Duncan

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


Re: [Haskell-cafe] How to install HOpenGL to Windows?

2009-04-30 Thread Claus Reinke
If someone wants to use a unix shell on an unknown platform, they 
should at least check that one exists there or -even better- provide 
one, not just assume that there'll always be one (and then be surprised 
about getting complaints from those windows users). Same for

autoconf, make  co.


You mean that we should be shipping a haskell platform with a full copy
of mingw + all the tools to make configure scripts run? I doubt that'll
make people happy. They'll complain about it not being native.


The platform includes GHC, which already includes mingw (GCC)!-)

What I meant was a cabal package bundling the pieces of msys (sh,
autoconf, make,..). And, no, the haskell platform doesn't need this,
so it should be a separate package. But cabal install should know
that this package would be nice to have at hand if building a package
that uses build-type:configure on windows.


just fixed:
http://hackage.haskell.org/trac/ghc/ticket/1502#comment:12

In principle there is no problem with finding the mingw headers on
Windows. All we need is that the rts or base package specify them in the
include-dirs in the package registration info. Cabal uses the same info.


In practice, we have instructions like these circulating (these being
examples of the better kind, as they actually got things working):
http://joelhough.com/blog/2008/04/14/haskell-and-freeglut-at-last/
http://netsuperbrain.com/blog/posts/freeglut-windows-hopengl-hglut/

And I've lost count of the number of times the finding of mingw
headers or libs has caused bugs (which usually went unnoticed
on the author's machine because the author would have a full
copy of mingw in c:/mingw, where gcc looks for things when
everything else fails - oh, unless you're using ghc's gcc on d:,
when this failsafe would suddenly fail as well, until recently).

Perhaps cabal had no problems with this, but problems were plenty
and initially non-obvious. So I'm happy that this fix has eliminated one
common cause of problems with installing Haskell software on windows.
Every little bit helps.

A couple more examples of why installing the tools that some 
cabal packages rely on isn't straightforward: 


But there is a significant number of Windows users who do not care to
install these tools at all.

Making the stuff work better for people who choose to use cygwin is
great. I have no objections to that. But the majority want stuff to
work without them having to install cygwin. In this case stuff often
means random hackage packages and many of them are using configure
scripts.


If cabal can do autoconf/configure stuff without having autoconf/
configure installed, great. Someone could write SH as a Haskell 
DSEL, for starters, then replicate the autoconf stuff (its all just SH
libraries and some macro processing, right?). But I'm not optimistic 
about that in general.


There probably are windows users who don't want to have
msys or cygwin on their machine, but I suspect there are more
windows users who simply don't want to bother with msys (so
if cabal installed and used it internally, they might accept that,
just as they accept, or at least live with, GHC installing and 
using mingw internally).



Then windows users could easily install either msys or
cygwin, and the remaining issue would be how to install
the headers and libraries for cabal packages with ffi 
bindings. Just as on other platforms.


Making them easier to install would probably convince many 
Windows users to install one of them.


It would also simplify cabal package installation instructions,
and avoid the it doesn't work and it thinks it is on unix so I
don't see how it could possibly work feeling. Instead, cabal
install would simply point out another package dependency
that needs installing.

I'm not complaining about people complaining. :-) I'd like to see 
things work better on windows.


I'm not surprised!-)
Claus


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


[Haskell-cafe] Few Alex questions

2009-04-30 Thread Dimitry Golubovsky
Hi,

Q1: I am trying to create an Alex equivalent of the following flex file:

http://code.haskell.org/yc2js/es-idl/lexer.ll (lexer for Web IDL which
is a dialect of OMG IDL)

I haven't been able to find Alex equivalent for the following line:

PoundSign   ^{WhiteSpace}*#

that is any amount of whitespace at the beginning of line followed by '#'

I defined a @WhiteSpace macro some place earlier, but Alex gives me
parser error on the line I created:

@PoundSign =  ^...@whitespace*#

in the position 28 that is position of '@', next to caret, that is,
caret is not recognized by Alex.

Can beginning of line (caret) be recognized by Alex?

Q2: The original line says:

MultiLineComment\/\*(([^*])|(\*[^/]))*\*\/

basically same as comments in C or Java.

I had to prefix star and slash even within square brackets with
backslashes to make it compile.

So I got:

@MultiLineComment  =  \/\*(([^\*])|(\*[^\/]))*\*\/

Is this correct understanding that if we want to match any character
except for an asterisk, then Alex would like to see [^\*] rather than
[^*]? And [^\/] rather than [^/]?

Or would it be better to use a hex code for the asterisk and slash?

Thanks.

-- 
Dimitry Golubovsky

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


[Haskell-cafe] [tryReadAdvChan :: AdvChan a - IO (Maybe a)] problems

2009-04-30 Thread Belka

Hi!

I need this function with requirement of heavy reads, *possibly under DDoS
attack*. 
Was trying to write such function, but discovered some serious problems of 
** possible racings, 
** possible starvations 
** unbalance: readAdvChan users may get better service than ones of
tryReadAdvChan
These are totally unacceptible for my case of DDoS risk.

Actually, am I wrong thinking, that it can't be helped - and the degradation
from cute concurency synchronization model of Chan is unavoidable? 

My (untested) code:
---
---
module AdvChan ( AdvChan
   , newAdvChan
   , readAdvChan
   , writeAdvChan
   , writeList2AdvChan
   , advChan2StrictList
   , withResourceFromAdvChan
   , tryReadAdvChan
   , isEmptyAdvChan
   ) where

import Control.Concurrent.Chan
import Control.Concurrent.MVar

data AdvChan a = AdvChan { 
acInst:: MVar Chan a
  , acWrite   :: a - IO ()
  , acIsEmpty :: IO Bool
}

newAdvChan :: IO AdvChan a 
newAdvChan = do ch- newChan 
mv_ch - newMVar ch 
return AdvChan {
 acInst= mv_ch
   , acWrite   = writeChan ch
   , acIsEmpty = isEmptyChan ch
   }

readAdvChan :: AdvChan a - IO a
readAdvChan ach = modifyMVar (acInst ach) 
 (\ ch - do a - readChan ch
 return (ch, a)
 )

writeAdvChan :: AdvChan a - a - IO ()
writeAdvChan = acWrite

writeList2AdvChan :: AdvChan a - [a] - IO ()
writeList2AdvChan ach[] = return ()
writeList2AdvChan ach (h:t) = writeAdvChan ach h  writeList2AdvChan ach t

advChan2StrictList :: AdvChan a - IO [a]
advChan2StrictList ach = modifyMVar (acInst ach) 
(\ ch - let readLoop = do emp -
isEmptyChan ch
   case emp of
   True  -
return []
   False -
do _head - readChan ch
  
_rest - readLoop
  
return (_head : _rest)
  in liftTuple (return ch,
readLoop)
)

withResourceFromAdvChan :: AdvChan a - (\ a - IO (a, b)) - IO b
withResourceFromAdvChan ach f = do res - readAdvChan ach
   (res_processed, result) - f res
   writeAdvChan ach res_processed
   return result

isEmptyAdvChan :: AdvChan a - IO Bool
isEmptyAdvChan = acIsEmpty

microDelta = 50

tryReadAdvChan :: AdvChan a - IO (Maybe a)
tryReadAdvChan ach = emp2Maybeness $ do mb_inst - tryTakeMVar (acInst ach)
case mb_inst of
Nothing   - emp2Maybeness
(threadDelay microDelta  tryReadAdvChan ach)
Just chan - do emp -
isEmptyChan ch 
result - case
emp of
 
True  - return Nothing
 
False - Just `liftM` readChan ch
putMVar (acInst
ach) chan
return result
  where emp2Maybeness f = do emp - isEmptyAdvChan ach
 case emp of
 True  - return Nothing
 False - f

---
---

Later after writing my own code, and understanding the problem I checked
Hackage. Found synchronous-channels package there
(http://hackage.haskell.org/cgi-bin/hackage-scripts/package/synchronous-channels),
but it isn't any further in solving my the unbalacedness problems. 

Any suggestions on the fresh matter are welcome.
Belka.
-- 
View this message in context: 
http://www.nabble.com/-tryReadAdvChan-%3A%3A-AdvChan-a--%3E-IO-%28Maybe-a%29--problems-tp23328237p23328237.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] The Haskell Reddit is 1 year old

2009-04-30 Thread Don Stewart
Just a reminder, the Haskell Reddit is live and active:

http://www.reddit.com/r/haskell/

It is a a place for fast, daily, comprehensive news about what's going
on in the Haskell community, combining blogs, mail, irc, ghc's patches,
the freaking types@ mailing list! It's all here, with comments.

Enjoy. Contribute.

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