fixIO bug
Stefan Ljungstrand
md9slj at mdstud.chalmers.se
Thu Apr 15 00:19:59 EDT 2004
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghc-output
Type: application/octet-stream
Size: 14730 bytes
Desc: ghc-output
Url : http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20040415/8c258cc2/ghc-output.obj
More information about the Glasgow-haskell-bugs
mailing list