[Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Conal Elliott
Has anyone implemented pattern-matching  substitution for
haskell-src-exts?  - Conal
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Gwern Branwen
On Wed, Jan 18, 2012 at 3:05 PM, Conal Elliott co...@conal.net wrote:
 Has anyone implemented pattern-matching  substitution for
 haskell-src-exts?  - Conal

I don't know what exactly you are looking for, but I remember banging
together a function-name search script using haskell-src-exts and
'find' last summer, which pattern-matches, looking for use of
particular function-names. Presumably you could change
`functionSearch` to not call `length` but instead replace the matched
function with another function and then write out the modules? Well,
maybe the source will be helpful, maybe not:

import System.Environment (getArgs)
import Language.Haskell.Exts
import qualified Data.Foldable as F (concat)
import Data.Generics.Uniplate.Data
-- import Debug.Trace

main :: IO ()
main = do (func:_) - getArgs
  args - fmap lines $ getContents
  mapM_ (checkAndPrint func) args

checkAndPrint :: String - FilePath - IO ()
checkAndPrint fn fs = do print fs
 x - readFile fs
 let exts = F.concat $ readExtensions x
 let parsed = parseFileContentsWithMode
(defaultParseMode { fixities = fixes, extensions = exts }) x
 case parsed of
  ParseFailed _ _ - (return ())
  ParseOk a - functionSearch fn a
 return ()

-- the default fixities augmented with everything necessary to parse my corpus
fixes :: Maybe [Fixity]
fixes = Just $ baseFixities ++ infixr_ 0 [==]

functionSearch :: String - Module - IO ()
functionSearch fun md = do
  let x = length [ () | Var (UnQual (Ident a)) - universeBi md, a == fun]
  putStrLn $ Found  ++ show x ++  occurences of function  ++ fun

-- 
gwern
http://www.gwern.net

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pattern-matching substitution for haskell-src-exts?

2012-01-18 Thread Joachim Breitner
Hi,

Am Mittwoch, den 18.01.2012, 12:05 -0800 schrieb Conal Elliott:
 Has anyone implemented pattern-matching  substitution for
 haskell-src-exts?  - Conal

without checking the code, I believe that hlint does exactly that; it
takes rules (given as Haskell code), matches them as patterns against
the real code and substitutes the matched parts in the right side of the
rule.

Greetings,
Joachim

-- 
Joachim nomeata Breitner
  m...@joachim-breitner.de  |  nome...@debian.org  |  GPG: 0x4743206C
  xmpp: nome...@joachim-breitner.de | http://www.joachim-breitner.de/



signature.asc
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe