<discocaml>
<shawnfrostx> is it possible to emulate polymorphic variants in a language with just variants? it’s one of the features i miss the most when i’m not coding in ocaml
<discocaml>
<contificate> do you mean like.. in the type system
<discocaml>
<contificate> or just the idea
<discocaml>
<contificate> I'm also surprised you like them, I don't really care for them at all
<discocaml>
<contificate> another one of those "wouldn't notice it was gone if it disappeared" features
<discocaml>
<shawnfrostx> just the way it’s used i guess. i would prefer to have the same level of type safety.
<discocaml>
<shawnfrostx> but i’m also curious how they are actually implemented. i’ve never seen them in other languages or in the usual beginner books
<discocaml>
<contificate> my understanding is that the names are hashed to integers which are the runtime representation
<discocaml>
<contificate> such that you can actually find ways to break compilation
<discocaml>
<contificate> by simply bruteforcing a colliding hash
<discocaml>
<contificate> for tags that are combined
<discocaml>
<contificate> scheme has a kind of dynamic, global, notion of this concept imo - in that symbols are usually hashcons'd
<discocaml>
<contificate> but no type level stuff to act as witness anywhere
<discocaml>
<dubious245> I have no idea how they work in one place I use them. They are just there powering a feature I like. :derpanda:
<discocaml>
<dubious245> I have no idea how they work in the one place I use them. They are just there powering a feature I like. :derpanda:
<discocaml>
<contificate> I keep my programming nice and simple, I've used polymorphic variants at a previous job for an implied subtyping relation
<discocaml>
<contificate> but that's about it
<discocaml>
<contificate> quite like the coercion operator thing
<discocaml>
<contificate> but really, ignoring forms of lightweight type level correctness, feels unnecessary, I could live without em
<discocaml>
<deepspacejohn> I don’t use them a lot but when I need them they’re really useful
<discocaml>
<dubious245> I used them in that example of a `convert_to_grayscale : 'any image -> gray image` and then in `thresh_image : gray image -> binary image` That is such a nice interface to me that's enforced by the compiler.
<discocaml>
<dubious245> I used them in that example of a `convert_to_grayscale : 'any image -> gray image` and then in `thresh_image : gray image -> binary image` That is such a nice interface to me that's also enforced by the compiler.
<discocaml>
<contificate> not seeing the polymorphic variants there, Dubious
<discocaml>
<dubious245> They are there in my heart.
<discocaml>
<dubious245> -# one second.
<discocaml>
<dubious245> ```ocaml
<discocaml>
<dubious245> (*Representing the different types of channels with polymorphic data types.*)
<discocaml>
<dubious245> type rgba = [ | `RGBA of mapf * mapf * mapf * mapf]
<discocaml>
<dubious245> type rgb = [ | `RGB of mapf * mapf * mapf]
<discocaml>
<dubious245> type gray = [ | `GRAY of mapf * mapf ]
<discocaml>
<dubious245> type binary = [ | `Binary of map8]
<discocaml>
<contificate> just littering types in my merlin buffer
<discocaml>
<dubious245> I don't even know if they are necessary here for what I want. I think some of yall suggested polymorphic variants to achieve this and others suggested GADT.
<discocaml>
<contificate> type tetris is my least favourite game, so I avoid GADTs personally - although cute in tiny, isolated, things I'll never touch again
<discocaml>
<shawnfrostx> yeah i just pretty much use polymorphic variants for function arguments where it’s not ergonomic to split them into a proper variant because different functions take different subsets / the type is used once or twice like in a result
<dmbaturin>
I'm trying to install opam on Windows Server 2019 with winget but get NoApplicableInstallers error. What may be issue? Does it only support later versions of Windows?
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 248 seconds]
wickedshell has quit [Ping timeout: 276 seconds]
<dh`>
the GADTs in ocaml and haskell are really too knotty to use effectively
<dh`>
coq's work somewhat better but you get into other problems there
Humean has joined #ocaml
<discocaml>
<dubious245> What are they used for?
<discocaml>
<Kali> gadts in general, or coq's specifically?
<discocaml>
<dubious245> In ocaml?
<discocaml>
<dubious245> But coq would be interesting to hear about.
<discocaml>
<uberpyro181> one thing is that they're behind the magic of how `Printf.printf` is implemented
<discocaml>
<uberpyro181> but really GADTs make WAY more sense in dependently typed languages
<discocaml>
<uberpyro181> (if you consider them a feature as opposed to.. just what exists by default)
<discocaml>
<uberpyro181> they're useful for encoding and proving properties
<discocaml>
<uberpyro181> you can encode proofs in inductive datatypes the same way as data
<discocaml>
<samuelalison> Hey there! I'm a junior MERN stack developer (MongoDB, Express.js, React, Node.js) actively looking for an internship to grow and contribute meaningfully to a dev team.
<discocaml>
<samuelalison> I bring 2 years of hands-on experience in the fintech and logistics industries, building scalable backend services and dynamic web applications
<discocaml>
<contificate> yes, it will tell you - hence "break compilation"
<discocaml>
<gooby_diatonic> I've appreciated when occasionally libs expose their interfaces using polymorphic variants, I think in those situations the non-polyvar interface would've been more cumbersome
<discocaml>
<contificate> depends how many tags there are
<discocaml>
<contificate> I just have a memory of looking at a type error and just being like "brilliant, glad they chose to include all these tags"
<theblatte>
froyo, dh`: ocaml is installed by opam, that's the one opam deems to have to recompile over and over due to "upstream or system changes"
myrkraverk has joined #ocaml
myrkraverk_ has quit [Ping timeout: 272 seconds]
Haudegen has quit [Quit: Bin weg.]
<discocaml>
<froyo> got ya
myrkraverk_ has joined #ocaml
myrkraverk has quit [Ping timeout: 252 seconds]
Haudegen has joined #ocaml
<discocaml>
<Kali> re gadts: in the stdlib, they're used in the Type module (added very recently) to provide proofs of type equality in situations where type equality might otherwise be erased (for example, module signatures/functors); GADTs are also used behind a string-like syntax to implement the typed format strings that you can pass to printf/format—you could just write them as normal constructors if you open the module the format type is defined in though
Humean has joined #ocaml
mange has quit [Quit: Zzz...]
trillion_exabyte has quit [Ping timeout: 252 seconds]
trillion_exabyte has joined #ocaml
<discocaml>
<deepspacejohn> Bigarray uses them to make some functions polymorphic, and effects use them so effects can be polymorphic.
YuGiOhJCJ has quit [Remote host closed the connection]
<discocaml>
<gabyfle> Hey, might be a stupid question but has OCaml Programming: Correct + Efficient + Beautiful ever been published in paper format ?
<discocaml>
<gabyfle> I really do prefer paper and I find this book insanely well written
cedb has quit [Ping timeout: 252 seconds]
bartholin has quit [Quit: Leaving]
cedb has joined #ocaml
Tuplanolla has quit [Quit: Leaving.]
<cedb>
i have a file with "if condition then run(command)" which compiles however if i add a let inside the if like so: "if condition then let x = 2 in run(command)" it doenst compile, can anyone tell me why?
<discocaml>
<._null._> I don't see an issue with this description. It's odd that you write function application as f(arg) though
<discocaml>
<Kali> not enough information (this should compile), you probably have a syntax error later in the file
<cedb>
the context is a code within a Lwt_main.run so I need a Lwt.return() at the end but i dont understand why i cant have ifs with no else if they just return unit
<cedb>
when i add a let binding inside *
<discocaml>
<yawaramin> hard to tell what exactly we are looking at here. can you add line numbers to the code sample and tell us which line num we should be looknig at? can you also copy-paste the exact error message from the compiler? also i think you have a misunderstanding about Lwt, it's not about putting a 'magic' `Lwt.return ()` at the end but about composing the entire program in terms of Lwt promises