<jtfmumm>
I'm not sure exactly what use case you're interested in, but here you could add a method to the trait and implement that method on both Parameterized and DontCareAboutGenerics (i.e. you could have them both implement the trait). That might look like: https://playground.ponylang.org/?gist=a7cbb41d318f2a72791c7c4073272ef9
<SeanTAllen>
if you have time jftmumm, that would make a great pony pattern
brainpro1 has joined #ponylang
<strmpnk>
Simulating generic type erasure. I still need to get a better handle on where traits vs interfaces work best. The differences feel too subtle to drive me to one over the other when I am writing the types which implement the concept.
droman_ has joined #ponylang
droman has quit [Ping timeout: 276 seconds]
vaninwagen has joined #ponylang
<vaninwagen>
The moment you've all been waiting for:
<alexashka>
good day, forgive my beginner question - I can do let someString: String iso = recover String end. How do I go about doing that for a boolean?
<vaninwagen>
alexashka: hi! :) a Boolean is basically always val
<alexashka>
vaninwagen: because it is a primitive? and primitives are val by default?
<vaninwagen>
yes, Bool and floats and all integers are a little special as they are represented as machine words
<vaninwagen>
whereas a String is an actual class with a size and some byte array underneath - so it can be mutable, while this is not possible for some, say Bool
<alexashka>
are classes val by default too?
<alexashka>
perhaps a better question - how do I print out the type of an object in pony ;0
<vaninwagen>
no, if you don't specify anything they are ref
<alexashka>
ok, so then why does var a: String ref = "hello" fail to compile?
<vaninwagen>
alexashka: printing a type, that is something that is not possible yet, as there is no reflection at all yet
<vaninwagen>
alexashka: yeah, let me get you the picture of class refcaps in some messages:
<vaninwagen>
you can do `class val MyImmutableClass` - this means that every variable that you declare as `MyImmutableClass` (without refcaps) will actually be `MyImmutableClass val`
<vaninwagen>
this is the default refcap
<alexashka>
ah, String is declared as class val String...
<vaninwagen>
then there is the refcap that constructors return, a constructor for `MyImmutableClass` written as: `new val create() => ...` will return you a `MyImmutableClass val`
<vaninwagen>
regardless of what the default refcap is
<vaninwagen>
so there is two places to look for
<vaninwagen>
and the constructor `String.create` returns you a `String ref` while the default refcap of String is `val`
<vaninwagen>
for most classes these are the same, but in case of String we have some special case
<vaninwagen>
usually you have String literals, that are `val` (immutable), but if you create an empty `String` via constructor, you usually want a mutable on (to append some bytes), thus it returns a `ref`
* vaninwagen
drinks a glass of water after all this talking ;)
<alexashka>
ok, so how does a beginner navigate this? I'm hoping there's a better way than looking at the implementation of every object to find out what it's refcaps will be
<vaninwagen>
the constructor `create` is `ref` by default, if no other cap is provided
<alexashka>
right. so I'm still a little lost - coming from other languages - there's a default initializer. When I go var a = String, what is being called behind the scenes here?
<vaninwagen>
if you just use the typename like in your example above, this expands to `String.create()`
<alexashka>
right, so then when would class val String, when would the val part become significant? If there's an alternate initializer that doesn't specify a refcap, it defaults to val?
<vaninwagen>
the default capability is also just sugar, os you can say `let x: String` instead of doing `let x: String val` all the time. this has nothing to do with the constructor stuff
<alexashka>
ah this is maddening, let me try another way - when I go let str = "hello", what does "hello" desugar to?
<vaninwagen>
a string literal is always a String val
<vaninwagen>
sorry for being not as helpful here, i guess i lost myself in explaining
<alexashka>
hehe I appreciate us communicating ;0
<alexashka>
I just wish the "duh" moments would be provided upfront - for instance, I have a class with a name field, I'd like to instantiate the class by passing a String to the constructor. But I want the name to be a ref. The string I'm passing in is a val, so how do I convert it to a ref?
<vaninwagen>
you know the playground? https://playground.ponylang.org/ increadibly useful for toying around and checking some questions with a quick sample
<alexashka>
ah great point, let me try that
<SeanTAllen>
you can't convert a val to a ref. that would be unsafe.
<SeanTAllen>
you can clone the val and the clone can be a ref.
<vaninwagen>
for your case above - this is actually unsafe, unless you clone the String
<vaninwagen>
yeah, hehe
<alexashka>
SeanTAllen: right that's what I'm thinking, so what's the usual pattern here? To simply clone?
<SeanTAllen>
i cant answer that as i dont really understand your case.
<vaninwagen>
SeanTAllen is actually my side kick, kicking when a default timeout hits
<SeanTAllen>
why are you passing a val instead of a ref to your constructor?
<SeanTAllen>
if you want a ref, require a ref. that would be my advice.
<SeanTAllen>
ah yeah... let someName = String.>append("Bobby") would be better for that part
<alexashka>
SeanTAllen: right, surely you'd agree creating a mutable strign should not be voodoo requiring the understanding of 5 concepts at once :)
<SeanTAllen>
¯\_(ツ)_/¯
<alexashka>
SeanTAllen: which's what your example perfectly illustrates
<SeanTAllen>
what would your suggestion be? String literals to me mutable?
<alexashka>
SeanTAllen: no no, I'd suggest having examples like the one you posted, included in the tutorial
<alexashka>
SeanTAllen: becaues currently, it's very theory heavy, very beginner hostile
<SeanTAllen>
we are open to suggestions and PR
<SeanTAllen>
saying "examples like the one I posted" doesnt help me improve the tutorial much.
<SeanTAllen>
where would that go?
<SeanTAllen>
when?
<SeanTAllen>
why?
<SeanTAllen>
if you could give more details that would be helpful
<SeanTAllen>
we have not written the tutorial to be hostile
<SeanTAllen>
i'm sorry you are struggling.
<vaninwagen>
alexashka the whole refcap type-system is very deep and needs to be to ensure safety, and this affects even the smallest part of your program. this is the steep learning curve all the veterans talk about.
<alexashka>
SeanTAllen: absolutely. I am a fan of 'explain like I'm 5' - I'd have 'here's how you do the same thing you do in Java in Pony'
<SeanTAllen>
where would you put that in the tutorial?
<alexashka>
and here's why it's different, and a little more complex, BUT you get benefit XYZ
<SeanTAllen>
its not really appropriate at the start, what if the user doesn't know java?
<vaninwagen>
I somehow got used to keeping this additional dimension in mind all the time, but it is quite a task to get into it.
<alexashka>
SeanTAllen: I think it'd be good to write one tutorial for java, and then port it to another 2-3 very popular languages
<alexashka>
to have side by side examples of here's how the very very basics are done
<vaninwagen>
But once you are able to "go with the flow", this is where the fun starts
<SeanTAllen>
we asked for folks to write "Pony for X" intros. So far no one has stepped forward.
<SeanTAllen>
its a volunteer project.
<SeanTAllen>
we all have jobs etc. so we do what we can.
<alexashka>
SeanTAllen: ya, I'd be happy to give it a try
<SeanTAllen>
i guess once folks learn it, they dont have much interest in writing a Pony for X.
<alexashka>
SeanTAllen: once I can get mutable string instantiation going :D haha
<SeanTAllen>
alexashka: if you want to tackle it, that would be great
<alexashka>
SeanTAllen: ya, I think it's a programming-wide problem, of documentation
<alexashka>
SeanTAllen: the more ppowerful the language, the worse the docs it seems, Haskell being a prime example :)
<SeanTAllen>
we have put a good amount of time into documentation. im sorry you find it lacking.
<SeanTAllen>
as someone who has spent a lot of time on documentation, it stings a little that you basically said the docs aren't good (or pony isnt very powerful).
<alexashka>
SeanTAllen: ya, I think very smart people have trouble documenting for mere mortals, it's almost incompatible
<vaninwagen>
a usual saying of haskell guys: "just follow the types" - should we put this down as "just follow the refcaps"?
<alexashka>
SeanTAllen: I think pony's very interesting - I didn't mean to hurt feelings re the documentation
<alexashka>
SeanTAllen: I think it's fair to say if you take someone who's only done OO, and isn't interested in programming language theory, they'd be utterly lost with Pony
<SeanTAllen>
alexashka: plenty of folks find the docs good and compliment them, plenty of folks have a hard time.
<SeanTAllen>
its a matter of background.
<SeanTAllen>
alexashka: plenty such folks have picked up Pony with the existing documentation.
<SeanTAllen>
people learn differently, i'm sorry you are having difficulty.
<alexashka>
ya, I hear you. I'm sorry too, I didn't mean to offend you
<SeanTAllen>
i'm not offended. writing documentation when the backgrounds of the potential audience are vast is very difficult.
<SeanTAllen>
its why 2-3 years ago i tried to get folks to write Pony for X intros but no one followed through, because of time constraints or whatever else.
<alexashka>
SeanTAllen: you're right. I'll bother the people in here with very beginner questions for a while and if I get someplace decent, I'll try a write-up that's amenable to people with my IQ :)
<alexashka>
SeanTAllen: ya, people like to write code, not documentation it seems. Very unfortunate
<SeanTAllen>
plenty of folks start work on code and end up not finishing that as well
<SeanTAllen>
i dont think your struggles are in any way reflective of IQ. learning new ideas is hard. the level of difficulty depends on what you are already familiar with. that has nothing to do with IQ.
<SeanTAllen>
if you wanted to write a Pony for Java Programmers, that would be great.