<Fardale>
And this is your file not how you compile it
steenuil has joined #ocaml
mxns has quit [Ping timeout: 244 seconds]
<mrvn>
When I write "let a = 10 in let b = 20 in let foo x = a * x + b in foo how does ocaml store a and b? Can't be on the stack of the current function since foo captures them and foo is returned. Are they copied into the function object for foo?
steenuil has quit [Ping timeout: 260 seconds]
<mrvn>
What if it's "let a = ref 10 in..."? Can't just make a copy of the ref there.
<d_bot>
<ggole> In general free variables of `foo` are copied into the closure of `foo`
<d_bot>
<ggole> But there are optimisations to avoid that for things like constants
steenuil has joined #ocaml
<mrvn>
And refs are records with a mutable field so they are heap allocated. And then the pointer to the record would be copied into the closure same as any heap pointer.
<mrvn>
Why did I think a ref would be a local variable?
<d_bot>
<ggole> Yep, pretty much
<d_bot>
<ggole> Well, there is an optimisation for refs that don't escape which turns them into local variables
<d_bot>
<ggole> Perhaps you half-remembered that?
<mrvn>
sure. but that's all covered under the "behaves as if" optimization rule.
<d_bot>
<ggole> Indeed
<mrvn>
In the above obviously any optimizer would inline the literal constants.
<d_bot>
<ggole> There's also a trick where top-level variables aren't put into closures, but instead loaded from a global slot
<d_bot>
<ggole> But it didn't seem like that was what your question was really about.
<mrvn>
No. for global variables the lifetime is infinite so they can be just used in-place.
borne has joined #ocaml
<mrvn>
I was pondering the problem that you could have "let a = ... let foo x () = ... a ... in modify a". But a is either a concrete value that's immutable, a pointer into the heap or a naked pointer from some C bindings (that really shouldn't exist).
<mrvn>
a can always be copied without problems.
<mrvn>
the "modify" will always change something a points to, never a itself.
<d_bot>
<ggole> Yep
mxns has joined #ocaml
<d_bot>
<ggole> In some languages with first-class functions and mutable variables (eg, Scheme) you do have that problem, which is usually addressed with assignment conversion
<mrvn>
or c++
<d_bot>
<ggole> In which variables which are assigned get turned into refs, and then it's pretty much the same from there
<d_bot>
<jktuglu> @ggole do you have any insights to my question?
<mrvn>
jktuglu: YOu still haven't shown how you compile your code
<mrvn>
cohttp-lwt-unix probably already links to Cohttp so you get that implicitly.
<d_bot>
<jktuglu> so wouldnt I have to add Lwt for it to work as well?
<d_bot>
<jktuglu> ah okay
<mrvn>
same for lwt.
<Guest268>
I am new here..guys
<Guest268>
what is the first things do i need to do??????\
<mrvn>
make coffee
<Guest268>
any body who can help
<d_bot>
<ggole> It's hard to know which modules are included in what without having used those libraries before
<Guest268>
??????
<mrvn>
My philosophy is to not rely on any implicit stuff. If you use LWT then link against LWT explicitly. If you use Unix, link against it. If it's already included implicitly nothing bad happens. But if it's missing then it won't link.
<d_bot>
<jktuglu> Library "cohttp-lwt-unix," not found.
<d_bot>
<jktuglu> from
<mrvn>
And in the future the implicitl stuff might change and your code would suddenly fail.
<d_bot>
<ggole> That looks like the source of the dune file
<Fardale>
@jktuglu just a space to have a list of libraries for example (libraries result bytes conduit mirage-time mirage-clock cstruct uri)
<Fardale>
so in your case you will need something like "(libraries cohttp-lwt-unix conduit-lwt)"
<mrvn>
jktuglu: by the way: Conduit_lwt.TCP.sockaddr in that record makes no sense. 1) you already opened Conduit_lwt so it would be just TCP.sockaddr. But next line you have just "capacity". That would have to be Conduit_lwt.TCP.capacity as well.
<mrvn>
s/But/2) But/
<mrvn>
Maybe the error is just that Conduit_lwt.TCP has no record with a label sockaddr.
<d_bot>
<jktuglu> okay this is boiler from the cohttp website
<d_bot>
<jktuglu> so I assumed there was nothing wrong with logic
<d_bot>
<Drup> Guys guys, I need a new stupid side project
<d_bot>
<Drup> preferably with some type wizardery
<d_bot>
<Drup> or some regex
<d_bot>
<Drup> Please submit your demands for type wizardery
mxns has quit [Ping timeout: 272 seconds]
<Fardale>
@jktuglu I did try on my side and I got a different error
<d_bot>
<theangryepicbanana> > or some regex
<d_bot>
<theangryepicbanana> @Drup make a textmate/editor grammar lol
<d_bot>
<theangryepicbanana> plenty of regex to go around there
<d_bot>
<Drup> heh, just use this new thingy that has grammars for all the languages in the universe
<d_bot>
<theangryepicbanana> x to doubt
<d_bot>
<jktuglu> what is your file setup?
<d_bot>
<jktuglu> fardale^
<Fardale>
just the line of the error in server_example.ml and your dune file
<d_bot>
<joris> It is probably not your kind of hype and not type wizardery enough for you. But I get more and more and more the feeling that lwt monad is not the right abastraction for concurrency to write middleware / rest servers. When you think about it monad are only useful to implement the logic of ios but everything in between is just some computation graph non blocking that needs to be efficiency scheduled as some kind of bfs and properly
<d_bot>
<joris> @theangryepicbanana why text mate. Treesitter... It supports ocaml but not text object yet
<d_bot>
<theangryepicbanana> by textmate I mean like anything that supports textmate-style grammars
<d_bot>
<Drup> @joris that's kinda solved by multicore ocaml though
<d_bot>
<theangryepicbanana> treesitter seems unorganized and I can't find docs for it
<d_bot>
<joris> @Drup right
<d_bot>
<ostera> @Drup i'd like untagged union types
<d_bot>
<Drup> not happening, inference is a mess for that
<Fardale>
@jktuglu with your source file and your dune file it does compile
<d_bot>
<joris> @theangryepicbanana I'm using tree sitter grammar in neovim for a month it works fine
<d_bot>
<theangryepicbanana> docs though?
<d_bot>
<joris> But it is missing queries for text objects
<d_bot>
<ostera> 😦
<d_bot>
<ostera> 😢
<d_bot>
<Drup> Also, I meant *library-level* type wizardery. Type-system improvements are not done on my spare times, I do enough of them on my work time
<d_bot>
<ostera> ah okay!
<d_bot>
<theangryepicbanana> I actually make textmate grammars for fun, so it's definitely interesting to me
<d_bot>
<ostera> @Drup how about a toolkit for building data pipelines
<d_bot>
<Drup> eh, I claim incomptence on data pipelines
<Fardale>
So I don't know where the problem is, but not on those two
<d_bot>
<jktuglu> fardale I will try now
<d_bot>
<ostera> how about an embeddable ocaml interpreter, a-la lua
<mrvn>
Drup: how about bitfiels for cstruct?
<d_bot>
<jktuglu> fardale same error
<d_bot>
<joris> @Drup typed css dsl when?
<d_bot>
<jktuglu> ```Info: Creating file dune-project with this contents:
<d_bot>
<jktuglu> | (lang dune 2.7)
<d_bot>
<jktuglu> File "server_example.ml", line 18, characters 6-30:
<Fardale>
I don't know, it does work on my computer
<d_bot>
<Drup> mrvn: what do you have in mind ?
berberman has quit [Ping timeout: 272 seconds]
<d_bot>
<jktuglu> what are your opam versions?
berberman_ has joined #ocaml
<d_bot>
<jktuglu> you said you dont use dune?
<d_bot>
<joris> I don't have concrete idea. The main missing thing is to implement proper rules merging (currently the only lib that works well is finding to js lib) but I assume it is pretty boring
<mrvn>
Drup: some form of ppx extension that lets you specify bitfiles like in C and get an identical result.
<mrvn>
Drup: has to work with sexp too
<d_bot>
<Drup> mrvn: hmm, I should look it up, I don't much about it. There are various bit-level parsing libraries in ocaml already though
neiluj has quit [Ping timeout: 258 seconds]
<d_bot>
<Drup> well, byte-level
<d_bot>
<ostera> @Drup does the top-level support code-reloading?
<d_bot>
<Drup> no
<d_bot>
<ostera> how about that
jbrown has quit [Ping timeout: 246 seconds]
<d_bot>
<ostera> fun enough for you? 😛
<d_bot>
<Drup> If I knew how to do it, it would already be done
<mrvn>
Drup: 1) needs to be bit levcel, 2) you need to figure out the bit offsets for each field so it matches the corresponding C struct.
<d_bot>
<Drup> (code reload in a typed language is *really* hard)
<d_bot>
<jktuglu> Fardale: Is your opam version 2.0.7?
<mrvn>
3) you want efficient code to access and modify the fields
<d_bot>
<ostera> > (code reload in a typed language is *really* hard)
<d_bot>
<ostera> @Drup i'm looking forward to bashing my head against this in the following months
<d_bot>
<Drup> mrvn: it doesn't seem so difficult to extend ppx_cstruct to do that, no ?
<mrvn>
ostera: What should code reload do? Just reevaluate all the code you input since start again? That would just have the same result.
<mrvn>
Drup: if you know what you are doing then probably not.
<d_bot>
<joris> Meh all of my ideas are stupid. Not very practical and typed but involves regex : a lib to use automata as compressed data structures. Also not regex but compile time perfect hashing is nice
<d_bot>
<ostera> mrvn: it'd reload code but keep the environment
<d_bot>
<Drup> @joris it's better if it's not practical, really
<d_bot>
<ostera> you'd need to retype whatever's currently in scope, possibly keep separate versions of the types, indexed by the module versions, or drop parts of the environment
<d_bot>
<joris> (I really love rust libs for perfect hashing hashtable generation and the lib (fst) to generate automaton from string data set to store a map is pretty cool. I actually used it in prod some time ago
<mrvn>
ostera: That would break code like "let f x = f x
<d_bot>
<ostera> mrvn: yes, and that's something to deal with
<d_bot>
<joris> Almost as good as zstd compression and immensely faster lookup
<d_bot>
<Drup> > a lib to use automata as compressed data structures
<d_bot>
<Drup> Actually, I was considering that one ...
<d_bot>
<Drup> you compile regex into transducer that emits bitcode of the parsetree
<mrvn>
ostera: or more preciscely it would unbreak it. Stuff that fails to compiled before because somethign wasn't defined would suddenly compile. Any correct input would not use anything from the env you kept.
<d_bot>
<joris> Also it is not so useless. Afaik it is used by lucene
<mrvn>
ostera: Only use case I can see would be if you modify a module you open in the toplevel and you want to rerun your test case over and over after every edit.
inkbottle has quit [Ping timeout: 260 seconds]
<d_bot>
<ostera> repls are nice to explore stuff too
<mrvn>
Does the top level have something like pythons dir(<module>) that lists all the values the module has?
<d_bot>
<ostera> you can use #show
<d_bot>
<Drup> oh, from the wording I though there was a rust lib for automata compression
<d_bot>
<joris> Ah no. I mean maybe but I don't know
<mrvn>
no a drup project then
<d_bot>
<joris> I don't know much about the internal of rust regex lib besides 'it is fast as hell'
<d_bot>
<joris> Faster than re2 from experience
mxns has joined #ocaml
<d_bot>
<Drup> it would be good to bench ocaml-re and compare that too
<d_bot>
<joris> I also don't know how fst works because afaik building minimal automata is hard. It does not do that but it works quite well in practice
jbrown has joined #ocaml
<d_bot>
<joris> Reminds me some work project when I was trying to build html efficient rewriting rules from user provided example to be run on a server proxy. Thankfully product realized it was not a cost effective viable product and cancelled the project because i was quite stuck xD
<Fardale>
@jktuglu 2.0.5, but that does not matter
<d_bot>
<joris> @Drup that is probably a fun project too, generating minimal regex from set of examples
<d_bot>
<joris> Already exists but afaik not in ocaml
<d_bot>
<jktuglu> Fardale: can I share a repo with you?
neiluj has joined #ocaml
<Fardale>
If you want
neiluj has quit [Changing host]
neiluj has joined #ocaml
<d_bot>
<Drup> (at least unless there is a good paper that I don't know about on the topic)
<d_bot>
<Drup> generating regexs is ... messy ? you can only generate ugly things
<d_bot>
<joris> Well you didn't specify beauty was a requirement
<d_bot>
<Drup> you did say minimal 🙂
<d_bot>
<Drup> afaik, there is no algorithm to "minimize" a regex
hnOsmium0001 has joined #ocaml
<d_bot>
<joris> Right. You know I'm an engineer not a theorician. Words don't have the same meaning to me. Minimal means small enough not minimal
<mrvn>
Drup: minimal is probably contra productive to beauty
<d_bot>
<joris> I just mean that generaging a huge or pattern of all input set is cheating
<mrvn>
The problem with regexp made from examples is the same as neural networks that separate cats from dogs. Give it a car as input and watch it output fun.
<mrvn>
joris: A huge "or" pattern would only match exactly the examples. That's never what you want or you would have just written an or of all examples.
<mrvn>
Drup: how about an algorithm that detects if 2 regexp match the same language?
<d_bot>
<Drup> mrvn: is there any other algorithm for that than "generate the minimal DFA and compare for equality" ?
<mrvn>
Drup: is THE minimal DFA for a language even a thing? aren't there many?
<mrvn>
Drup: I would have thought you would need to do a symbolic evaluation of the regexp and see if they match the same things
<d_bot>
<Drup> yeah, IIRC, the minimal DFA is unique
<mrvn>
then don't you have your regexp minimizer? Build the minimal DFA and disassemble it
<d_bot>
<Drup> yeaah, if you regex engine works like that
<d_bot>
<Drup> (`re` doesn't)
mxns has quit [Ping timeout: 240 seconds]
<def>
the regex you extract from a DFA is usually much larger than the one used to build it
<def>
(afaict, we don't know how to build a small re from a DFA)
<d_bot>
<Drup> def: the question was about a small re from a set of strings
<d_bot>
<joris> It is probably not what you want to do but I feel like mentioning itsince afaik it was discussed at ocsf (not sure I was not there) and it is something I am currently doing as side projects at work
<d_bot>
<joris> Ocaml world heavily heavily lacks small 'by examples' how-to / tutorials for newcommers to explain languages features by use case and patterns to use them
<d_bot>
<Drup> I'm not very good at those, unfortunately
<d_bot>
<joris> Currently working on some 'modules and functors by example' and 'phantom types in practice' for instance
<d_bot>
<joris> Well idk. Your blog post on diff list (iirc? I forgot) was a gem
<d_bot>
<joris> Anyway gtg
<d_bot>
<Drup> yeah, but it was specific enough
<d_bot>
<Drup> def: I read the TDFA article today
<d_bot>
<joris> Yeah but it does not need to be generic
<d_bot>
<Drup> I would need some prompt, really, like "here is combination of feature X Y Z that I don't really understand"
narimiran has quit [Ping timeout: 260 seconds]
<d_bot>
<joris> I think this is one way to approach it. But the other way is 'look I build this fully typed stuff, I used this language feature because it brings that and it works like this. I could also have used that but it would have been less good because blabala'
<d_bot>
<joris> It does not need to be driven by concept. It can be driven by use case
<d_bot>
<wtetzner> Is there a way to reference the signature described by an `.mli` file by name elsewhere?
<d_bot>
<joris> No. Usually you put common signatures in ml files for this reason
<d_bot>
<wtetzner> OK, thanks
mmohammadi9812 has joined #ocaml
<def>
Drup: so ok, and what do you think?
<mrvn>
joris: I thouhgt you could reference the interface of a one module in the mli file of another now
<d_bot>
<Drup> TDFA is really nice, it's clearly "heavy-duty" (it's a thomson-like construction, plus determinisation/minisation), but I like the general approach
amiloradovsky has quit [Remote host closed the connection]
<d_bot>
<Drup> amusingly, the final form is almost a register automaton
amiloradovsky has joined #ocaml
<def>
and the method doesn't seem applicable to a derivative approach :P?
<d_bot>
<Drup> Unclear. 🙂
<d_bot>
<Drup> In particular, the final determinisation does some fairly fancy things with epsilon-transitions and registers. It also has 2 variations, one with 0-lookahead, and one with 1-lookahead (which is better)
<mrvn>
Drup: I think 1-lookahead is worse but more usefull
<mrvn>
appropo lookahead: Is there a parser generator with configurable N-lookahead?
<mrvn>
or one that looks at the grammar and says: Ok, this needs N-lookahead?
<d_bot>
<Drup> for LL, yes
<d_bot>
<Drup> for LR .... not that I know of, but IIRC, LR(N) for N >= 1 is not that useful
<d_bot>
<Drup> for TDFA, 1 lookahead is clearly significantly more efficient in practice. The expressivity doesn't change
<mrvn>
is LL(0) or LR(0)?
Haudegen has quit [Read error: Connection reset by peer]
Hrundi_V_Bakshi has joined #ocaml
Haudegen has joined #ocaml
<d_bot>
<Drup> is what ?
<mrvn>
useful
<mrvn>
Not sure how you would write a grammar in LL(0) or LR(0) that has "if then" and "if then else"
<d_bot>
<Drup> I'll let def answer that one 🙂
neiluj has quit [Remote host closed the connection]
amiloradovsky has quit [Remote host closed the connection]
amiloradovsky has joined #ocaml
<d_bot>
<jit> LL(0)?
<d_bot>
<jit> never heard of it lol
mxns has joined #ocaml
mxns has quit [Ping timeout: 244 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 256 seconds]
amiloradovsky has quit [Ping timeout: 244 seconds]