I have written code like this
import System.Environment
import Control.Exception
import Data.List
f :: String -> [String] -> IO ()
f str [] =
putStrLn "String 2"
f str (x : xs) =
putStrLn "String 1"
main :: IO ()
main = do
xs <- getArgs
let str = head xs
let xs = tail xs
f str xs
return ()
but when I compile it and trying to run I always have only answer <<loop>>
ghc run.hs
./run some_string some_over_arguments
run: <<loop>>
What's wrong with this code? I've tryed to hoogle <<loop>> but found nothing. If I pass to f not str xs but str [some_hardcoded_list] this code works fine, so I guess this is something wrong with xs.
$ ./run my_string any_argumentthis is exactly what I tiped-Wall; when you do, the compiler will warn you when these things happen. And just a by the way: instead of binding the head and then the tail you can just pattern match the_:_constructor. It's easier to write and if you do, the compiler will also warn you about the second potential problem in your code (inexhaustive pattern match -- what ifxsis[]?). And besides that incomplete functions likehead&tailare just bad :P-Wallexists in haskell.