[GHC] #1200: ghci scripts ending in printf lines fail with
Exception: Prelude.undefined
GHC
trac at galois.com
Tue Mar 6 02:56:36 EST 2007
#1200: ghci scripts ending in printf lines fail with Exception: Prelude.undefined
------------------------+---------------------------------------------------
Reporter: dons | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 6.6
Severity: normal | Keywords:
Difficulty: Unknown | Testcase:
Architecture: Unknown | Os: Unknown
------------------------+---------------------------------------------------
There appears to be some differences in runhaskell/ghci and ghc when it
comes to printf.
Consider this program:
{{{
import Text.Printf
import System.Environment
main = do
[who] <- getArgs
printf "hello, %s\n" who
}}}
when compiled:
{{{
$ ghc A.hs
$ ./A world
hello, world
}}}
When run in GHci:
{{{
$ ghci A.hs
Prelude Main> :set args world
Prelude Main> main
hello, world
*** Exception: Prelude.undefined
}}}
Hmm! And in runhaskell:
{{{
$ runhaskell A.hs world
hello, world
*** Exception: Prelude.undefined
}}}
An ugly 'return ()' seems to help:
{{{
import Text.Printf
import System.Environment
main = do
[who] <- getArgs
printf "hello, %s\n" who
return ()
}}}
which produces:
{{{
$ runhaskell A.hs world
hello, world
}}}
As does an explicit annotation:
{{{
$ cat A.hs
import Text.Printf
import System.Environment
main = do
[who] <- getArgs
printf "hello, %s\n" who :: IO ()
}}}
So some defaulting is coming into play?
{{{
$ ghci
Prelude> :l A.hs
*Main> :t main
main :: IO t
*Main> :set args world
*Main> main :: IO ()
hello, world
*Main> main :: IO String
hello, world
"*** Exception: Prelude.undefined
}}}
Is GHCi/runhaskell giving an overly generous type to 'main'? I note the
following
is also valid "runhaskell" programs:
{{{
$ cat A.hs
main = return "hello, world"
$ runhaskell A.hs
"hello, world"
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1200>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list