# Values to string

**URL:** <https://discourse.ats-lang.org/t/values-to-string/386>\
**Category:** Google Group\
**Created:** [April 4, 2015, 2:27pm UTC](https://discourse.ats-lang.org/t/values-to-string/386 "2015-04-04T14:27:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [April 4, 2015, 2:27pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/1 "2015-04-04T14:27:28Z")

</div>

In haskell one can use (show x) to convert x to string , provided that x is  
showable and new datatypes can implement show for converting values of that  
type to string.

Is there _already_ some thing like _show_ in ATS that can use to convert  
to string from integer , char , bool and other types.

Thanks.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [April 5, 2015, 8:20pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/2 "2015-04-05T20:20:59Z")

</div>

I added tostring.sats and tostring.dats into ATSLIB/prelude:

> <https://github.com/githwxi/ATS-Postiats/blob/master/prelude/SATS/CODEGEN/tostring.atxt>

> <https://github.com/githwxi/ATS-Postiats/blob/master/prelude/DATS/CODEGEN/tostring.atxt>

This will be made available in the next release.

In general, a tostring\_\* function is based on its corresponding tostrptr\_\*  
function; the latter  
returns a linear string that can be freed after its use.

Here are a few short examples:

[https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude\_tostring.datsOn](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude_tostring.datsOn) Saturday, April 4, 2015 at 11:28:11 PM UTC-4, Chotu S wrote:

> Thanks for reply.
> 
> Main purpose is to have a documented uniform interface for common tasks  
> like for converting values to string , reading values from string and  
> others.
> 
> It is not like that you cannot do Haskell style of programming in ATS.
> 
> > However, you  
> > can quickly feel that such a style of programming done in ATS is rather  
> > wasteful.
> 
> Okay 🙂
> 
> On Saturday, April 4, 2015 at 11:11:02 PM UTC+5:30, gmhwxi wrote:
> 
> > As of now, the primary way to “show” a value in ATS is to call some  
> > kind of ‘fprint’ function.
> > 
> > ‘show’ in Haskell sounds like a misnomer; it should really be called  
> > ‘toString’.
> > 
> > There is a tostring (not toString) function for bool and another for  
> > char. I can gradually  
> > add such functions for other common types.
> > 
> > It is not like that you cannot do Haskell style of programming in ATS.  
> > However, you  
> > can quickly feel that such a style of programming done in ATS is rather  
> > wasteful.
> > 
> > On Saturday, April 4, 2015 at 10:27:28 AM UTC-4, Chotu S wrote:
> > 
> > > In haskell one can use (show x) to convert x to string , provided that x  
> > > is showable and new datatypes can implement show for converting values of  
> > > that type to string.
> > > 
> > > Is there _already_ some thing like _show_ in ATS that can use to  
> > > convert to string from integer , char , bool and other types.
> > > 
> > > Thanks.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [April 8, 2015, 6:54pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/3 "2015-04-08T18:54:25Z")

</div>

The kind of polymorphism involved in tostring\_val is often referred to as  
ad-hoc polymorphism  
(in contrast to parametric polymorphism).On Wed, Apr 8, 2015 at 12:24 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com)\> wrote:

> Le dimanche 5 avril 2015 22:20:59 UTC+2, gmhwxi a écrit :
> 
> > Here are a few short examples:
> > 
> > [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude\_tostring.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude_tostring.dats)
> 
> The things like `tostring_val<int>` here , is this classical generic as it  
> looks like or is this static polymorphism as I feel to guess?
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [April 8, 2015, 4:47pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/4 "2015-04-08T16:47:42Z")

</div>

I believe your guess is correct:  
[https://github.com/githwxi/ATS-Postiats/commit/28b20bc1ec78e3cf70bd2ac7ca676867a75b8c32On](https://github.com/githwxi/ATS-Postiats/commit/28b20bc1ec78e3cf70bd2ac7ca676867a75b8c32On) Wed, Apr 8, 2015 at 12:24 PM, ‘Yannick Duchêne’ via ats-lang-users \< [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com)\> wrote:

> Le dimanche 5 avril 2015 22:20:59 UTC+2, gmhwxi a écrit :
> 
> > Here are a few short examples:
> > 
> > [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude\_tostring.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude_tostring.dats)
> 
> The things like `tostring_val<int>` here , is this classical generic as it  
> looks like or is this static polymorphism as I feel to guess?
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/d7d0d222-11fd-4994-89b7-243dc9b3d6c3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

Brandon Barker  
[brandon...@gmail.com](mailto:brandon...@gmail.com)

---

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [April 5, 2015, 3:28am UTC](https://discourse.ats-lang.org/t/values-to-string/386/5 "2015-04-05T03:28:11Z")

</div>

Thanks for reply.

Main purpose is to have a documented uniform interface for common tasks  
like for converting values to string , reading values from string and  
others.

It is not like that you cannot do Haskell style of programming in ATS.

> However, you  
> can quickly feel that such a style of programming done in ATS is rather  
> wasteful.

Okay :-)On Saturday, April 4, 2015 at 11:11:02 PM UTC+5:30, gmhwxi wrote:

> As of now, the primary way to “show” a value in ATS is to call some  
> kind of ‘fprint’ function.
> 
> ‘show’ in Haskell sounds like a misnomer; it should really be called  
> ‘toString’.
> 
> There is a tostring (not toString) function for bool and another for char.  
> I can gradually  
> add such functions for other common types.
> 
> It is not like that you cannot do Haskell style of programming in ATS.  
> However, you  
> can quickly feel that such a style of programming done in ATS is rather  
> wasteful.
> 
> On Saturday, April 4, 2015 at 10:27:28 AM UTC-4, Chotu S wrote:
> 
> > In haskell one can use (show x) to convert x to string , provided that x  
> > is showable and new datatypes can implement show for converting values of  
> > that type to string.
> > 
> > Is there _already_ some thing like _show_ in ATS that can use to  
> > convert to string from integer , char , bool and other types.
> > 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![Yannick\_Duchene](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yannick\_Duchene](https://discourse.ats-lang.org/u/Yannick_Duchene)\
**Post date:** [April 8, 2015, 4:24pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/6 "2015-04-08T16:24:13Z")

</div>

> Here are a few short examples:
> 
> [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude\_tostring.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/prelude_tostring.dats)

The things like `tostring_val<int>` here , is this classical generic as it  
looks like or is this static polymorphism as I feel to guess?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [April 4, 2015, 5:41pm UTC](https://discourse.ats-lang.org/t/values-to-string/386/7 "2015-04-04T17:41:02Z")

</div>

As of now, the primary way to “show” a value in ATS is to call some  
kind of ‘fprint’ function.

‘show’ in Haskell sounds like a misnomer; it should really be called  
‘toString’.

There is a tostring (not toString) function for bool and another for char.  
I can gradually  
add such functions for other common types.

It is not like that you cannot do Haskell style of programming in ATS.  
However, you  
can quickly feel that such a style of programming done in ATS is rather  
wasteful.On Saturday, April 4, 2015 at 10:27:28 AM UTC-4, Chotu S wrote:

> In haskell one can use (show x) to convert x to string , provided that x  
> is showable and new datatypes can implement show for converting values of  
> that type to string.
> 
> Is there _already_ some thing like _show_ in ATS that can use to  
> convert to string from integer , char , bool and other types.
> 
> Thanks.
