[Haskell-beginners] GHC compilation without using module Main

Andrew Pennebaker andrew.pennebaker at gmail.com
Mon Mar 7 00:03:26 CET 2011


I got -main-is to work with a single Haskell file, but it seems to have
trouble with multiple files.

$ cat scriptedmain.hs
#!/usr/bin/env runhaskell

module ScriptedMain where

meaningOfLife :: Int
meaningOfLife = 42

main :: IO ()
main = putStrLn $ "Main: The meaning of life is " ++ show meaningOfLife
$ cat test.hs
#!/usr/bin/env runhaskell

module Test where

import ScriptedMain hiding (main)

main :: IO ()
main = putStrLn $ "Test: The meaning of life is " ++ show meaningOfLife
$ ghc -o scriptedmain -main-is ScriptedMain scriptedmain.hs
$ ./scriptedmain
Main: The meaning of life is 42
$ ghc -o test -main-is Test.main test.hs scriptedmain.hs
compilation IS NOT required
ld: duplicate symbol _ZCMain_main_info in scriptedmain.o and test.o
collect2: ld returned 1 exit status

Cheers,

Andrew Pennebaker
www.yellosoft.us



On Sun, Mar 6, 2011 at 5:54 PM, Daniel Fischer <
daniel.is.fischer at googlemail.com> wrote:

> On Sunday 06 March 2011 23:32:43, Andrew Pennebaker wrote:
> > Is there a way to compile a Haskell script with a different module name
> > than Main?
> >
>
> $ ghc -main-is ScriptedMain --make ScriptedMain
>
> The -main-is flag tells GHC what to regard as Main.main.
> Give it a module name (Foo) to say main is Foo.main, a function name (bar)
> to tell it main is Main.bar or a quailfied function name (Foo.bar) to tell
> it main is function bar in module Foo.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110306/504cfced/attachment.htm>


More information about the Beginners mailing list