[Haskell-beginners] Re: Showing control characters
Russ Abbott
russ.abbott at gmail.com
Tue Nov 9 14:44:42 EST 2010
I wasn't at a computer with Haskell when I wrote the earlier message.
Here's how it seems to work.
File:
*data *MyType = MyType
*instance *Show MyType *where*
show MyType = "a\nb"
Load the above file. Then:
> MyType -- This does what I want it to do after all.
a
b
> show MyType
"a\nb"
> putStrLn (show MyType)
a
b
> print MyType
a
b
*-- Russ Abbott
_____________________________________________*
* Professor, Computer Science
California State University, Los Angeles
Google voice: 424-235-5752 (424-cell-rja)
blog: http://russabbott.blogspot.com/
vita: http://sites.google.com/site/russabbott/
_____________________________________________*
On Tue, Nov 9, 2010 at 9:40 AM, Russ Abbott <russ.abbott at gmail.com> wrote:
> Is there some way to include control characters in a Show string so that
> they take effect when the element is Shown?
>
> For example, if I define a String "a\nb" and use putStrLn on it, the \n
> causes a return, but when I simply return the string from a function, the \n
> is shown as \n. Is there a way to get the \n to execute when it's embedded
> in a returned value?
>
> Thanks
> *
> -- Russ Abbott
> _____________________________________________*
> * Professor, Computer Science
> California State University, Los Angeles
>
> Google voice: 424-235-5752 (424-cell-rja)
> blog: http://russabbott.blogspot.com/
> vita: http://sites.google.com/site/russabbott/
> _____________________________________________*
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20101109/22efcbb3/attachment.html
More information about the Beginners
mailing list