Leonidas changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.1.1 released: https://ocaml.org/releases/5.1.1 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
dnh has joined #ocaml
Tuplanolla has quit [Quit: Leaving.]
tremon has quit [Quit: getting boxed in]
darchitect has quit [Quit: WeeChat 4.1.1]
average has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
waleee has quit [Ping timeout: 260 seconds]
waleee has joined #ocaml
waleee has quit [Ping timeout: 260 seconds]
jabuxas has quit [Ping timeout: 260 seconds]
waleee has joined #ocaml
rgrinberg has joined #ocaml
waleee has quit [Ping timeout: 246 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
average has quit [Quit: Connection closed for inactivity]
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
bartholin has joined #ocaml
hsw has quit [Read error: Connection reset by peer]
hsw has joined #ocaml
Serpent7776 has joined #ocaml
Square2 has joined #ocaml
rgrinberg has joined #ocaml
<discocaml> <bluddy5> There's an old tool called ocamlscript that tried to use ocaml for scripting
<discocaml> <bluddy5> I don't know if it still works. I also wouldn't try to replace python scripting with ocaml. It's just not optimized for this usecase, and you'll bump into all sorts of issues with no way out. In the context of a company that directs all their resources towards solving these problems, it may seem easy.
bartholin has quit [Quit: Leaving]
mi6x3m has joined #ocaml
<mi6x3m> hey ocaml, can I compiler an .a library with ocamlmklib without the native compiler?
azimut has quit [Ping timeout: 255 seconds]
pluviaq has quit [Ping timeout: 256 seconds]
soni_ has quit [Ping timeout: 256 seconds]
soni_ has joined #ocaml
arya_elfren has quit [Ping timeout: 256 seconds]
patrick__ has quit [Ping timeout: 256 seconds]
migalmoreno has quit [Ping timeout: 256 seconds]
patrick__ has joined #ocaml
pluviaq has joined #ocaml
migalmoreno has joined #ocaml
arya_elfren has joined #ocaml
dnh has joined #ocaml
mi6x3m has quit [Quit: Leaving]
jabuxas has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Square3 has joined #ocaml
Geekingfrog_ has joined #ocaml
Techcable_ has joined #ocaml
hexology- has joined #ocaml
masterbuilder_ has joined #ocaml
adrien_ has joined #ocaml
ski_ has joined #ocaml
infinity0_ has joined #ocaml
infinity0 has quit [Killed (erbium.libera.chat (Nickname regained by services))]
infinity0_ is now known as infinity0
Square2 has quit [*.net *.split]
masterbuilder has quit [*.net *.split]
ski has quit [*.net *.split]
Techcable has quit [*.net *.split]
hexology has quit [*.net *.split]
nore has quit [*.net *.split]
leonardus has quit [*.net *.split]
Geekingfrog has quit [*.net *.split]
adrien has quit [*.net *.split]
Techcable_ is now known as Techcable
Geekingfrog_ is now known as Geekingfrog
neiluj has joined #ocaml
wingsorc has quit [Ping timeout: 256 seconds]
nore has joined #ocaml
leonardus has joined #ocaml
Leonidas has quit [Ping timeout: 264 seconds]
Leonidas has joined #ocaml
dnh has joined #ocaml
Anarchos has joined #ocaml
<discocaml> <Ada> i’ve written ocaml scripts sometimes to run in top level just to try stuff out or process data
ski_ is now known as ski
Anarchos has quit [Ping timeout: 255 seconds]
<discocaml> <Kali> i use ocaml as a scripting language occasionally
azimut has joined #ocaml
<discocaml> <deepspacejohn> I don't use it as a general purpose scripting language but within a dune project it's very simple to define an ocaml executable and use it as a "script" to do stuff
hexology- is now known as hexology
alexherbo2 has joined #ocaml
waleee has joined #ocaml
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
dnh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
omegatron has joined #ocaml
dnh has joined #ocaml
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
czy has joined #ocaml
a51 has quit [Quit: WeeChat 4.2.1]
average has joined #ocaml
jabuxas has quit [Ping timeout: 264 seconds]
myrkraverk has joined #ocaml
Anarchos has joined #ocaml
a51 has joined #ocaml
masterbuilder_ is now known as masterbuilder
masterbuilder has quit [Changing host]
masterbuilder has joined #ocaml
<discocaml> <regularspatula> "you'll bump into all sorts of issues with no way out" <- could you elaborate on that?
a51 has quit [Quit: WeeChat 4.2.1]
a51 has joined #ocaml
jabuxas has joined #ocaml
Anarchos has quit [Quit: Vision[]: i've been blurred!]
average has quit [Quit: Connection closed for inactivity]
<discocaml> <bluddy5> Well, it's a general statement, but IMO trying an barely used use-case in a language with a small ecosystem is a recipe for trouble. But it looks like other people are doing it, so maybe it's fine.
<discocaml> <regularspatula> I guess the definition of scripting is a little hazy anyway
darchitect has joined #ocaml
<darchitect> hey guys, I am struggling to understand something to do with includes in the module system of Ocaml (maybe it's a pretty beginner question)
<darchitect> I have got the following program ->
<darchitect> module type Sig1 = sig
<darchitect> type t
<darchitect> val init : t
<darchitect> val modify : t -> t
<darchitect> end
<darchitect> module MySig1Impl : Sig1 = struct
<darchitect> type t = int
<darchitect> let init = 128
<darchitect> let modify x = x + 1
<darchitect> end
<darchitect> module MySig1 : Sig1 = MySig1Impl
<darchitect> (* --- *)
<darchitect> module type Sig2 = sig
<darchitect> include Sig1
<darchitect> val to_string : t -> string
<discocaml> <leostera> any chance you acn just link a gist?
<darchitect> end
<darchitect> module MySig2Impl : Sig2 = struct
<darchitect> include MySig1Impl
<darchitect> let to_string = Int.to_string
<darchitect> end
<darchitect> module MySig2 : Sig2 = MySig2Impl
<darchitect> and I am getting this from merlin in MySig2Impl to_string -
<darchitect> Values do not match:
<darchitect> val to_string : int -> string
<darchitect> is not included in
<darchitect> val to_string : t -> string
<darchitect> The type int -> string is not compatible with the type t -> string
<darchitect> Type int is not compatible with type t
<darchitect> any ideas why this is so ? my Sig2 is including all definitions in Sig1 then my implementation MySig1Impl implements everything AND it makes the type concrete t turns to an int. Then I include from MySig2Impl everything from MySig1Impl, this should also make t to int in MySig2Impl right ? but for some reason it doesn't :/
<darchitect> at least based off of my understanding of the type checking
<octachron> With the constraint `MySig1Impl : Sig1` you are making your implementation fits `Sig1` exactly by erasing all details from the implementation.
<discocaml> <._null._> Including and especially erasing `type t = int`
<octachron> In other words, you have asked the module system to only remember that `MySig1Impl` defines a type `t` and forget that this type `t` was an int.
<darchitect> so if I wanted to include the implementation of MySig1Impl into MySig2Impl, how would I do it so that it fits both Sig1 and Sig2 ?
<octachron> aka signature constraints actively erase information, and should not used to check that an implementation is a subtype of the signature.
<octachron> Don't use signature constraints if your aim is not to hide definitively implementation details.
<darchitect> hmm
<discocaml> <leostera> you can let t be concrete with an annotation: `Sig2 with type t = int`
<darchitect> I think I got something wrong then - I thought you could use MySig1Impl to implement Sig1 and then you have another Sig2 which is very close to Sig1 apart from a couple of functions -> then you include Sig1 into your Sig2 signature
<darchitect> but then I should be able to include some implementation of Sig1 into my Sig2 implementation right
<octachron> Your MySig1Impl implements `Sig1`, with or without the signature constraint.
<darchitect> you're right this resolves the merlin error
<discocaml> <._null._> You can use `MySig1Impl` to implement `Sig1`, but you shouldn't write ` : Sig1` (as in, hide type information) if you intend to extend it
<darchitect> but then isn't this hiding the fact that it implements Sig1 from the reader
<octachron> Not really, OCaml module system uses structural subtyping, so any module fullfills an infinite number of signatures
<discocaml> <._null._> (What signatures does the empty module fulfill besides the empty one ?)
<darchitect> do you recommend some reading not on the syntax or the rules, but more on examples of when to use what (as in best practices) ?
<darchitect> when to hide and when not to
<darchitect> when to constraint *
<discocaml> <._null._> You can constrain only at the point of use (functor applications mainly)
<octachron> Hm, right this is the other direction of the subtyping relationship. So more an exponentially increasing (with the size of the module) number of signatures.
neiluj has quit [Quit: neiluj]
<discocaml> <._null._> It will even happen without adding the type ascription
<octachron> Or when you are writing an interface file for a library module.
a51 has quit [Quit: WeeChat 4.2.1]
<discocaml> <diligentclerk> @octachron
<discocaml> <diligentclerk> Thanks for your advice the other day
<discocaml> <diligentclerk> I am using the Futhark language for a numerical computing project and I want to call it from OCaml. I am definitely getting a use-after-free segmentation fault. I shared with the Futhark maintainer the code and he said
<discocaml> <diligentclerk> > It is very strange. I can think of one reason it could happen: just before calling the Futhark entry point, after extracting the pointers from the OCaml-level array objects, the GC runs. At this point, the OCaml arrays are dead, and are garbage collected, and so the C pointers are also freed.
<discocaml> <diligentclerk> > But this would imply that using finalizers to wrap C objects in OCaml is very fragile, and must be done very carefully.
<discocaml> <diligentclerk> Do you have anything to add here about the exact order of events that stuff happens in when you use finalizers to wrap C objects? Because clearly we are having some misunderstanding about what is the correct order of operations here, what should be done first.
<discocaml> <diligentclerk> The Futhark maintainer is I think an expert in SML but not in OCaml, so he has some knowledge that crosses over but not a full understanding of how OCaml works.
<discocaml> <diligentclerk> @octachron
<discocaml> <diligentclerk> Thanks for your advice the other day
<discocaml> <diligentclerk> I am using the Futhark language for a numerical computing project and I want to call it from OCaml. (The Futhark is transcompiled to C so it is just standard OCaml to C interfacing.) I am definitely getting a use-after-free segmentation fault. I shared with the Futhark maintainer the code and he said
<discocaml> <diligentclerk> > It is very strange. I can think of one reason it could happen: just before calling the Futhark entry point, after extracting the pointers from the OCaml-level array objects, the GC runs. At this point, the OCaml arrays are dead, and are garbage collected, and so the C pointers are also freed.
<discocaml> <diligentclerk> > But this would imply that using finalizers to wrap C objects in OCaml is very fragile, and must be done very carefully.
<discocaml> <diligentclerk> Do you have anything to add here about the exact order of events that stuff happens in when you use finalizers to wrap C objects? Because clearly we are having some misunderstanding about what is the correct order of operations here, what should be done first.
<discocaml> <diligentclerk> He said
<discocaml> <diligentclerk> > In particular, the finalizer should be attached to the C pointer.
<discocaml> <diligentclerk> > And... maybe you should use a weak reference?
<discocaml> <octachron> From your description, you have a memory ownership issue.
<discocaml> <octachron> Why are the OCaml finalizers freeing C-owned memory?
<discocaml> <diligentclerk> Unfortunately I don't think I'm not the one to ask here, I was ideally hoping to just be a user of a tool which allows me to not have to think about this.
<discocaml> <diligentclerk>
<discocaml> <diligentclerk> zshipko wrote a tool https://github.com/zshipko/futhark-bindgen/tree/main which automatically generates \*.ml files with the external calls and *.mli files to provide the interface, so in an ideal world I personally would not have to understand what the right way to allocate and deallocate memory is here.
<discocaml> <diligentclerk> Is there a right way / wrong way to register C objects with the finalizer and let the garbage collector deal with the problem of when is the last time an OCaml function uses the C object?
<discocaml> <diligentclerk> He is in this server (@\zshipko) so we could just ping him for his answer. I posted an issue on the github tracker.
<discocaml> <diligentclerk> Unfortunately I don't think I'm the one to ask here, I was ideally hoping to just be a user of a tool which allows me to not have to think about this.
<discocaml> <diligentclerk>
<discocaml> <diligentclerk> zshipko wrote a tool https://github.com/zshipko/futhark-bindgen/tree/main which automatically generates \*.ml files with the external calls and *.mli files to provide the interface, so in an ideal world I personally would not have to understand what the right way to allocate and deallocate memory is here.
<discocaml> <diligentclerk> Is there a right way / wrong way to register C objects with the finalizer and let the garbage collector deal with the problem of when is the last time an OCaml function uses the C object?
<discocaml> <diligentclerk> He is in this server (@\zshipko) so we could just ping him for his answer. I posted an issue on the github tracker.
<discocaml> <diligentclerk> Unfortunately I don't think I'm the one to ask here, I was ideally hoping to just be a user of a tool which allows me to not have to think about this.
<discocaml> <diligentclerk>
<discocaml> <diligentclerk> zshipko wrote a tool https://github.com/zshipko/futhark-bindgen/tree/main which automatically generates \*.ml files with the external calls and *.mli files to provide the interface, so in an ideal world I personally would not have to understand what the right way to allocate and deallocate memory is here.
<discocaml> <diligentclerk> Is there a right way / wrong way to register C objects with the finalizer and let the garbage collector deal with the problem of when is the last time an OCaml function uses the C object?
<discocaml> <diligentclerk> He is in this server (@\zshipko) so we could just ping him for his answer. I posted an issue on the github tracker with a somewhat minimized version of the segfaulting code.
alexherbo2 has quit [Ping timeout: 250 seconds]
olle has quit [Ping timeout: 255 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
bartholin has joined #ocaml
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 252 seconds]
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
mal`` has quit [Quit: Leaving]
neiluj has joined #ocaml
mal`` has joined #ocaml
rgrinberg has joined #ocaml
rgrinberg has quit [Client Quit]
rgrinberg has joined #ocaml
olle has joined #ocaml
mima has joined #ocaml
Tuplanolla has joined #ocaml
darchitect has quit [Ping timeout: 264 seconds]
Anarchos has joined #ocaml
Square3 has quit [Ping timeout: 264 seconds]
Serpent7776 has quit [Ping timeout: 240 seconds]
jabuxas has quit [Ping timeout: 256 seconds]
darchitect has joined #ocaml
alexherbo2 has joined #ocaml
mmohammadi9812 has joined #ocaml
mmohammadi9812 has quit [Remote host closed the connection]
mmohammadi9812 has joined #ocaml
a51 has joined #ocaml
mmohammadi9812 has quit [Ping timeout: 272 seconds]
rgrinberg has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Groumf has joined #ocaml
alexherbo2 has quit [Remote host closed the connection]
justache has quit [Read error: Connection reset by peer]
justache has joined #ocaml
Anarchos has quit [Ping timeout: 252 seconds]
wingsorc has joined #ocaml
olle has quit [Ping timeout: 260 seconds]
jabuxas has joined #ocaml
bartholin has quit [Quit: Leaving]
rgrinberg has joined #ocaml
a51 has quit [Quit: WeeChat 4.2.1]