[Haskell-cafe] Re: Language.Haskell and strings

Maurí­cio briqueabraque at yahoo.com
Sun Sep 21 21:06:17 EDT 2008


Ed, thanks for your code. However,
I need to use something that fits
inside the whole pretty-print engine.
I would like to call parseModule
in some string of Haskell code and
get it nicely typed, with those big
strings inside.

Best,
Maurício

> I'm not a Haskell expert but here the solution to your problem that I 
> can think of.
> 
> import Data.List
> 
> prettyStr :: Int -> String -> IO ()
> prettyStr maxlen str = do
>    putStr ("\"" ++ head brokenStr)
>    mapM_ (\str -> putStr ("\\\n\\" ++ str)) (tail brokenStr)
>    putStr "\"\n"
>    where brokenStr = map (snd.unzip) $ groupBy (\_ (i,_) -> i `mod` 
> maxlen /= 0) $ zip [0..] str
> 
> Ed
> 
> On Sat, Sep 20, 2008 at 4:14 PM, Maurí­cio <briqueabraque at yahoo.com 
> <mailto:briqueabraque at yahoo.com>> wrote:
> 
>     Hi,
> 
>     I'm using Language.Haskell.* and would
>     like to know if it's possible to
>     pretty-print big strings like this:
> 
>     "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
> 
>     into something like this:
> 
>     "aaaaaaaa\
>     \aaaaaaaa\
>     \aaaaaaaa\
>     \aaaaaaaa\
>     \aaaaaaaa\
>     \aaaaaaaa\
>     \aaaaaaaa"
> 
>     to respect the limit on number of
>     columns. Can you help me? Is it
>     possible to do that?
> 
>     Thanks,
>     Maurício
> 
>     _______________________________________________
>     Haskell-Cafe mailing list
>     Haskell-Cafe at haskell.org <mailto:Haskell-Cafe at haskell.org>
>     http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list