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)
<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