[Ur] int to string?

Saulo Araujo saulo2 at gmail.com
Sun Oct 9 04:04:28 EDT 2016


Hi Michael,

Your definition of int2string is fine. For example, the code

fun int2string (i : int) : string = show i

val s = int2string 10

compiles without errors. I suspect the problem is in another part of your
code. The error message suggests that you have an expression that produces
a list where something else is expected. In my experience learning
languages of the ML family, in situations like this, it helps to
type-annotate arguments and results of functions. Eventually, it also helps
to type-annotate expressions. For example

val h = 10
val t = []
val s = (h :: t) : int

Thanks to the type annotation ": int", the compiler will produce an error
saying that there is a list int where an int is required:

Expression:  Basis.Cons [int] {1 = h, 2 = t}
  Have con:  list int
  Need con:  int
Incompatible constructors
Have:  list int
Need:  int

Regards,
Saulo

On Sun, Oct 9, 2016 at 4:07 AM, Michael Rohs <
michael.rohs at hci.uni-hannover.de> wrote:

> Hi all,
>
> I have a question to a very simple problem. How to convert an integer to a
> string?
>
> This does not work:
>
> fun int2string (i : int) : string = show i
>
> Error message:
>
> /.../test.ur:19:36: (to 19:40) Unification failure
> Expression:  show [<UNIF:H::Type>] _
>   Have con:  show (list <UNIF:H::Type>)
>   Need con:  <UNIF:I::Type> -> <UNIF:J::Type>
> Incompatible constructors
> Have:  show (list <UNIF:H::Type>)
> Need:  <UNIF:I::Type> -> <UNIF:J::Type>
>
> I couldn't find anything else like Int.toString or so.
>
> Thank you very much in advance!
>
> Best,
> Michael
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20161009/b1afb20b/attachment.html>


More information about the Ur mailing list