[Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Lennart Augustsson
Adrian Hey wrote: Why are top level IORefs any worse than other IORefs (for example)? Because global variables are just BAD. They have been considered bad a long time, it's not a Haskell thing. If you really grok the functional way of doing things there should be *very*, *very* few times you need

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Lennart Augustsson
Adrian Hey wrote: 4- They already exist (stdin,stout,stderr) and I don't recall anybody ever complaining about this. stdin, stdout, and stderr are not global variables. They are just handles. One possible implementation of handles is as an Int. So stdin is no more a global variable than 0.

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Lennart Augustsson
Keean Schupke wrote: Adrian Hey wrote: The first step to solving a problem is to at least recognise that it exists. What is bizarre is that so many folk seem to be in denial over this. Perhaps you would like to show me your solution to the oneShot problem. Why are you unable to give a concrete

RE: [Haskell-cafe] Making MVar and Chan Instances of Typeable

2004-11-08 Thread Simon Peyton-Jones
| instance Typeable a = Typeable (MVar a) where | typeOf x = | mkAppTy (mkTyCon Control.Concurrent.MVar.MVar) [typeOf (undefined::a)] As I think you now know, the above declaration is fine if you use -fglasgow-exts. Haskell 98 does not support lexically scoped type variables, but GHC

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Jules Bean
On 8 Nov 2004, at 12:23, Lennart Augustsson wrote: Adrian Hey wrote: 4- They already exist (stdin,stout,stderr) and I don't recall anybody ever complaining about this. stdin, stdout, and stderr are not global variables. They are just handles. One possible implementation of handles is as an

Re: [Haskell-cafe] Dynamic Type Contruction

2004-11-08 Thread Ralf Laemmel
Vitor, That's amazing!!! Your question is very timely! :-) You know ... someone just challenged me with this question, and I added the corresponding function to the boilerplate testsuite. However, it is much more typeful than you propose. I call it the typeful reflection benchmark.

[Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Keith Wansbrough
[posted to haskell-cafe per SLPJ's request] Hi Adrian, I can assure you that for the intended applications of oneShot it is vital that realInit is executed once at most, but the user must [..] So please, no more handwaving arguments about this kind of thing being unnecessary, bad programming

[Haskell-cafe] Currying and errors

2004-11-08 Thread Graham Klyne
I just found myself writing a function that looked like this: isSubsumedByWith :: TBox c - c - c - Bool isSubsumedByWith [] c d = isALSubsumedBy c d isSubsumedByWith _ _ _ = error TBox reasoning not supported for AL and immediately noticed that I might also write this:

[Haskell-cafe] FiniteMap-like module for unordered keys?

2004-11-08 Thread Graham Klyne
Is there a module that provides functionality similar to that of Data.FiniteMap for keys that do not have a defined ordering relation? (I looked at Data.HashTable, but I couldn't figure why it needs to be implemented in the IO monad, except to optimize the internal implementation. Also, it's

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Adrian Hey
On Monday 08 Nov 2004 3:57 pm, Keith Wansbrough wrote: [posted to haskell-cafe per SLPJ's request] Hi Adrian, I can assure you that for the intended applications of oneShot it is vital that realInit is executed once at most, but the user must [..] So please, no more handwaving

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Keean Schupke
Adrian Hey wrote: The problem is simple enough to restate for anyone who's interested. Provide a simple reliable mechanism to ensure that in a given program run one particular top level IO operation cannot be executed more than once. No language can guarantee this - all I have to do is run 2

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Keith Wansbrough
Adrian Hey writes: The problem is simple enough to restate for anyone who's interested. Provide a simple reliable mechanism to ensure that in a given program run one particular top level IO operation cannot be executed more than once. Can you give one concrete example of an intended

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Robert Dockins
As a purely practical matter, it seems like the easiest solution (to this particular use case) is to write a small wrapper initializer in C which is idempotent, then use FFI to call the wrapper, rather than calling the initialization directly. This is easy enough to do with a static local

Re: [Haskell-cafe] Currying and errors

2004-11-08 Thread Marcin 'Qrczak' Kowalczyk
Graham Klyne [EMAIL PROTECTED] writes: isSubsumedByWith :: TBox c - c - c - Bool isSubsumedByWith [] c d = isALSubsumedBy c d isSubsumedByWith _ _ _ = error TBox reasoning not supported for AL and immediately noticed that I might also write this: isSubsumedByWith

[Haskell-cafe] IO and State (was Re: [Haskell] Re: Global Variables and IO initializers)

2004-11-08 Thread Iavor S. Diatchki
Hello, Just wanted to point out that the suggested idea is not quite correct. (well that has to be quantiifed a bit, see bellow) Krasimir Angelov wrote: --- Ben Rudiak-Gould [EMAIL PROTECTED] wrote: This is solved by merging the IO and ST monads, something that ought to be done anyway:

[Haskell-cafe] Hal Daume III's NewBinary now ghc6ized, cabalized, debianize, darcsized.

2004-11-08 Thread Jeremy Shaw
Hello, I am quite interested in having better Binary support in Haskell -- especially support for reading and writing binary files and protocols that have fields smaller than 8-bits and non-byte alignment. As a first step, I have republished Hal Daume III's NewBinary package in hopes that it

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Keean Schupke
Just to add a small point... you can see how the 'bad' single context design affects the code that uses it. Because C allows global variables it is possible to write libraries that require once-and-only-once initialisation. In Haskell (without global variables) it is impossible (or at least

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and IO initializers

2004-11-08 Thread Adrian Hey
On Monday 08 Nov 2004 12:14 pm, Lennart Augustsson wrote: Adrian Hey wrote: Why are top level IORefs any worse than other IORefs (for example)? Because global variables are just BAD. Who said anything about global? If you really grok the functional way of doing things there should be

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and =?iso-8859-1?q?IO initializers?=

2004-11-08 Thread Adrian Hey
On Monday 08 Nov 2004 10:37 am, Keean Schupke wrote: Adrian Hey wrote: The first step to solving a problem is to at least recognise that it exists. What is bizarre is that so many folk seem to be in denial over this. Perhaps you would like to show me your solution to the oneShot problem.

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables =?iso-8859-1?q?and IO initializers?=

2004-11-08 Thread Adrian Hey
On Monday 08 Nov 2004 12:26 pm, Lennart Augustsson wrote: Keean Schupke wrote: Adrian Hey wrote: The first step to solving a problem is to at least recognise that it exists. What is bizarre is that so many folk seem to be in denial over this. Perhaps you would like to show me your

[Haskell-cafe] Re: Global Variables and IO initializers

2004-11-08 Thread Peter Simons
Adrian Hey writes: I don't see any value in problems that are specifically designed so that they can be solved only with a global entity. Even if it was true that I had specifically designed this problem, it's existance is of some interest I think. Perhaps my choice of words wasn't

Re: [Haskell-cafe] Re: Global Variables and IO initializers

2004-11-08 Thread jeff
Quoting Peter Simons [EMAIL PROTECTED]: Just ask the C++ folks about the wonders of global variables that are actually complex classes with a constructor and a destructor. You can't use that as an argument against global variables in other languages. -- Jeff

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and =?utf-8?q?IO initializers?=

2004-11-08 Thread Keean Schupke
Yes I didn't read your specification accurately... However I would argue such a constraint on the problem domain is artificial as operating systems exist. At the end of the day it is the job of the OS to manage such one-shot hardware inits, not application code. (As the OS is the only thing that

RE: [Haskell-cafe] Re: Processing of large files

2004-11-08 Thread Simon Marlow
John Goerzen writes: Yes it does. If you don't set block buffering, GHC will call read() separately for *every* single character. (I've straced stuff!) This is a huge performance penalty for large files. It's a lot more efficient if you set block buffering in your input, even if

Re: [Haskell-cafe] Re: Global Variables and IO initializers

2004-11-08 Thread jeff
Quoting Peter Simons [EMAIL PROTECTED]: jeff writes: Just ask the C++ folks about the wonders of global variables that are actually complex classes with a constructor and a destructor. You can't use that as an argument against global variables in other languages. Why not? So

Re: [Haskell-cafe] Global Variables and IO initializers

2004-11-08 Thread Ben Rudiak-Gould
I think the broad issue is that there are many different levels of the system at which something can be global: a module, a thread, a process, a user, a computer, a network segment, the internet, the universe, etc.. If your model of a concept is more global than the concept itself, you lose

Re: [Haskell-cafe] Global Variables and =?utf-8?q?IO=09initializers?=

2004-11-08 Thread Benjamin Franksen
On Tuesday 09 November 2004 03:18, Ben Rudiak-Gould wrote: Adrian Hey's example of a badly-written C library is one. But I agree with Robert Dockins that such cases are better solved in C than in Haskell. Yes. Your code won't depend on compiler (dependent) flags to disable optimizations, which

Re: [Haskell-cafe] Re: [Haskell] Re: Global Variables and whatever

2004-11-08 Thread Adrian Hey
On Monday 08 Nov 2004 9:53 pm, Keean Schupke wrote: What did you think of the code example given where the one-shot nature is provided by a 'C' wrapper around the FFI function. I think this is the best solution... As a pragmatic solution to this (and only this) particular problem it's OK. But