[Ur] int to string?
    Michael Rohs 
    michael.rohs at hci.uni-hannover.de
       
    Sun Oct  9 05:55:06 EDT 2016
    
    
  
Hi Saulo,
Thanks for your help. Thanks for the suggestion to add type annotations. It indeed works, but only if I don't open the List module. 
The problem appears if I add module List (even without using any of its functions).
test.urp:
$/list
test
test.ur:
open List
if I remove "open List" from test.ur it works.
I don't understand why...
Here is the full test.ur:
----------------------------------------------
(*open List*)  <-- error if uncommenting this line
fun int2string (i : int) : string = show i
val s = int2string 123
fun main () =
    let
        val stuff = "apple" :: "key" :: "goat" :: []
        fun predicate (s : string) : bool = s <> "apple"
        (* val stuff2 = List.filter predicate stuff*)
    in
        return <xml><body>
        {[s]}<br/>
          <br/>
        </body></xml>
    end
----------------------------------------------
Best,
Michael
> On 09 Oct 2016, at 10:04, Saulo Araujo <saulo2 at gmail.com> wrote:
> 
> 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
> 
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
    
    
More information about the Ur
mailing list