title: Haskell: Trapped in IO monad
body: <p>I am trying to parse a file using the <code>parseFile</code> function found in the the <code>haskell-src-exts</code> package.</p>
  <p>I am trying to work with the output of <code>parseFile</code> which is of course <code>IO</code>, but I can't figure out how to get around the <code>IO</code>.  I found a function <code>liftIO</code> but I am not sure if that is the solution in this situation.  Here is the code below.</p>
  <pre><code>import Language.Haskell.Exts.Syntax
  import Language.Haskell.Exts 
  import Data.Map hiding (foldr, map)
  import Control.Monad.Trans
  
  increment :: Ord a =&gt; a -&gt; Map a Int -&gt; Map a Int
  increment a = insertWith (+) a 1
  
  fromName :: Name -&gt; String
  fromName (Ident s) = s
  fromName (Symbol st) = st
  
  fromQName :: QName -&gt; String
  fromQName (Qual _ fn) = fromName fn
  fromQName (UnQual n) = fromName n
  
  fromLiteral :: Literal -&gt; String
  fromLiteral (Int int) = show int
  
  fromQOp :: QOp -&gt; String
  fromQOp (QVarOp qn) = fromQName qn
  
  vars :: Exp -&gt; Map String Int
  vars (List (x:xs)) = vars x
  vars (Lambda _ _ e1) = vars e1
  vars (EnumFrom e1) = vars e1
  vars (App e1 e2) = unionWith (+) (vars e1) (vars e2)
  vars (Let _ e1) = vars e1
  vars (NegApp e1) = vars e1
  vars (Var qn) = increment (fromQName qn) empty
  vars (Lit l) = increment (fromLiteral l) empty
  vars (Paren e1) = vars e1
  vars (InfixApp exp1 qop exp2) = 
                   increment (fromQOp qop) $ 
                       unionWith (+) (vars exp1) (vars exp2)
  
  
  
  match :: [Match] -&gt; Map String Int
  match rhss = foldr (unionWith (+) ) empty 
                      (map (\(Match  a b c d e f) -&gt; rHs e) rhss)
  
  rHS :: GuardedRhs -&gt; Map String Int
  rHS (GuardedRhs _ _ e1) = vars e1
  
  rHs':: [GuardedRhs] -&gt; Map String Int
  rHs' gr = foldr (unionWith (+)) empty 
                   (map (\(GuardedRhs a b c) -&gt; vars c) gr)
  
  rHs :: Rhs -&gt; Map String Int
  rHs (GuardedRhss gr) = rHs' gr
  rHs (UnGuardedRhs e1) = vars e1
  
  decl :: [Decl] -&gt; Map String Int
  decl decls =  foldr (unionWith (+) ) empty 
                       (map fun decls )
      where fun (FunBind f) = match f
            fun _ = empty
  
  pMod' :: (ParseResult Module) -&gt; Map String Int
  pMod' (ParseOk (Module _ _ _ _ _ _ dEcl)) = decl dEcl 
  
  pMod :: FilePath -&gt; Map String Int
  pMod = pMod' . liftIO . parseFile 
  </code></pre>
  <p>I just want to be able to use the <code>pMod'</code> function on the output of <code>parseFile</code>.</p>
  <p>Note that all the types and data constructors can be found at <a href="http://hackage.haskell.org/packages/archive/haskell-src-exts/1.13.5/doc/html/Language-Haskell-Exts-Syntax.html" rel="nofollow noreferrer">http://hackage.haskell.org/packages/archive/haskell-src-exts/1.13.5/doc/html/Language-Haskell-Exts-Syntax.html</a> if that helps.   Thanks in advance!</p>