Re: re-opening a closed stdin?
"Simon Marlow" <[EMAIL PROTECTED]> writes: > It is nice, but it introduces too many problems. What happens to any > I/O errors encountered by the lazy I/O? They have to be discarded, > which means you can't effectively use lazy I/O for robust applications > anyway. Damn, I forgot that "file" means file in the real world, not Platonic file! I now agree that it is actually not nice. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: re-opening a closed stdin?
"Simon Marlow" <[EMAIL PROTECTED]> writes: > One reason, I think, is lazy I/O(*). It's to stop you accidentally [...] > (*) kill it! die! die! So you want main = readFile "/dev/zero" >> return () to terminate violantly rather than terminate peacefully? :) Seriously, I understand that the IO monad is the most intuitive and robust when it is strict. But sometimes it is also nice if one could map a file to a lazy string. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Optimisation and unsafePerformIO
"David Sabel" <[EMAIL PROTECTED]> writes: > {-# NOINLINE b #-} > > b x = if even x then unsafePerformIO getChar else bot > > bot = bot > > main = do > putChar (b 4) > putChar (b 6) I am not a compiler implementer (or lawyer, for that matter :) But I propose this guess. First, both even 4 and even 6 get constant-folded to True; so b 4 and b 6 both become unsafePerformIO getChar. Then there is a common subexpression elimination. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Docs missing?
The doc RPM package for Red Hat 7.3 suffers the same problem as the SuSE one. Could someone please give a hand-holding guide so that we can fix it ourselves? Please? Please? ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Double your monad in 30 days
Ashley Yakeley <[EMAIL PROTECTED]> writes: > Prelude> 0 * 2 > 0 We can generalize this. import Monad double_your_monad_in_30_days :: (MonadPlus M) => M a double_your_monad_in_30_days = mzero `mplus` mzero ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: i368-pc-os2-emx port
"Simon Marlow" <[EMAIL PROTECTED]> writes: > On the other hand, you'd need something like mingw for OS/2 - does > such a beast exist? The substring "emx" refers to an OS/2 version of gcc and libraries that make OS/2 look really like Unix from the programmer's point of view. (It probably even pre-dates cygwin.) I have two encouraging stories to tell. First, for a school assignment, I wrote an OpenGL program on emx, then ported it to school's Solaris+Mesa ten minutes before the deadline --- where porting meant removing "#include ". Second, I wrote a program that used tcpip sockets on Unix, then merely recompiled it on emx to use it on OS/2 as well. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Congrats to Mandrake
[EMAIL PROTECTED] (Ketil Z. Malde) writes: > I'm not sure what the point would be, if they are in the > distributions anyway? Isn't it better to install them by apt-get or > up2date or whatever? (In fact, I had almost thought manually > downloading packages a thing of the past, but then the IT department > insisted on Red Hat) If I, a developer, wrote a program, and some distributions included it (while others didn't), I would want to acknowledge and thank them in public. If I, a potential customer choosing among Linux distributions, liked to use a program, and I saw on the program home page that so-and-so distributions included the program, I would arrange my preference accordingly. If I, an absent-minded user, heard about some great program from my friends, and saw on the program home page which distributions included it, I might realize "Gosh, *my* distribution CD already has it!" and save some download and install effort. Remember, I am absent-minded, so I wouldn't know what's on my CD unless someone stick it on my face. :) I probably don't need hyperlinks; I just need to know if my distribution includes it or not. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Instances of IArray
I had looked into the source code of IArray a bit. Like you have found, (!) is not a class method. In fact, none of the claimed class methods in the doc is a class method, and no class method of IArray is documented. Instead, IArray class methods seem to pertain to implementation details (I mean, "unsafeAt"!), and user operations such as (!) are constrained polymorphic functions, e.g., (!) :: (IArray a e, Ix ix) => a ix e -> ix -> e >From the user's point of view, there is little difference between a class method and a class-constrained polymorphic function when the provided instances are abstract types. So the documentation is telling a white lie. Of course, you see the difference when you roll your own IArray instance. I think the white lie is a balance between exposition simplicity and implementation tuning. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: State Transformer
Theodore Norvell <[EMAIL PROTECTED]> writes: > Jorge's question raised a question in my mind. The IOExts > module has many of the same features as the ST module, why > are there two ways to do the same thing? Is the ST module > only there for legacy purposes? My user view is that I appreciate the presence of both. When I write a pure function that can be implemented efficiently in imperative programming, I want the ST monad to support mutable variables. E.g., to implement "f n returns a list of all primes between 2 and n", I want to use a mutable array and hide it. When I write an I/O-bound routine that can be implemented conveniently with state variables, I want the IO monad to support mutable variables. Now my grief is that I cannot write a subprogram with state variables and have it reused in ST and IO. Fortunately I can write a subprogram with mutable arrays and have it reused in ST and IO, so I can write "sort a given array"; but I cannot write "increment a given integer variable". Of course, you can tell me to use mutable arrays of length 1 to simulate mutable variables. Fine! ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: State Transformer
> > testfunc = do > >r <- newSTRef ('x',0) > >foo r > >bar r > >(c,n) <- readSTRef r > >return n Jorge Adriano <[EMAIL PROTECTED]> writes: > Yeap, I could do it like this myself :) > The whole problem is with passing the 'r' as a parameter, which is precisly > what I'm trying to avoid. I agree with you. My work-around is then to define foo and bar locally to testfunc, in the scope of r: testfunc = do r <- newSTRef ('x',0) let foo = do (c,n) <- readSTRef r writeSTRef r ('a', n+1) bar = do (c,n) <- readSTRef r writeSTRef r (c,n+2) foo bar (c,n) <- readSTRef r return n But if this looks like unsatisfactory (it does to me, too), perhaps you have to go back to DIY monads. DIY monads are good when: you fix the state variables, you don't want to mention them in subprogram parameters. The ST monad is good when: you create more state variables on the fly, you use mutable arrays, you don't want to write your own monad and put/get commands. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: State Transformer
I will just translate your example from Norvell's DIY state monad to GHC's ST monad. As you noticed, GHC's ST monad begins with an "empty" state and you use some commands to add state variables as you go. This means the translation is not straightforward. I hope you still get the gist of it. Your hunch is correct: Norvell's applyST becomes GHC's runST. Your example uses two state variables: a Char and an Int, paired up as a tuple. Below, I use one state variable of type (Char,Int) for that, as hinted by your first attempt at the translation. foo and bar will each need to take a parameter --- the reference to the state variable, due to the reference business. testfunc = do r <- newSTRef ('x',0) foo r bar r (c,n) <- readSTRef r return n foo r = do (c,n) <- readSTRef r writeSTRef r ('a', n+1) bar r = do (c,n) <- readSTRef r writeSTRef r (c,n+2) tryTestFunc = runST testfunc ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: ghc image size
Mike Gunter <[EMAIL PROTECTED]> writes: > Why is executable size a barrier? 1.64 megabytes (that's the size of > the executable I built with GHC most recently) of disk space costs less > than half a cent. I don't like this argument. Can I go to a computer store, pay a cent, and get a hard disk with space 1.64 megabytes or more? Until then, I can't believe that 1.64 megabytes of disk space costs less than half a cent. When a compiler does not perform as good as other compilers (e.g., in terms of generated code size), it is important to ask: Why does it happen? Is there anything we can do to improve it? Being critical is the first step towards progress. (Of course these questions should be asked in a constructive rather than whining way.) Why would anyone optimize code for time --- a second of electricity and labour cost less than a cent... ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Working character by character in Haskell
"Andre W B Furtado" <[EMAIL PROTECTED]> writes: [...] > For example, suppose function doSomeStuffWith returns its own parameter. > Using a 1.5MB file in this case, the Haskell program ends in almost 5 > seconds, while the C program ends in less than 0.5 seconds... Is my Haskell > program too bad implemented? (I'm using GHC 4.08-1 under a Windows 98 > platform.) I indeed think that your Haskell program is inefficient and is not a translation of your C program. It reverses a huge string, which takes not only execution time but also garbage collection time and memory, which entails even more time for OS overhead and swapping out other things in the physical memory. (Many programmers complain "my linear-time algorithm takes just 1 second on a 100M list, so why is it taking 5 seconds on a 200M list?" They forget that because of issues such as cache locality and virtual memory, their computers do not scale.) I am wondering that if doSomeStuffWith is pure-functional, why are you writing and using copyFile instead of just using map? I mean: main :: IO () main = do bmFile <- openFileEx "in.txt" (BinaryMode ReadMode) bmString <- hGetContents bmFile writeFile "out.txt" (map doSomestuffWith bmString) hClose bmFile Because both hGetContents and map are lazy and use O(1) memory, this program behaves exactly as your C program plus occasional garbage collections that don't hurt too much. In partcular, the OS will see no difference (although the cache does). ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Student Programming Projects
Consider goal-directed theorem prover (or proof checker). Two existing samples are in Lawrence Paulson's ML for the Working Programmer, and yours truly's http://www.cs.utoronto.ca/~trebla/fp/prover/index.html The advantage of mine is it illustrates monads. The advantage of Paulson's is it doesn't scare people with monads :) and it includes a substitution library (yet another monad, but shhh) for use in first-order logic. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Confused about enabling parallel ghc
I installed ghc 4.08.2 binaries for sparc solaris (and those for intel linux, too), then tried compiling a sample program (the fibonacci one in the user guide) with ghc -parallel. The compiler complained: Could not find interface file for `Prelude' in the directories ./*.hi /u/trebla/lib/ghc-4.08.2/imports/lang/*.mp_hi /u/trebla/lib/ghc-4.08.2/imports/concurrent/*.mp_hi /u/trebla/lib/ghc-4.08.2/imports/lang/*.mp_hi /u/trebla/lib/ghc-4.08.2/imports/concurrent/*.mp_hi /u/trebla/lib/ghc-4.08.2/imports/std/*.mp_hi (and similarly for Parallel.) Does it mean I must build ghc myself from source? The user guide promises a lot of binary bundles such as par. Ever since 4.0x, the ghc download page ceases to mention them. Where are they? ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users