companion_cube changed the topic of #ocaml to: Discussions about the OCaml programming language | http://www.ocaml.org | OCaml 4.11 release notes: https://caml.inria.fr/pub/distrib/ocaml-4.11/notes/Changes | Try OCaml in your browser: http://try.ocamlpro.com | Public channel logs at http://irclog.whitequark.org/ocaml
Tuplanolla has quit [Quit: Leaving.]
madroach has quit [Ping timeout: 246 seconds]
madroach has joined #ocaml
madroach has quit [Ping timeout: 260 seconds]
madroach_ has joined #ocaml
Nahra has quit [Remote host closed the connection]
mfp has quit [Ping timeout: 240 seconds]
waleee-cl has quit [Quit: Connection closed for inactivity]
mbuf has joined #ocaml
ania123 has joined #ocaml
snowpanda has joined #ocaml
waleee-cl has joined #ocaml
narimiran has joined #ocaml
ania123 has quit [Quit: Connection closed]
stylewarning has quit [Ping timeout: 245 seconds]
stylewarning has joined #ocaml
stylewarning has joined #ocaml
stephe_ has joined #ocaml
stephe has quit [Ping timeout: 245 seconds]
stephe_ is now known as stephe
ELLIOTTCABLE has quit [Ping timeout: 245 seconds]
ELLIOTTCABLE has joined #ocaml
bytesighs has quit [Ping timeout: 245 seconds]
stylewarning has quit [Ping timeout: 245 seconds]
rfv has quit [Ping timeout: 245 seconds]
rfv has joined #ocaml
bytesighs has joined #ocaml
stylewarning has joined #ocaml
arecaceae has quit [Remote host closed the connection]
arecaceae has joined #ocaml
wonko7 has joined #ocaml
bacam_ has joined #ocaml
bacam has quit [Ping timeout: 245 seconds]
b20n has quit [Ping timeout: 245 seconds]
pmonson has quit [Ping timeout: 245 seconds]
pmonson has joined #ocaml
Druup has joined #ocaml
Drup has quit [Ping timeout: 245 seconds]
b20n has joined #ocaml
stylewarning has quit [Ping timeout: 245 seconds]
narimiran has quit [Ping timeout: 245 seconds]
stylewarning has joined #ocaml
caasih has quit [Ping timeout: 245 seconds]
olle has joined #ocaml
b20n has quit [Ping timeout: 245 seconds]
narimiran has joined #ocaml
b20n has joined #ocaml
caasih has joined #ocaml
olle has quit [Ping timeout: 240 seconds]
Haudegen has joined #ocaml
snowpanda has quit [Quit: Leaving...]
olle has joined #ocaml
Nahra has joined #ocaml
vicfred has quit [Quit: Leaving]
sagax has joined #ocaml
narimiran has quit [Ping timeout: 252 seconds]
TheLemonMan has joined #ocaml
serif[m] has quit [Ping timeout: 245 seconds]
bartholin has joined #ocaml
serif[m] has joined #ocaml
sagax has quit [Ping timeout: 252 seconds]
<Sumera[m]> Hi all! Is this channel for general discussions for all things Ocaml or just for things related to development of the Ocaml language toolchain?
<Druup> All things ocaml :)
<Druup> (which includes the compiler, naturally)
Druup is now known as Drup
<Sumera[m]> That's awesome!
<Sumera[m]> I was wondering if there a library for encoding Strings in Ascii-8/utf-8. I came across Camomile but the repo doesn't look very active and I am not really able to find proper docs. Any help would be great!
<octachron> It depends on the source and destination encoding.
<octachron> For utf-n on both sides, uutf is sufficient
mfp has joined #ocaml
sagax has joined #ocaml
<d_bot> <bikal> am trying to get this to work
<d_bot> <bikal> ```
<d_bot> <bikal> module Params = struct
<d_bot> <bikal> type _ t =
<d_bot> <bikal> | [] : 'a t
<d_bot> <bikal> | ( :: ) : 'a * 'b t -> ('a -> 'b) t
<d_bot> <bikal>
<d_bot> <bikal> let c = [ "s"; 1; 2.3; true ]
<d_bot> <bikal>
<d_bot> <bikal> let parse l =
<d_bot> <bikal> let parse_int s =
<d_bot> <bikal> try Some (int_of_string s) with
<d_bot> <bikal> | _ -> None
<d_bot> <bikal> in
<d_bot> <bikal> let parse_float s =
<d_bot> <bikal> try Some (float_of_string s) with
<d_bot> <bikal> | _ -> None
<d_bot> <bikal> in
<d_bot> <bikal> Core.List.fold_left l ~init:[] ~f:(fun acc s ->
<d_bot> <bikal> match parse_int s with
<d_bot> <bikal> | Some i -> i :: acc
<d_bot> <bikal> | None -> (
<d_bot> <bikal> match parse_float s with
<d_bot> <bikal> | Some f -> f :: acc
<d_bot> <bikal> | None -> s :: acc))
<d_bot> <bikal> end
<d_bot> <bikal> ```
<d_bot> <bikal> but getting ```This expression has type (int -> 'a) t
<d_bot> <bikal> but an expression was expected of type 'a t
<d_bot> <bikal> The type variable 'a occurs inside int -> 'a
<d_bot> <bikal> ```
<olle> ??
<olle> Don't spam code like that ;(
<olle> Looks shit in IRC
<olle> Couple of lines are ok, but keep them under 5. Otherwise, pastbin or whatever.
<d_bot> <bikal> IRC?
<olle> This channel is linked with IRC channel through a bot
<d_bot> <octachron> @bikal : with GADTS, it is often a good first step to try to write the type of the function.
<d_bot> <bikal> ok
<olle> Actually, the code looks well-formatted in IRC too :d
<olle> Hm
<olle> Still, I guess
<d_bot> <octachron> And in this case, you should see that `parse` cannot be typed in OCaml.
<d_bot> <octachron> Heterogeneous lists are a very rigid data structure. It might be better to see them as a familly of tuple types.
<d_bot> <bikal> yes. but tuple is static no? aka the cardinality of its members have to be known at compile time right?
<d_bot> <octachron> It is the same with heterogeneous lists.
<d_bot> <bikal> ah. so we can't dynamically create heterogenous list at runtime?
<olle> Just wrap it in ADT?
<olle> type list_item = ...
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
* olle scoffs at type magic
<d_bot> <octachron> Ah, your implementation allow to fill up the remaining types, so at least the type of `[]` is compatible with the type `_ :: _ `.
<d_bot> <octachron> But, yes, creating an heterogeneous lists at runtime and using them and require to have some companion type witness.
<d_bot> <bikal> companion type witness?
<d_bot> <bikal> not sure I understand
<d_bot> <dinosaure> _type witness_ is like a value which is a _constructor_ with the type information
<d_bot> <dinosaure> such as `type 'a witness` & `val extract : 'a witness -> value -> 'a option` for example
<d_bot> <dinosaure> a simple example of that is `hmap`: https://github.com/dbuenzli/hmap
<d_bot> <octachron> A simpler example that generate a random heterogeneous lists, and its companion list of types at runtime:
<d_bot> <octachron> Note that this not that different of having a list of `type t = Float of float | Int of int`. The tag and the corresponding type information is just stored in a different list.
<d_bot> <bikal> yes, that would be my fallback option. Was wondering if GADT would be more concise ... looking at your example now
<d_bot> <octachron> There are few cases where the GADT option would be more concise, but if you don't have some extra constraints, the list of a variant types will be simpler *and* shorter.
narimiran has joined #ocaml
<d_bot> <bikal> I was looking at implementing a function like 'scanf' in userland but with my own custom parsing in fmt, so gadt looked like it would allow me ... but it seems they type mastery required is quite high
<d_bot> <bikal> like this func `route "/home/about/:int" (fun i -> i + 2)`
<d_bot> <octachron> Beware that the `format strings` are not strings at all, they are GADTs masquerading as strings with the complicity of the compiler.
Haudegen has quit [Quit: Bin weg.]
<d_bot> <Anurag> If combinators are okay to use instead of format strings you can do this with my routes library https://github.com/anuragsoni/routes
<d_bot> <bikal> yep
<d_bot> <octachron> Typically, `"%d"` is `Format (Int (Int_d, No_padding, No_precision, End_of_format), "%d")` without the magic sugar
<d_bot> <bikal> Not exactly format string but just string with some special keyword
<d_bot> <bikal> eg : `:int`, `:float`, `:bool` etc
<d_bot> <octachron> You cannot derive types from values in the language. This is more the job of a ppx.
<d_bot> <bikal> This looks nice.
<d_bot> <bikal> @Anurag can `routes` go the other way? so from string `"/user/:string/:int64"` to value `sum`?
<d_bot> <bikal> I probably need to experiment with a bit more but thanks for the lib, it looks promising
Haudegen has joined #ocaml
TheLemonMan has joined #ocaml
<d_bot> <Anurag> Hmm, not sure I fully understand, but routes allows for scanf style parsing `<pattern> => handler`, and printf/sprintf style printing `keys -> format -> string/unit`
<d_bot> <Anurag> for printing if you have a route pattern of `/user/:string:int64` you can get a `sprintf` style function out of routes via `Routes.sprintf <pattern for "/user/:string/:int64"`. That'll return something with a signature `string -> int64 -> string`
curtosis has joined #ocaml
curtosis has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
curtosis has joined #ocaml
curtosis is now known as curtosis[away]
curtosis[away] is now known as curtosis
curtosis is now known as curtosis[away]
curtosis[away] is now known as curtosis
<d_bot> <bikal> What I meant was if there is a way to create routes via string and not the combinators, for eg
<d_bot> <bikal> `Routes.create "/user/:string/:int" = ... (Routes.target)`
<d_bot> <Anurag> No, that isn't available. I believe the ocaml compiler does some magic to convert the strings to the GADT representation (like @octachron mentioned).
<d_bot> <octachron> Yes, the compiler essentially uses a builtin typed-ppx for doing the translation.
olle has quit [Ping timeout: 265 seconds]
<d_bot> <bikal> Ah, I was just re-looking at this article by @Drup https://drup.github.io/2016/08/02/difflists/ and wanted to see if I can do essentially `val parse : string list -> ('ty, 'v) t` or `val parse : string -> ('ty, 'v)t`
<d_bot> <bikal> But yeah got the same issue with my earlier attempt.
<d_bot> <octachron> General rule: in a non-dependently typed language, you cannot generate type information from a value.
<d_bot> <Drup> Yeah, you need a ppx for that
<d_bot> <bikal> ok
<d_bot> <Drup> it's not terribly satisfying :/
<d_bot> <bikal> yeah
<d_bot> <Drup> @bikal if you want to use this to do routing, I suggest you take a look at Furl
<d_bot> <bikal> this one? https://github.com/Drup/furl?
<d_bot> <Drup> yeah
<d_bot> <Drup> there is also a thing by ocamlpro to do routing for rest APIs which uses a similar concept (and is published/finished)
<d_bot> <bikal> oh, which one?
<d_bot> <Drup> ah `resto`, it's called
<companion_cube> there's a tiny version of that in tiny_httpd, too
Haudegen has quit [Quit: Bin weg.]
<d_bot> <bikal> `resto` looks nice, is the ez_resto module the one to use or just resto?
curtosis has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
<d_bot> <Anurag> `ezresto` adds some abstraction on top of `resto` which provide a simpler UX. I'd recommend starting there and seeing if it meets your needs, and then see if there is something you aren't able to achive with ezresto and then go to `resto`
mbuf has quit [Quit: Leaving]
<d_bot> <antron> is discuss.ocaml.org really slow right now? or just for me?
bartholin has quit [Quit: Leaving]
Haudegen has joined #ocaml
<d_bot> <mseri> Works fine for me
narimiran has quit [Ping timeout: 252 seconds]
<d_bot> <antron> seems to be fine for me now, also
narimiran has joined #ocaml
vicfred has joined #ocaml
olle has joined #ocaml
Tuplanolla has joined #ocaml
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
olle has quit [Ping timeout: 265 seconds]
curtosis has joined #ocaml
wonko7 has quit [Ping timeout: 260 seconds]
curtosis has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
dckc has quit [Read error: Connection reset by peer]
dckc has joined #ocaml
Nahra has quit [Ping timeout: 245 seconds]
narimiran has quit [Ping timeout: 245 seconds]
tinga has joined #ocaml
<d_bot> <hcarty> @sgrove I haven't created tars in memory but have extracted them. Looking at the ocaml-tar interface it should be possible to do something resembling an inverse of what's in this gist, but I haven't tried to be sure. This is a partial and simplified version of what I've used: <https://gist.github.com/hcarty/18650157caa9f0f6d1a19df62d89c138>
<d_bot> <sgrove> @hcarty I managed to figure it out, thank you!
Tuplanolla has quit [Quit: Leaving.]
<d_bot> <Zach5050> hi
<d_bot> <Zach5050> Does anyone know how to add multiple things to a list at the same time?
<d_bot> <Zach5050> my professor gives the psuedocode on the left and i must add two tuples to the list at the same time, i looked in List and cant find anything
<d_bot> <Zach5050> ```ocaml
<d_bot> <Zach5050> if((type_check ((str1,typ2)::(str2,typ1)::te)
<d_bot> <Zach5050> ```
<d_bot> <Zach5050> i tried this but the test still fails
Haudegen has quit [Ping timeout: 240 seconds]
<Fardale> This is the correct way to add two pairs (str1,typ2) and (str2,typ1) to the list te
curtosis has joined #ocaml
curtosis is now known as curtosis[away]
curtosis[away] has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]