findDefsWithType ses t modName
  = applyTP (stop_tdTP (failTP `adhocTP` inMatch)) t
      where
       inMatch (mat@(Dec (HsFunBind _ ((HsMatch loc1  pnt pats (HsBody e) ds):xs)))::HsDeclP)
         = do
              res3 <- findType pnt t 
              if res3 == [True]
                then do
                       addTypeSigDecl t Nothing ([], Nothing) True

                else do
                        -- create a type signature!
                        res <- getSig  ses modName (pNTtoName pnt)
                        
                        -- addTypeDecl  mat (Just (pNTtoPN pnt))  ([res], Nothing) True
                        
                        addTypeSigDecl t (Just (declToPName [declToName mat] mat)) ([res], Nothing) True
                        --    return [res2]
                       --     inMatch _ = fail "" 
       inMatch (dec@(Dec (HsPatBind _ pnt _ _))::HsDeclP)
         = do
              res3 <- findType (patToPNT pnt) t
              if res3 == [True]
                then
                  return dec
                else do
                  -- create a type signature!
                  res <- getSig  ses modName (pNTtoName (patToPNT pnt))
                        
                  -- addTypeDecl dec (Just (pNTtoPN (patToPNT pnt))) ([res], Nothing) True
                  addTypeSigDecl dec (Just (declToPName [declToName dec] dec)) ([res], Nothing) True

                  
                 --   return [res2]
       inMatch _ = fail ""
{- getSig ses modName name 
 = do
      let types = getTypes name ses modName
      -- error $ show types
      let types1 = cleanTypes (tail types)

      let (context, l) = getContext (head types)
      let types2 = l : types1
   --   let context2 = init context
      let types3 = map (filter (/= '\n')) types2
      let newSig = createTypeSig name context types3
     -- error $ show newSig
      
      return newSig       
getSig name ses modName
 = do
      let types = getTypes name ses modName
      let types1 = cleanTypes (tail types) -- modName

      let (context, l) = getContext (head types) -- modName
      let types2 = l : types1
   --   let context2 = init context
      let newSig = createTypeSig name context types2
     -- error $ show newSig
      
      return newSig -}


 
--createTypeSig :: String -> [String] -> [String] -> HsDeclP
findDefsWithType ses t modName
  = applyTP (stop_tdTP (failTP `adhocTP` inMatch)) t
      where
       inMatch (mat@(Dec (HsFunBind _ ((HsMatch loc1  pnt pats (HsBody e) ds):xs)))::HsDeclP)
         = do
              res3 <- findType pnt t 
              if res3 == [True]
                then do
                       addTypeSigDecl t Nothing ([], Nothing) True

                else do
                        -- create a type signature!
                        res <- getSig  ses modName (pNTtoName pnt)
                        
                        -- addTypeDecl  mat (Just (pNTtoPN pnt))  ([res], Nothing) True
                        
                        addTypeSigDecl t (Just (declToPName [declToName mat] mat)) ([res], Nothing) True
                        --    return [res2]
                       --     inMatch _ = fail "" 
       inMatch (dec@(Dec (HsPatBind _ pnt _ _))::HsDeclP)
         = do
              res3 <- findType (patToPNT pnt) t
              if res3 == [True]
                then
                  return dec
                else do
                  -- create a type signature!
                  res <- getSig  ses modName (pNTtoName (patToPNT pnt))
                        
                  -- addTypeDecl dec (Just (pNTtoPN (patToPNT pnt))) ([res], Nothing) True
                  addTypeSigDecl dec (Just (declToPName [declToName dec] dec)) ([res], Nothing) True

                  
                 --   return [res2]
       inMatch _ = fail ""
{- getSig ses modName name 
 = do
      let types = getTypes name ses modName
      -- error $ show types
      let types1 = cleanTypes (tail types)

      let (context, l) = getContext (head types)
      let types2 = l : types1
   --   let context2 = init context
      let types3 = map (filter (/= '\n')) types2
      let newSig = createTypeSig name context types3
     -- error $ show newSig
      
      return newSig       
getSig name ses modName
 = do
      let types = getTypes name ses modName
      let types1 = cleanTypes (tail types) -- modName

      let (context, l) = getContext (head types) -- modName
      let types2 = l : types1
   --   let context2 = init context
      let newSig = createTypeSig name context types2
     -- error $ show newSig
      
      return newSig -}


 
--createTypeSig :: String -> [String] -> [String] -> HsDeclP
findDefsWithType ses t modName
  = applyTP (stop_tdTP (failTP `adhocTP` inMatch)) t
      where
       inMatch (mat@(Dec (HsFunBind _ ((HsMatch loc1  pnt pats (HsBody e) ds):xs)))::HsDeclP)
         = do
              res3 <- findType pnt t 
              if res3 == [True]
                then do
                       addTypeSigDecl t Nothing ([], Nothing) True

                else do
                        -- create a type signature!
                        res <- getSig  ses modName (pNTtoName pnt)
                        
                        -- addTypeDecl  mat (Just (pNTtoPN pnt))  ([res], Nothing) True
                        
                        addTypeSigDecl t (Just (declToPName [declToName mat] mat)) ([res], Nothing) True
                        --    return [res2]
                       --     inMatch _ = fail "" 
       inMatch (dec@(Dec (HsPatBind _ pnt _ _))::HsDeclP)
         = do
              res3 <- findType (patToPNT pnt) t
              if res3 == [True]
                then
                  return dec
                else do
                  -- create a type signature!
                  res <- getSig  ses modName (pNTtoName (patToPNT pnt))
                        
                  -- addTypeDecl dec (Just (pNTtoPN (patToPNT pnt))) ([res], Nothing) True
                  addTypeSigDecl dec (Just (declToPName [declToName dec] dec)) ([res], Nothing) True

                  
                 --   return [res2]
       inMatch _ = fail ""
{- getSig ses modName name 
 = do
      let types = getTypes name ses modName
      -- error $ show types
      let types1 = cleanTypes (tail types)

      let (context, l) = getContext (head types)
      let types2 = l : types1
   --   let context2 = init context
      let types3 = map (filter (/= '\n')) types2
      let newSig = createTypeSig name context types3
     -- error $ show newSig
      
      return newSig       
getSig name ses modName
 = do
      let types = getTypes name ses modName
      let types1 = cleanTypes (tail types) -- modName

      let (context, l) = getContext (head types) -- modName
      let types2 = l : types1
   --   let context2 = init context
      let newSig = createTypeSig name context types2
     -- error $ show newSig
      
      return newSig -}


 
--createTypeSig :: String -> [String] -> [String] -> HsDeclP