|
fixIO bug: msg#00013lang.haskell.glasgow.bugs
The code is a small modification of mine to the attribute-grammar-like (multi-pass lazy) example with recursive IO at http://www.cse.ogi.edu/PacSoft/projects/rmb/repMin.html The original code replaces every (leaf) elements in a tree by the minimum of them all, returning the new tree, while printing out the elements, in traversion order. My modification tries to also print out minimum (at each non-leaf call) the global minimum (which is lazily passed down as a value from the 'future'). Probably this should generate a "Fail: <<loop>>" at first attempt to prematurely force the global minimum (or maybe earlier). The problem is, it actually duplicates some of the other IO effects a few times, before grinding to a "Fail: <<loop>>" stop ! The files : ---- IO.hs import System.IO (fixIO) data Tree a = L a | B (Tree a) (Tree a) deriving Show -- One-pass, with IO on both passes rpMin :: Tree Int -> Int -> IO (Tree Int, Int) rpMin (L a) m = do putStr "Elem " ; print a return (L m, a) rpMin (B l r) m = do (l', ml) <- rpMin l m (r', mr) <- rpMin r m let m' = ml `min` mr putStr "LocMin " ; print m' putStr "GlobMin " ; print m -- oops ! :) return (B l' r', m') replaceMin :: Tree Int -> IO (Tree Int) replaceMin t = fmap fst $ fixIO (\ ~(t', m) -> rpMin t m) main = replaceMin (B (L 1) (L 2)) ---- linux-version Linux page-208 2.4.22-gentoo-r7 #1 Wed Mar 3 02:12:36 PST 2004 i686 AMD Athlon(tm) XP 1800+ AuthenticAMD GNU/Linux ---- ghc-version The Glorious Glasgow Haskell Compilation System, version 6.2.1 ---- commands ghc IO.hs > ghc-output 2>&1 ./a.out > output 2>&1 ---- ghc-output (see attachment) ---- output Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Elem 1 Elem 2 LocMin 1 GlobMin Fail: <<loop>> ---- (Note : The code in the attached file was not run in GHC by me, but by skew) -- Stefan Lj md9slj The infinity that can be finitely expressed is not the true infinity
Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@xxxxxxxxxxx http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [ ghc-Bugs-935017 ] double arrows causes a panic, SourceForge.net |
|---|---|
| Next by Date: | [ ghc-Bugs-935792 ] --make and -main-is don't work together, SourceForge.net |
| Previous by Thread: | [ ghc-Bugs-935017 ] double arrows causes a panic, SourceForge.net |
| Next by Thread: | RE: fixIO bug, Simon Marlow |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |