companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 4.12 released: https://ocaml.org/releases/4.12.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
waleee has quit [Ping timeout: 255 seconds]
hackinghorn has joined #ocaml
<d_bot> <Def> it depends on the grammar is written, this can be LR(1)
<d_bot> <Def> (lr(1) requires that a single token ahead is enough to decide whether to shift or reduce, the prefix of both rules can be expressed using only shifts)
<d_bot> <Def> LR(2) does not increase expressiveness. Actually, forall k, LR(k) is equivalent to LR(1)
<d_bot> <Def> GLR is the LR generalization that can handle all CFG.
zebrag has quit [Quit: Konversation terminated!]
<d_bot> <theangryepicbanana> I rewrote these rules 3 times with no success
zebrag has joined #ocaml
<d_bot> <theangryepicbanana> it's literally impossible due to the ambiguity I explained
<d_bot> <theangryepicbanana> (ironically enough though, the grammar was designed to not be ambiguous lol)
zebrag has quit [Remote host closed the connection]
<d_bot> <Def> can you show me the grammar?
zebrag has joined #ocaml
zebrag has quit [Remote host closed the connection]
mbuf has joined #ocaml
JSharp has quit []
JSharp has joined #ocaml
gzj has joined #ocaml
gravicappa has joined #ocaml
gzj has quit [Remote host closed the connection]
theblatt1 has joined #ocaml
theblatte has quit [*.net *.split]
thizanne has quit [*.net *.split]
rom1504 has quit [*.net *.split]
scoobybejesus has quit [*.net *.split]
gzj has joined #ocaml
thizanne has joined #ocaml
rom1504 has joined #ocaml
scoobybejesus has joined #ocaml
ocabot has quit [*.net *.split]
Leonidas has quit [*.net *.split]
Ekho has quit [*.net *.split]
ebb has quit [*.net *.split]
Drup has quit [*.net *.split]
Leonidas_ has joined #ocaml
ebb has joined #ocaml
ocabot has joined #ocaml
lisq has quit [*.net *.split]
Fardale has quit [*.net *.split]
jyc has quit [*.net *.split]
darxun has quit [*.net *.split]
andreypopp_ has quit [*.net *.split]
Fardale has joined #ocaml
lis has joined #ocaml
jyc has joined #ocaml
darxun has joined #ocaml
andreypopp has joined #ocaml
Ekho has joined #ocaml
octachron has quit [*.net *.split]
dy has quit [*.net *.split]
notnotdan has quit [*.net *.split]
cemerick has quit [*.net *.split]
hexology has quit [*.net *.split]
sim642 has quit [*.net *.split]
drakonis has quit [*.net *.split]
arg has quit [*.net *.split]
Boarders has quit [*.net *.split]
ks_ has quit [*.net *.split]
arg_ has joined #ocaml
octachron_ has joined #ocaml
notnotdan has joined #ocaml
drakonis has joined #ocaml
drakonis has joined #ocaml
drakonis has quit [Signing in (drakonis)]
Boarders has joined #ocaml
sim642 has joined #ocaml
cemerick has joined #ocaml
hexology has joined #ocaml
ks_ has joined #ocaml
dy has joined #ocaml
Drup has joined #ocaml
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
gravicappa has quit [Ping timeout: 268 seconds]
Haudegen has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
mro has joined #ocaml
rgrinberg has joined #ocaml
lis is now known as lisq
gzj has quit [Read error: Connection reset by peer]
gzj has joined #ocaml
waleee has joined #ocaml
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
<d_bot> <Aram> Hello. It it possible to recover the type index of a GADT? From what I can find online, this requires creating a runtime representation of a type, and passing that around, but I don't want to do that, because it would defeat the purpose of wanting a GADT in the first place.
<d_bot> <Aram> Alternativelly, what I really want is a polytypic function which can take a `foo ty | bar ty | ...`, and match on foo, bar, etc (but foo, bar, etc, are type indices, not constructors). It appears that I can only do this with modular implicits, which are not yet available in OCaml.
<d_bot> <Aram> to give more context, I have a GADT `type _ instr`, which represents machine instructions, and has many constructors (one for each instruction), but instructions form classes, and I want to clasify the GADT by class, so I do for example `Or: reg * reg_or_imm32 -> alu instr`, `Ldxw: reg * ind -> load instr`. And I want to differentiate the `alu instr` from a `load instr` in a function without having to match on ALL the constructors,
<d_bot> <Aram> Alternativelly, I can put each instruction class in its own module, but then because of lack of modular implicits (so lack of overloading) I have to force my callers to always know the class of the instructions they are using...
mro has quit [Quit: Leaving...]
<d_bot> <octachron> You can never match on types in OCaml. However, from your description you shouldn't need to? Simply matching on the GADTs constructor should work?
<d_bot> <octachron> If the issue is that you have many constructors with the same type, or the same kind, you can just split your initial constructor by classes.
<d_bot> <Aram> yes but then the caller needs to be aware of the class.
<d_bot> <Aram> I can't hide that from the caller, no?
<d_bot> <octachron> I am not sure what you mean by hiding from the caller?
<d_bot> <Aram> basically whether something is a `load instr` or an `alu instr` is an implementation detail, that is useful to maintain type-safety inside my module. but outside the module, I don't want the user to have to know anything about `load` or `alu`, just `instr`.
<d_bot> <octachron> Then you can erase the type index from `instr` with an existential: `type instr = Instr: 'a inner_instr -> instr`.
<d_bot> <Aram> hmm.
<d_bot> <Aram> but the user still needs to know the class of the instruction, no? because they need to call, say `size_load` insead of `size_alu`. I can't make an overloaded function.
<d_bot> <octachron> Your requirements seem contradictory? Either the type index doesn't matter outside of the modules and external user can just call `size`, or it does matter and users have to know about the differences between `load instr` and `alu instr`.
<d_bot> <Aram> the type index shouldn't matter outside, but I can't make it to not matter outside -- that's the problem.
<d_bot> <Aram> basically the problem is that the mapping between constructors and type indices is not one to one.
<d_bot> <Aram> and I generally want to decide something based on type indices, but that seems to be impossible.
<d_bot> <Aram> since I can only match on constructors, I might as well not use GADTs, since I can't use them withoutn having my callers care about the type index.
<d_bot> <octachron> If I understand correctly, you want for instance to have a function `size: 'a instr -> int`. But you end up with a `alu_size: alu instr -> int` and `load_size: load instr -> int`?
<d_bot> <octachron> That can be fixed.
<d_bot> <Aram> yes
<d_bot> <octachron> If you can share the real code (with the type definition), I can explain the potential fix on your code. Otherwise, I can show what I mean on a toy example.
glassofethanol has joined #ocaml
<d_bot> <Aram> http://ix.io/3sJA
<d_bot> <octachron> And you want to have a size function that is defined by reusing a size function for each class?
gravicappa has joined #ocaml
<d_bot> <Aram> yes
Tuplanolla has joined #ocaml
<Armael> constructors of the load, store and misc class don't have arguments of the same type -- that seems a bit problematic (in the sence that you can't have a single size function for the entire load class)
<Armael> sense*
<d_bot> <Aram> (that's true -- size is not the best example here -- the real function is something like `iclass`, which returns part of the opcode space and is uniquily determined by the class of the instruction and doesn't need to look at the data inside the constructor.)
aquijoule__ has quit [Ping timeout: 252 seconds]
<d_bot> <Aram> well yeah.
<d_bot> <Aram> but now the user has to explicitely construct an `'a instr` when using size.
<d_bot> <Aram> ```
<d_bot> <Aram> let ld_instr = Ldabsw 1234l
<d_bot> <Aram> let ld_instr_size = size (Load ld_instr)
<d_bot> <Aram> ```
<d_bot> <Aram> which means, for example, that I can't have an `opcode: 'a instr -> int` function that can call size (because it still has to know what the class is).
<d_bot> <Aram> basically we lifted the problem one level up.
richbridger has joined #ocaml
<d_bot> <octachron> I see no problem with having a `'a instr -> int`? And similarly, I am not sure how you expect users to not have to construct a `'a instr` before using size on a a value of type `'a size`.
<d_bot> <octachron> (And you could have `let ld_instr = ldabsw 1234l`)
<d_bot> <Aram> well, in this particular case, users having to know 7 instruction classes is not a big deal.
<d_bot> <Aram> but say we have x86 assembly instead of this eBPF assembly.
<d_bot> <Aram> suddently we have hundreds of instruction classes.
<d_bot> <Aram> the users should use this as a DSL, they should know the name and syntax of the instruction, but the fact that there are classes of instructions should be an implementation detail (especially since on x86 instruction classes have very cryptic names, not just Load, Store, etc).
<d_bot> <Aram> I still want to have the concept of an instruction class, to maintain invariants and type-safety internally.
<d_bot> <Aram> but I don't want users to be exposed to instruction classes.
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
<d_bot> <Aram> basically the clasification function is semantically a function from types to values.
<d_bot> <Aram> we can have such a thing with modules.
<d_bot> <Aram> but the "cases" of the function have to live in different modules, and I don't thimk we can unify them under a single name (unless we have modular implicits).
<d_bot> <Dak> Hi! Can someone do a Ocaml work? Im paying for that! DM me if you are interested
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<d_bot> <NULL> Well, you narrowly escaped the warning on top of #beginners but it should probably apply here as well
bartholin has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
gzj has quit [Remote host closed the connection]
aquijoule_ has joined #ocaml
richbridger has quit [Read error: Connection reset by peer]
gzj has joined #ocaml
<d_bot> <Cyclomatic Complexity> In OCaml, this works: `let f : type a . a -> a = fun (type b) (x : b) : b -> x ;;`
<d_bot> <Cyclomatic Complexity> But how does it happen? Is there some alpha-renaming happening behind the stages (and if so, which strategy is used to avoid accidental captures when alpha-renaming?)? Is it converted to some de-bruijn representation?
mro has joined #ocaml
berberman has quit [Ping timeout: 255 seconds]
berberman has joined #ocaml
mro has quit [Quit: Leaving...]
<d_bot> <Armael> (the complexity budget is a bit high so I don't know how much I would recommend that solution, but the idea is that the combination of `classify_instr` and `of_classified` allows you to define functions by "pattern-matching" on instruction classes, without having to make such classes part of the definition of the `instr` type, as in octachron's approach)
Haudegen has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
eight has quit [Quit: leaving]
<d_bot> <octachron> @Aram : since the aim is to avoid exposing the internal datatypes, it seems that you could expose only smart constructors: `ldabsw: int32 -> instr` in the DSL.
<d_bot> <Aram> yeah.
<d_bot> <Aram> I thought of that.
<d_bot> <Aram> it works.
<d_bot> <Aram> it's quite unfortunate I need all that duplication, but yeah.
<d_bot> <Aram> btw, this is how it works in Haskell: http://ix.io/3sKh
<d_bot> <Aram> (not that I really know haskell, I just tried it out to see if I can do it).
mbuf has quit [Quit: Leaving]
adanwan has quit [Ping timeout: 244 seconds]
adanwan has joined #ocaml
<d_bot> <Aram> @Armael thanks, yes. this works. it's somewhat unfortunate syntactically, but it does exactly what I want.
<d_bot> <Armael> you can simplify it somewhat if you know you'll not need the payload of the instruction when defining a function using `of_classified`, just its class
<d_bot> <Armael> (then you don't need the record)
gzj has quit [Ping timeout: 255 seconds]
<d_bot> <Alistair> Yeah, by using k-grams but this would require explicit k-grams using the ocamllex and menhir tools, which isn't very practical
mbuf has joined #ocaml
TakinOver has quit [Ping timeout: 268 seconds]
TakinOver has joined #ocaml
<d_bot> <thangngoc89> A learning project of mine : https://github.com/thangngoc89/denu
<d_bot> <thangngoc89> Don't use it, just for fun
tizoc has left #ocaml [#ocaml]
tizoc has joined #ocaml
gzj has joined #ocaml
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
aquijoule_ has quit [Quit: Leaving]
bartholin has quit [Quit: Leaving]
gareppa has joined #ocaml
gareppa has quit [Client Quit]
gzj has quit [Remote host closed the connection]
gzj has joined #ocaml
neiluj has joined #ocaml
<neiluj> Hi! How do you convert an Lwt_result.t into an Lwt.t?
<neiluj> in this case, the error is mapped to a none value
<thizanne> neiluj: 'a Lwt_result.t is 'a result Lwt.t
<thizanne> thus, you map whatever plain result conversion you want
<thizanne> you also get Lwt_result.get_exn, in case you want to turn the Error result case into a Lwt failure
<neiluj> thanks, do give more context I'm using a bind from Lwt_result.Infix so the function expects a Lwt_result.t as a return value
<neiluj> I'd like an Lwt.t
<neiluj> oh nice
<neiluj> thanks thizanne :)
<d_bot> <Alistair> With ppx_deriving.map, is there an option s.t `map` has the signature `'a t -> f:('a -> 'b) -> 'b t` instead of `('a -> 'b) -> 'a t -> 'b t`?
gzj has quit [Ping timeout: 255 seconds]
waleee has joined #ocaml
mro has joined #ocaml
Guest8905 has quit [Ping timeout: 252 seconds]
Guest8905 has joined #ocaml
glassofethanol has quit [Quit: leaving]
mro has quit [Quit: Leaving...]
Haudegen has quit [Quit: Bin weg.]
mbuf has quit [Remote host closed the connection]
<d_bot> <Swerve> Question about js\_of\_ocaml: I've got a program that uses Graphics and opens up a window with some circles and squares inside. It runs fine when I call `dune exec main.exe`. But if I use jsoo to turn my code into js, and put that in an html page, I just get errors about being unable to open the graphics window. I've scoured the jsoo docs and SO and can't find anything helpful, anyone have any experience using Graphics_js?
<d_bot> <thangngoc89> @Swerve maybe you need Graphics_js instead ?
<d_bot> <Swerve> I'm using Graphics\_js currently
<d_bot> <Alistair> The errors would be helpful
<d_bot> <Swerve> `"Graphics.open_graph: cannot open the window"`
<d_bot> <thangngoc89> You need to not pull Graphics in the code
<d_bot> <Swerve> As in, don't put `open_graph` or `draw_rect` or stuff like that in the code?
<d_bot> <Swerve> I'm not quite sure what you mean
<d_bot> <Swerve> (thanks btw)
<d_bot> <thangngoc89> Try to remove all references to Graphics
<d_bot> <Swerve> The entirety of my code is graphics though: https://pastebin.com/j4t2bNff
<d_bot> <Alistair> `Graphics_js` includes `Graphics`
<d_bot> <Alistair> the `open_graph` method is provided by the runtime here https://github.com/ocsigen/js_of_ocaml/blob/58210fabc947c4839b6e71ffbbf353a4ede0dbb7/runtime/graphics.js#L39
<d_bot> <thangngoc89> Hmm 🤔
<d_bot> <Alistair> Your error occurs on line `67`, could be a browser permission error or something?
<d_bot> <Alistair> e.g. it fails to execute https://www.w3schools.com/jsref/met_win_open.asp
<d_bot> <Alistair> Have you got an adblocker on your browser?
<d_bot> <Swerve> I do, but I'm looking at it with the VSCode live-preview
<d_bot> <Swerve> and even if I don't try to preview it, it's an error at build time
<d_bot> <Swerve> This is my dune and html files (for reference):
<d_bot> <Swerve> dune: https://pastebin.com/es8UqXEb
<d_bot> <Swerve> html: https://pastebin.com/dVc1RbLV
<d_bot> <thangngoc89> I don’t usually have to do that to build jsoo
<d_bot> <thangngoc89> Just dune build main.bc.js
Corbin has joined #ocaml
<d_bot> <Swerve> just running `dune build main.bc.js` with no `open_graph` line in my code, I still get `Graphics.Graphic_failure,31,Not initialized`
<d_bot> <Swerve> When I run the js with node
<d_bot> <Alistair> I'm working w/ `-rectypes` and I'm wondering why I get a cyclic type error w/ ```ocaml
<d_bot> <Alistair> module Make (F: T1) (O : T1 -> T1) = struct
<d_bot> <Alistair> module Open = O(F)
<d_bot> <Alistair>
<d_bot> <Alistair> type t = (t Open.t) F.t
<d_bot> <Alistair> end;;
<d_bot> <Alistair> ```
rgrinberg has joined #ocaml
Haudegen has joined #ocaml
vicfred has joined #ocaml
neiluj has quit [Ping timeout: 276 seconds]
neiluj has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 255 seconds]
Stumpfenstiel has joined #ocaml
<d_bot> <Alistair> @octachron?
neiluj has quit [Quit: Leaving]
<d_bot> <octachron> I imagine that `T1 = sig type 'a t end`. The issue is that even with `-rectypes` trivial loops (e.g. `type t = t`) are not allowed.
<d_bot> <Alistair> :(, I'm trying to generalize https://keleshev.com/map-as-a-recursion-scheme-in-ocaml w/ an arbitrary functor added to the recursive type (which may be used for typing info / location, etc), is it possible to do something like this in ocaml?
vicfred has quit [Quit: Leaving]
gravicappa has quit [Ping timeout: 255 seconds]
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
shawn has joined #ocaml
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
xenu has quit [Read error: Connection reset by peer]
xenu has joined #ocaml
xenu_ has joined #ocaml
xenu_ has quit [Client Quit]
<d_bot> <theangryepicbanana> apologies for the late reply, but here's the relevant (old) grammar <https://github.com/ALANVF/star_parser/blob/master/lib/parser.mly#L340-L382>
<d_bot> <theangryepicbanana> and then here are the rules for the messages that it collides with <https://github.com/ALANVF/star_parser/blob/master/lib/parser.mly#L451-L528>
Stumpfenstiel has quit [Ping timeout: 255 seconds]
Haudegen has quit [Ping timeout: 255 seconds]