`show' in ghci dialogue

Neil Mitchell ndmitchell at gmail.com
Sat Jan 12 08:11:00 EST 2008


Hi Serge,

I think what you are looking for is putStr:

ghci> putStr "Test\nhere"
Test
here

Thanks

Neil

On 1/12/08, Serge D. Mechveliani <mechvel at botik.ru> wrote:
> People,
>
> I have a question about usage of `show' in the GHCi dialogue system.
>
> I introduce my user  class DShow,  trying to improve the class Show of
> Haskell-98. For example, I program
>
> ---------------------------
> class DShow a where dShow :: ShowOptions -> a -> String
> ...
> main = let listOfListPairs = [ ([1,2,3], []     ),
>                                ([4,5,6], [7]    ),
>                                ([9,8,0], [0,0,0])
>                              ]                     :: [ ([Int], [Int]) ]
>            opts = ShowOptions {verbosity      = 2,
>                                listSepator    = ", \n\n",
>                                fieldSeparator = ", \n"}
>        in
>        putStr (dShow opts listOfListPairs)
> ---------------------------
>
> Then, the command  ./Main  outputs
>
> -----------------------
> [([1, 2, 3], []),
>
> ([4, 5, 6], [7]),
>
> ([9, 8, 0], [0, 0, 0])]
> -----------------------
>
> This way of the output format control by dShow and ShowOptions is my goal.
> But the command
>
>   > main
>
> in the ghci interpreter outputs something like this:
>
> "[([1, 2, 3), []),\n\n([4, 5, 6), [7]),\n\n([9, 8, 0],\n\n[0, 0, 0])]"
>
> How can the user force  ghci  to output the same output format as in
> the case of  ./Main
> (how to interprete '\n') ?
>
> 1. If we give to the interpreter the line
>
>    > listOfListPairs
>
> , then the  ghci  dialogue system does interprete the NewLine
> characters on output as needed --
> only          for the value of  (show listOfListPairs).
> And I need it for the value of  (dShow opts listOfListPairs).
> Is there any way to substitute a user function instead of `show' in the
> ghci  output?  (and dShow has additional argument ...).
>
> 2. Which function  outputs  a string in the  ghci  dialogue system?
>    Can the user make this function to interprete the NewLine character
>    in the argument string?
>
> Thank you in advance for your explanation.
>
> -----------------
> Serge Mechveliani
> mechvel at botik.ru
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>


More information about the Glasgow-haskell-users mailing list