jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
Matthias247 has quit [Read error: Connection reset by peer]
prettyvanilla_ has joined #ponylang
prettyvanilla has quit [Ping timeout: 256 seconds]
prettyvanilla_ has quit [Ping timeout: 240 seconds]
prettyvanilla has joined #ponylang
prettyvanilla has quit [Ping timeout: 245 seconds]
prettyvanilla_ has joined #ponylang
prettyvanilla has joined #ponylang
prettyvanilla_ has quit [Ping timeout: 240 seconds]
mvzink_ has joined #ponylang
mvzink_ has quit [Client Quit]
Mister has joined #ponylang
Mister has left #ponylang ["Ex-Chat"]
c355e3b has quit [Quit: Connection closed for inactivity]
_whitelogger has joined #ponylang
jemc has joined #ponylang
mvzink has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
jemc has quit [Ping timeout: 240 seconds]
jemc has joined #ponylang
amclain has quit [Quit: Leaving]
tm-exa has joined #ponylang
tm-exa has quit [Quit: Textual IRC Client: www.textualapp.com]
jemc has quit [Ping timeout: 260 seconds]
mrkishi_ has quit [Ping timeout: 240 seconds]
mvzink has joined #ponylang
gornikm has quit [Ping timeout: 255 seconds]
ericbmerritt_ has quit [Ping timeout: 255 seconds]
ericbmerritt_ has joined #ponylang
gornikm has joined #ponylang
kulibali_ has joined #ponylang
kulibali has quit [Ping timeout: 240 seconds]
kulibali_ is now known as kulibali
doublec has quit [Ping timeout: 255 seconds]
doublec has joined #ponylang
killerswan has joined #ponylang
killerswan has quit [Client Quit]
zevlg has quit [Remote host closed the connection]
zevlg has joined #ponylang
_andre has joined #ponylang
c355e3b has joined #ponylang
jkleiser has joined #ponylang
jemc has joined #ponylang
jkleiser has quit []
amclain has joined #ponylang
Matthias247 has joined #ponylang
_andre has quit [Quit: leaving]
emancu has joined #ponylang
emancu has quit []
mvzink_ has joined #ponylang
mvzink_ has quit [Quit: A merry Christmas to all, and to all a good night!]
<carado> hi, is it possible to have a single object which is a sort of a generic collection, so that i could do `object.insert[String]("hello")`, `object.insert[U32](5)`, `object.contains[U32](4)`, and stuff like that ?
<carado> what I don’t want is to have to modify the code of its class each time I can a new type that it can contain values of
<SeanTAllen> not sure what you are asking
<SeanTAllen> are you saying you want it to be able to hold string and U32 at the same time?
<SeanTAllen> or that one instance holds Strings and another holds U32s?
<carado> the same instances, holds a set of String and a set of U32
<carado> and a set of Float if I suddenly want to add some Floats in the mix
<SeanTAllen> no
<SeanTAllen> you cant do that
<SeanTAllen> the only way you can do that is to make it an Any
<SeanTAllen> and then you would have to match on the Any to get it back to whatever type it might be
<SeanTAllen> and even that probably isnt what you want
<carado> it’s the closest i’ll be able to get, i think
<jemc> you can use a type union if you know ahead of time which types you're intending to mix
<jemc> it would be interesting to know more about your use case, because we might be able to suggest a more idiomatic approach
<jemc> (a type union would have many of the same issues as using `Any`)
<carado> well, what I really want to do is a generic message bus which I can hold as a single objects
<carado> it’ll have a set of hooks for various types of messages, receive messages, and route the messages appropriately.
<carado> and, I would like to be able to add a message type to my code without updating the message bus’s code
<jemc> well, if you want to use that kind of pattern, I'd suggest not having your "generic message" be a collection, but just a wrapper for a single object (with a type)
<jemc> for example you could create a class called `MyCoolMessage` that has the fields that you need for that type of message
<jemc> then, assuming you're using deeply immutable messages (`val`), you generic message wrapper could have a field of type `Any val`, which allows you to assign an instance of `MyCoolMessage val` to it
<jemc> in your receiving code, you'd do a `match` statement where one of the clauses matched for the type `MyCoolMessage val` and handled it with the proper application logic for that type of message
<jemc> it should all work just fine, but it still might not be most idiomatic for Pony
<jemc> (depending on what you're doing at a higher level)
<carado> so all hooks take as argument to apply() an Any and do match of a single type ?
<jemc> or maybe a match including a clause for any kind of message they care about handling
<jemc> which could be just one type in a simple case
<carado> at a higher level, I’m considering using pony for a video game, in which I’d like to make some things (window, network input, keyboard input) produce messages without having to worry about who receives them (and have multiple receivers)
<jemc> here's an idea for a different approach that may be a little more idiomatic, if it works for you
<jemc> in pony, a behaviour is already a handler for an event message in a mailbox, so it seems a little bit of an anti-pattern to recreate that pattern on top of it
<jemc> that is, if I create a behaviour `be foo(a: U32, b: String)`, it's effectively already a hook for handling events of `foo` with a message object that holds a `U32` and a `String`
<jemc> the trick in your case is getting the event publishers to talk to the event subscribers without your central routing bus needing to know about every possible behaviour you might want to implement in the future
<jemc> I think you can do this with a combination of interfaces and type parameters
<jemc> let's say your message bus is called `World`
<jemc> and let's say you want to have a message type for keyboard input called `handle_keystroke` that takes a `U64` for the `key_code`
<jemc> you could create an `interface KeyboardListener be handle_keystroke(U64: key_code)`
<jemc> then from your code that actually receives the incoming keyboard events, you access the world, then use that interface as a way of refining the subscribers that you care to talk to
<jemc> for example
<jemc> `world.access_each[KeyboardListener]({(listener: KeyboardListener) => listener.handle_keystroke(99) })`
<jemc> `access_each` would be a method that loops over every listener registered in the world, uses `match` to see if it is of type `KeyboardListener`, and if so, pass it to the given lambda function
mvzink_ has joined #ponylang
<jemc> which could be a little inefficient in a very large world, but it's a decent start and there would be ways of improving performance from there
<jemc> the main point is that `KeyboardListener` is a type parameter, so the `access_each` method is generic and the `World` doesn't have to know anything about the interface you're asking for
<jemc> the idea is a bit of a variation on the "access pattern" I wrote up a while ago: https://github.com/ponylang/pony-patterns/blob/master/async/access.md
<jemc> the variation is that instead of an actor giving access to itself, it would be giving (external, tag) access to other actors based on their matching of the given type
<jemc> so I guess it's not really that similar :P
<jemc> if that sounds like something you'd want to try, but need help with figuring out the implementation, let me know
<carado> mmh
<carado> so `access_each` has to be called by every hook every time a message comes in just in case one of them catches it ?
<carado> i’m not really sure i get it, but i’ll read your link and see what i can figure out. anyway, thanks a lot !
<jemc> carado: `access_each` would be called by those *publishing* events
<jemc> the subscribers of events would simply receive a call to their `handle_keystroke` behaviour without having to do anything special to listen (other than registering with your `World`)