Using -fext-core without a Main function

If I have a file 'Foo.hs' that contains one line 'addOne x = x + 1', I want to run something like: ghc -c -fext-core Foo.hs to get the core version of this file. Unfortunately, when I do that, it complains that Main doesn't have a function main. And it doesn't produce the .hcr file. I tried adding -no-hs-main but that doesn't help. I can add 'main = undefined' to Foo.hs, but then the core file doesn't contain the declaration of addOne because it's not used. Any suggestions? Thanks! -h -- Hal Daume III --- me AT hal3 DOT name | http://www DOT hal3 DOT name "Arrest this man, he talks in maths." | http://nlpers.blogspot.com

The flag -fext-core is a red herring. GHC assumes any module with no
"module" declaration is actually called Main and hence insists on a
main declaration.
""""
mbolingbroke@Perihelion ~/tmp
$ ghc -c Hal.hs
Hal.hs:1:0: The function `main' is not defined in module `Main'
"""
Compile this instead:
"""
module Hal where
addOne x = x + 1
"""
Cheers,
Max
On 13 April 2010 17:38, Hal Daume III
If I have a file 'Foo.hs' that contains one line 'addOne x = x + 1', I want to run something like:
ghc -c -fext-core Foo.hs
to get the core version of this file.
Unfortunately, when I do that, it complains that Main doesn't have a function main. And it doesn't produce the .hcr file.
I tried adding -no-hs-main but that doesn't help.
I can add 'main = undefined' to Foo.hs, but then the core file doesn't contain the declaration of addOne because it's not used.
Any suggestions?
Thanks!
-h
-- Hal Daume III --- me AT hal3 DOT name | http://www DOT hal3 DOT name "Arrest this man, he talks in maths." | http://nlpers.blogspot.com _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On 04/13/10 12:48, Max Bolingbroke wrote:
The flag -fext-core is a red herring. GHC assumes any module with no "module" declaration is actually called Main and hence insists on a main declaration.
...or to be precise, it means module Main (main) where {...} ...and this is what the Haskell 98 standard requires (section 5.1). Thus, main has to be defined/imported in said module, so that it can be exported thus. (Also, GHC feels free to remove/optimize/change definitions that are not exported...) -Isaac

I suppose that does work :). Thanks! Are there any examples out there for reading in Core files using the ghc package? I can't really find anything that's up to date... -h Max Bolingbroke wrote:
The flag -fext-core is a red herring. GHC assumes any module with no "module" declaration is actually called Main and hence insists on a main declaration.
"""" mbolingbroke@Perihelion ~/tmp $ ghc -c Hal.hs
Hal.hs:1:0: The function `main' is not defined in module `Main' """
Compile this instead:
""" module Hal where addOne x = x + 1 """
Cheers, Max
On 13 April 2010 17:38, Hal Daume III
wrote: If I have a file 'Foo.hs' that contains one line 'addOne x = x + 1', I want to run something like:
ghc -c -fext-core Foo.hs
to get the core version of this file.
Unfortunately, when I do that, it complains that Main doesn't have a function main. And it doesn't produce the .hcr file.
I tried adding -no-hs-main but that doesn't help.
I can add 'main = undefined' to Foo.hs, but then the core file doesn't contain the declaration of addOne because it's not used.
Any suggestions?
Thanks!
-h
-- Hal Daume III --- me AT hal3 DOT name | http://www DOT hal3 DOT name "Arrest this man, he talks in maths." | http://nlpers.blogspot.com _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-- Hal Daume III --- me AT hal3 DOT name | http://www DOT hal3 DOT name "Arrest this man, he talks in maths." | http://nlpers.blogspot.com
participants (3)
-
Hal Daume III
-
Isaac Dupree
-
Max Bolingbroke