module Main
where
import System.Environment

main = do args <- getArgs -- get the list of command line arguments
          case args of -- if args has
            -- at least one element, of which the first is m, then
            (m:_) -> let n = read m -- parse the number as a string
                     -- apply the putStrLn action to each of the combinations
                     in mapM_ putStrLn (combinations n)
            -- any other number of elements (ie 0), then
            _     -> putStrLn "Give me a number"

alphanum = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']

combinations 0 = [[]] -- base case: the empty string
combinations n
    | n > 0     = [ x:xs -- prefix xs with x...
                  | x <- alphanum -- ...for each letter in alphanum...
                  , xs <- combinations (n-1) -- ...and for each string in
                                             -- combinations (n-1).
                  ]
    | otherwise = error "negative length!"

-- compile with
--  ghc -o combinations Combinations.hs
