I have run into a baffling distinction between the behavior of GHCi and the compiled binary from GHC. I suspect it's something pretty stupid on my part. I have the following test program <test.hs> import Matrix main = let f1 = bRgauss 4 3 f2 = bRgauss 3 2 fu = f1 *. f2 in bsave "fumat" fu ---------------------------------- The type signature of bsave is -- | save a matrix to a file bsave :: String -> m -> IO() bsave str z = do k <- matindx z withCString str (\x -> bmsave x k) and bmsave is a C routine that does a simple write to disk using fprintf. If I compile using GHC and run this as test.exe it does absolutely nothing, no file is actually saved. In fact no file is saved even if I try to print components of fu in the IO monad. Whereas if I load it into GHCi and run main, everything works as expected. Well sort of. Apparently everytime I extract something out of fu and use it in an IO monad it executes all the IO actions in fu, so it's easy to get unwanted behavior with incautious use.
SevenThunders wrote:
I have run into a baffling distinction between the behavior of GHCi and the compiled binary from GHC. I suspect it's something pretty stupid on my part.
I have the following test program <test.hs> import Matrix
main = let f1 = bRgauss 4 3 f2 = bRgauss 3 2 fu = f1 *. f2 in bsave "fumat" fu ---------------------------------- The type signature of bsave is
-- | save a matrix to a file bsave :: String -> m -> IO() bsave str z = do k <- matindx z withCString str (\x -> bmsave x k)
and bmsave is a C routine that does a simple write to disk using fprintf. If I compile using GHC and run this as test.exe it does absolutely nothing, no file is actually saved. In fact no file is saved even if I try to print components of fu in the IO monad.
Whereas if I load it into GHCi and run main, everything works as expected. Well sort of. Apparently everytime I extract something out of fu and use it in an IO monad it executes all the IO actions in fu, so it's easy to get unwanted behavior with incautious use.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
OK it was stupid. Apparently GHC behaves differently according to what the name of the high level source file is. If I renamed test.hc to main.hc everything works the same as GHCi. I probably should actually read the manual some day. -- View this message in context: http://www.nabble.com/Baffled-by-Disk-IO-tf2021760.html#a5559084 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.
* SevenThunders:
OK it was stupid. Apparently GHC behaves differently according to what the name of the high level source file is. If I renamed test.hc to main.hc everything works the same as GHCi. I probably should actually read the manual some day.
Some operating systems have a "test" program, which gets called if you just enter "test". Try using "./test" and see if it makes a difference.
Yes I do have another test on my path. It is in a utilities directory of unix like commands that have been ported to windows. However I also have a test.exe that was created by ghc that seems to do nothing, even if I type ./test.exe. Thanks for the hint though. -- View this message in context: http://www.nabble.com/Baffled-by-Disk-IO-tf2021760.html#a5566155 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.
Florian Weimer wrote:
* SevenThunders:
OK it was stupid. Apparently GHC behaves differently according to what the name of the high level source file is. If I renamed test.hc to main.hc everything works the same as GHCi. I probably should actually read the manual some day.
Some operating systems have a "test" program, which gets called if you just enter "test". Try using "./test" and see if it makes a difference. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Sorry forgot to quote the original message. and my reply: Yes I do have another test on my path. It is in a utilities directory of unix like commands that have been ported to windows. However I also have a test.exe that was created by ghc that seems to do nothing, even if I type ./test.exe. Thanks for the hint though. -- View this message in context: http://www.nabble.com/Baffled-by-Disk-IO-tf2021760.html#a5566174 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.
participants (3)
-
Florian Weimer -
Matthew Bromberg -
SevenThunders