Values to string

58 views
Skip to first unread message

Chotu S

unread,
Apr 4, 2015, 10:27:28 AM4/4/15
to ats-lan...@googlegroups.com
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.

gmhwxi

unread,
Apr 4, 2015, 1:41:02 PM4/4/15
to ats-lan...@googlegroups.com

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.

Chotu S

unread,
Apr 4, 2015, 11:28:11 PM4/4/15
to ats-lan...@googlegroups.com
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 :-)

gmhwxi

unread,
Apr 5, 2015, 4:20:59 PM4/5/15
to ats-lan...@googlegroups.com

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.dats

Yannick Duchêne

unread,
Apr 8, 2015, 12:24:13 PM4/8/15
to ats-lan...@googlegroups.com


Le dimanche 5 avril 2015 22:20:59 UTC+2, gmhwxi a écrit :

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?

Brandon Barker

unread,
Apr 8, 2015, 12:48:03 PM4/8/15
to ats-lang-users

--
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.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at 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.



--
Brandon Barker
brandon...@gmail.com

Hongwei Xi

unread,
Apr 8, 2015, 2:54:26 PM4/8/15
to ats-lan...@googlegroups.com
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> wrote:
Reply all
Reply to author
Forward
0 new messages