companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 4.14.0 released: https://ocaml.org/releases/4.14.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
Fardale has quit [Quit: WeeChat 2.8]
Fardale has joined #ocaml
alexherbo2 has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
olle has joined #ocaml
perrierjouet has joined #ocaml
alexherbo2 has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
waleee has quit [Ping timeout: 260 seconds]
olle has quit [Ping timeout: 268 seconds]
olle has joined #ocaml
alexherbo2 has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
perrierjouet has quit [Quit: WeeChat 3.8]
Haudegen has quit [Ping timeout: 268 seconds]
alexherbo2 has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #ocaml
olle has quit [Ping timeout: 260 seconds]
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #ocaml
perrierjouet has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
waleee has joined #ocaml
alexherbo2 has joined #ocaml
alexherbo2 has quit [Ping timeout: 260 seconds]
waleee has quit [Ping timeout: 246 seconds]
waleee has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
jao has quit [Ping timeout: 268 seconds]
tizoc has quit [Quit: Coyote finally caught me]
tizoc has joined #ocaml
chrisz has quit [Ping timeout: 260 seconds]
chrisz has joined #ocaml
shamelessshill has joined #ocaml
<shamelessshill> Hello?
bobo has joined #ocaml
spip has quit [Read error: Connection reset by peer]
shamelessshill has left #ocaml [#ocaml]
mbuf has joined #ocaml
azimut has quit [Ping timeout: 255 seconds]
bgs has joined #ocaml
calvnce has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
trev has joined #ocaml
Serpent7776 has joined #ocaml
xd1le has joined #ocaml
bgs has quit [Remote host closed the connection]
bartholin has joined #ocaml
podge has joined #ocaml
podge has quit [Client Quit]
podge has joined #ocaml
hsw has quit [Quit: Leaving]
hsw has joined #ocaml
wingsorc has quit [Ping timeout: 252 seconds]
Haudegen has joined #ocaml
Humean has joined #ocaml
<Humean> Hello friends
<Humean> I have a question about interfaces
<Humean> To me it makes sense to define a function which takes an argument of a type that satisfies a certain interface
<Humean> But I have been struggling to figure out how to do this
<Humean> Maybe I am doing a category error with interfaces in oop vs module interfaces
<Humean> Here is an example: Let's say I am simulating a message board. Posts and Users are each represented by a module with a type t and some methods that act on that type. Both posts and users have an ID associated with them, so both modules implement a function "get_id" which takes a t and returns some id. So it makes sense to say that both modules implement a module interface that could be called "Identifiable" which has one function signature,
<Humean> ooh the other half of my message disappeared
<Humean> thats cool
mro has joined #ocaml
<vsiles> Humean: not an expert in modules or OO in ocaml, but this looks like the OO way of doing things. I don't know if ocaml modules will allow you this kind of "subtyping"
<Humean> yeah, what I want is to be able to write one function "is_same_id" that compares two arguments of type M.t (where M implements Identifiable) by calling M.get_id on each and comparing the value
<Humean> yeah i think you are right, it is too oop
<Humean> but i am trying to avoid boilerplate
<Humean> Basically trying to have a function that is parametric with a constraint on the type parameter
<Humean> that it must afford certain functions being called on it
<vsiles> out of my ocaml league, I stick to less generic code :D
<vsiles> maybe functors
<vsiles> maybe module have some kind of subtype relation ?
<Humean> yeah i think functors are somehow the answer
<Humean> modules have a duck typing thing with module signatures
mro has quit [Remote host closed the connection]
<Humean> hmm maybe you are right and it is like subtypes
<Humean> j will google "ocaml subtyping"
Humean has quit [Read error: Connection reset by peer]
mro has joined #ocaml
<octachron> You can also start by using function arguments
<vsiles> higher-order ftw
<octachron> A function of type `is_same_id: get_id:('a -> int) -> ... ` is the same as having a constraint on `'a`.
<vsiles> it's a bit verbose in the function signature, but you could even pack this in a struct (wait, OO is back now :D)
<octachron> Then you can slowly go up in complexity if your need grows:
<octachron> - record of functions (aka explicit dictionary passing)
<octachron> - object (aka structurally typed explicit dictionary passing)
Humean has joined #ocaml
<Humean> I see this post which suggests using objects as they support row polymorphism
<octachron> - packed modules (aka structurally typed record of function with different bells)
<Humean> :O
<octachron> - functors (when you need full dependent types)
<vsiles> Humean: octachron suggested a few things you can start with but you disconnected. Go read the public logs :D
Humean has quit [Read error: Connection reset by peer]
<vsiles> octachron: if you have any small examples with functors, I'm curious. I don't think I know how to do that this way
<vsiles> if you don't, nevermind, I'll try someday
Humean has joined #ocaml
<Humean> wow coreirc dcs you whenever you tab out
<Humean> ok
<Humean> ill check the logs thanks!
Humean has quit [Read error: Connection reset by peer]
Humean has joined #ocaml
<Humean> you can do this? "type 'a t = (module S with type t = 'a)
<octachron> My functor how-to (originally for numericians): If you have ever written a module with an "open M" at the top, writing a functor is just making explicit the dependency between this module and the module that you have been writing.
<Humean> and jt works if M is an interface too right
<Humean> are interface and signature synonymous
<Humean> I had it working with parametric function that took the get_id function as an argument
<Humean> I just felt it could be better
<Humean> want to do things the most OCAML way
<octachron> Signatures are interfaces for modules (if interfaces could define types and interfaces)
mro has quit [Remote host closed the connection]
<octachron> My point of view is that having a higher-order function is fine for a start.
<Humean> Yeah I agree, I got stuck on this for no reason basically
<octachron> It is easier to decide if functors or more local encoding are a better fit once you have more clients
<Humean> Thank you for your help folks
<octachron> My OCaml idiom is to first start by writing concrete types and functions, and then abstract when necessary (while being confident that the language will let me abstract many complex patterns)
<Humean> Refactoring heavy
<Humean> I guess it is important to have an ide that makes such refactorings easier
<octachron> vsiles, my most recent simple functor might be well: https://github.com/ocaml/ocaml/blob/trunk/utils/diffing.mli
Humean has quit [Read error: Connection reset by peer]
mro has joined #ocaml
podge has quit [Remote host closed the connection]
Humean has joined #ocaml
<Humean> [01:08] <octachron> vsiles, my most recent simple functor might be well: https://github.com/ocaml/ocaml/blob/trunk/utils/diffing.mli
<Humean> this is a really good ocaml example i think
<octachron> Humean, at the same time, the type system makes such refactoring straigthforward, you mostly have to fix the type errors.
<Humean> it is really well documented and the purpose is straightforward to understand
<Humean> very teachable example
Humean has quit [Read error: Connection reset by peer]
Humean has joined #ocaml
mro has quit [Remote host closed the connection]
podge has joined #ocaml
<Humean> Sorry for dc spam, I need to get a bouncer I guess
<Humean> That is true, it is not like writing a worse language that requires eternal vigilance that changes do not silently break things
<Humean> like i do at my day job
<Humean> ;)
Humean has quit [Read error: Connection reset by peer]
Humean has joined #ocaml
Humean has quit [Read error: Connection reset by peer]
bartholin has quit [Quit: Leaving]
olle has joined #ocaml
Humean has joined #ocaml
Humean has quit [Read error: Connection reset by peer]
Humean has joined #ocaml
mro has joined #ocaml
Humean has quit [Read error: Connection reset by peer]
mro has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
<zebrag[m]> <companion_cube> "zebrag: `type foo = bar = A | B..." <- Yeah, thanks
mro has quit [Remote host closed the connection]
mro has joined #ocaml
Humean has joined #ocaml
Humean has quit [Read error: Connection reset by peer]
calvnce has quit [Quit: Client closed]
troydm has quit [Ping timeout: 252 seconds]
azimut has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
calvnce has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
trev has quit [Remote host closed the connection]
mro has quit [Remote host closed the connection]
mro has joined #ocaml
Haudegen has joined #ocaml
malc has quit [Read error: Connection reset by peer]
malc has joined #ocaml
jao has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
trev has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
rgrinberg has joined #ocaml
mro has quit [Read error: Connection reset by peer]
mro has joined #ocaml
spip has joined #ocaml
bobo has quit [Ping timeout: 264 seconds]
barak has joined #ocaml
malc has left #ocaml [ERC 5.4.1 (IRC client for GNU Emacs 29.0.50)]
xd1le has quit [Quit: xd1le]
mro has quit [Remote host closed the connection]
troydm has joined #ocaml
mro has joined #ocaml
count3rmeasure has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
John_Ivan__ has joined #ocaml
rak has quit [Quit: Segmentation fault (core recycled)]
rak has joined #ocaml
John_Ivan_ has quit [Ping timeout: 248 seconds]
mbuf has quit [Quit: Leaving]
mro has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
barak has quit [Ping timeout: 260 seconds]
calvnce has quit [Quit: Client closed]
Haudegen has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
mro has quit [Read error: Connection reset by peer]
mro has joined #ocaml
mro has quit [Read error: Connection reset by peer]
podge has quit [Ping timeout: 248 seconds]
Tuplanolla has joined #ocaml
barak has joined #ocaml
trev has quit [Remote host closed the connection]
bartholin has joined #ocaml
barak has quit [Ping timeout: 256 seconds]
waleee has joined #ocaml
bgs has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
calvnce has joined #ocaml
Stumpfenstiel has joined #ocaml
deadmarshal_ has quit [Quit: IRCNow and Forever!]
deadmarshal_ has joined #ocaml
trev has joined #ocaml
wingsorc has joined #ocaml
deadmarshal_ has quit [Quit: IRCNow and Forever!]
deadmarshal_ has joined #ocaml
rgrinberg has joined #ocaml
trev has quit [Remote host closed the connection]
calvnce has quit [Quit: Client closed]
olle has quit [Ping timeout: 252 seconds]
bgs has quit [Remote host closed the connection]
count3rmeasure has quit [Quit: Leaving]
rgrinberg has quit [Ping timeout: 272 seconds]
bartholin has quit [Quit: Leaving]
Serpent7776 has quit [Ping timeout: 252 seconds]
Stumpfenstiel has quit [Ping timeout: 260 seconds]
Haudegen has quit [Ping timeout: 260 seconds]