- expandStrings vs = do
- xs <- mapM expandString vs
- -- Flatten the elements of the expanded list; this is
- -- to permit substitutions for list-valued variables. e.g.,
- -- package_deps["${deps}"] where env var (say) 'deps'
- -- is "base,haskell98,network"
- return (concat (map (wordsBy (==',')) xs))
-
- -- Just for fun, keep this in the IO monad.
+ expandStrings :: [String] -> IO [String]
+ expandStrings = liftM concat . mapM expandSpecial
+
+ -- Permit substitutions for list-valued variables (but only when
+ -- they occur alone), e.g., package_deps["${deps}"] where env var
+ -- (say) 'deps' is "base,haskell98,network"
+ expandSpecial :: String -> IO [String]
+ expandSpecial str =
+ let expand f = liftM f $ expandString str
+ in case splitString str of
+ [Var _] -> expand (wordsBy (== ','))
+ _ -> expand (\x -> [x])
+