[Haskell-cafe] Re: Allowing hyphens in identifiers

Daniel Fischer daniel.is.fischer at web.de
Wed Dec 16 04:18:00 EST 2009


Am Mittwoch 16 Dezember 2009 07:56:26 schrieb Colin Paul Adams:
> >>>>> "Daniel" == Daniel Fischer <daniel.is.fischer at web.de> writes:
>
>     Daniel> Now, would you be interested in a transformation the other
>     Daniel> way round, so that you can read other people's code in
>     Daniel> your preferred style?
>
> I would, applied to the output of haddock, at least.

As a pre-alpha version:

------------------------------------------------------------
module Main (main) where

import Data.Char (isUpper, isLower, toLower)

main :: IO ()
main = interact unCamel

unCamel :: String -> String
unCamel ('<':cs) = '<' : inTag cs
unCamel (a:bs@(b:cs))
    | isLower a && isUpper b    = a : '_' : toLower b : unCamel cs
    | otherwise                 = a : unCamel bs
unCamel cs = cs

inTag :: String -> String
inTag ('>':cs)  = '>' : unCamel cs
inTag (a:cs)    =  a  : inTag cs
inTag []        = []
------------------------------------------------------------

Compile, run with

./unCamel < /path/to/HaddockOutput.html > /path/to/Haddock_output.html

(or whatever Windows uses to redirect stdin and stdout)
This makes a few not-well-founded assumptions about haddock's output. Try it on a couple 
of files, report bugs. If it works satisfactorily, we can add a front-end to make 
transformation easy (like, pass an input directory and an output directory on the command 
line, and it recursively copies the directory content, transforming all .html files, 
giving you a complete documentation with working links).


More information about the Haskell-Cafe mailing list