Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to coerce a value to a String in Pony?

Tags:

ponylang

I am trying to learn Pony, and for obvious reasons, one of the first things I want to do is print values.

However, it does not seem to work for most things, like:

env.out.print(2 + 2)

Gives the error:

Could not infer literal type, no valid types found

I also tried:

let four: U32 = 2 + 2
env.out.print(four)

But this gives an uglier error saying I need something that is a subtype of ByteSeq. Fine, but how do I get one of those?

like image 320
Renato Avatar asked Jun 10 '16 17:06

Renato


1 Answers

You'll have to convert the integer into a String.

In Pony there is an interface called Stringable which declares the function string(fmt), and a lots of classes implements that interface. Integers do for instance.

So just call .string() to convert a value in something printable.

like image 193
Nicolas Lalevée Avatar answered Oct 10 '22 14:10

Nicolas Lalevée