haskell - Printing two arguments -
i trying :load file "hello.hs" , keep getting errors below.
i using winghci 1.0.6.
i have printed 1 argument , worked when try print 2 arguments not in scope error shown below.
my hello.hs code contains code below.
-----------------hello.hs--------------------
module main import system.environment main :: io ( ) main = args <- getargs --getting first arg putstrln("hello," ++args!!0) args1 <- getargs putstrln("hello," ++args1!!1) --getting second arg ----------errors while trying :load command --------
hello.hs:6:37: not in scope: ‘args’ hello.hs:7:13: last statement in 'do' block must expression args1 <- getargs putstrln ("hello," ++ args1 !! 1) hello.hs:7:50: not in scope: ‘args1’ perhaps meant ‘args’ (line 5)
put putstrln command on separate line. second do not necessary (in fact, necessary not have it). additionally, should know compiler views hard tabs padding out next eight-space boundary; although things correctly indented here on so, code's mixture of tabs , spaces incorrect. recommend either using single tab @ beginning of each line in do block or converting tabs spaces. see my diatribe on tab styles. so:
main = args <- getargs --getting first arg putstrln("hello," ++args!!0) args1 <- getargs putstrln("hello," ++args1!!1) --getting second arg this smallest change needed make things work. additionally, since see no reason believe arguments change between 2 calls getargs, may omit second call , reuse args:
main = args <- getargs putstrln("hello," ++args!!0) putstrln("hello," ++args!!1)
Comments
Post a Comment