0

I need to get program arguments and show them

module Main ( main ) where

import System ( getArgs )

main = do

 args<-getArgs

 print $ show args

But it does nothing.Maybe my call incorrect?

>main 3 4
Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431

2 Answers2

3

It sounds like you're trying to run the program from within GHCi. In that case, you can use the :main command to run your program with arguments.

*Main> :main foo bar
"[\"foo\",\"bar\"]"
hammar
  • 138,522
  • 17
  • 304
  • 385
0

Try changing 'System' -> 'System.Environment':

module Main ( main ) where
import System.Environment ( getArgs )

main = do
  args <- getArgs
  mapM putStrLn args
barti_ddu
  • 10,179
  • 1
  • 45
  • 53
  • 1
    `ghc --make Main` and `Main.exe arg1 arg2` – barti_ddu Oct 20 '11 at 20:07
  • 1
    @Артём Царионов: guess you are calling `ghci` (interpreter), not `ghc` which is compiler... Run cmd, navigate to your source dir and execute `ghc --make Main` – barti_ddu Oct 20 '11 at 20:27
  • @Артём Царионов: anyway, you'd better import `System.Environment` (afair, ghc switched to new import locations from 7.2 completely) http://www.haskell.org/hoogle/?hoogle=getargs – barti_ddu Oct 20 '11 at 21:18
  • @Артём Царионов: in WinGhci you can compile with `:! ghc --make number6+2` – franza Oct 20 '11 at 21:23