companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 4.14.0 released: https://ocaml.org/releases/4.14.0.html | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
Tuplanolla has quit [Quit: Leaving.]
sagax has quit [Ping timeout: 255 seconds]
vicfred has joined #ocaml
raskol has joined #ocaml
Haudegen has quit [Ping timeout: 276 seconds]
waleee has quit [Ping timeout: 258 seconds]
rgrinberg has joined #ocaml
raskol has quit [Ping timeout: 248 seconds]
raskol has joined #ocaml
bobo_ has joined #ocaml
spip has quit [Ping timeout: 255 seconds]
zebrag has joined #ocaml
hackinghorn has quit [Ping timeout: 272 seconds]
hackinghorn has joined #ocaml
recherche has joined #ocaml
zebrag has quit [Quit: Konversation terminated!]
<greenbagels> is the return type of an infinitely recursive function always a type variable 'a?
<d_bot> <ggole> Not necessarily, the return type can be constrained by an annotation or a case that is present but logically impossible to reach.
<companion_cube> `let rec f() = if false then 1 else f()`
gopiandcode has quit [Quit: WeeChat 3.0]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<greenbagels> so its type can basically be constrained to be anything?
<greenbagels> or i guess, something that includes the "possible" return types...
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 255 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 255 seconds]
vicfred has quit [Quit: Leaving]
<octachron> greenbagels, it might work better to see it the other way around: a function whose return type is 'a for any 'a never returns.
gravicappa has joined #ocaml
raskol has quit [Ping timeout: 244 seconds]
gravicappa has quit [Ping timeout: 248 seconds]
rgrinberg has joined #ocaml
rgrinberg has quit [Ping timeout: 255 seconds]
Haudegen has joined #ocaml
gravicappa has joined #ocaml
azimut has quit [Ping timeout: 240 seconds]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
mro has joined #ocaml
mro has quit [Remote host closed the connection]
<d_bot> <Butanium (@me on reply)> What do you mean octachron ?
<d_bot> <Butanium (@me on reply)> Fun.id is typed 'a -> 'a and does return
<d_bot> <octachron> Right, you need a condition that the `'a` does not appears on the left-hand side of the arrow.
<d_bot> <Butanium (@me on reply)> Do you mean something like `'a -> 'b` ?
<d_bot> <Butanium (@me on reply)> For this signature I can't think about any existing function that return
<d_bot> <octachron> Yes? Any type of the form `'a. ... (* no 'a in the ... *) -> 'a`.
<d_bot> <Butanium (@me on reply)> but won't `fun x y z t u v -> x` have this signature ?
<d_bot> <octachron> Not at all since its type is `'a -> ... -> 'a`.
<d_bot> <Butanium (@me on reply)> so what's insisde the `...` in your example ?
<d_bot> <Butanium (@me on reply)> `'a. ... (* no 'b in the ... *) -> 'b` I understand
<d_bot> <Butanium (@me on reply)> if you meant
<d_bot> <octachron> Anything without `'a`?
<d_bot> <octachron> Which problemdo you see with the universal quantification on `'a`?
<d_bot> <ggole> It gets a bit more complicated with the type variable being able to appear in negative positions in the `...`
<d_bot> <ggole> If I've even got that right
<d_bot> <Butanium (@me on reply)> I'm really confused
<d_bot> <ggole> eg, `int -> (int -> 'a) -> 'a`
<d_bot> <Butanium (@me on reply)> could you just give me an example of your above form ?
<d_bot> <octachron> @ggole , the condition can indeed be refined. But rather `int -> ('a -> int) -> 'a`
<d_bot> <octachron> `let rec loop: 'never. unit -> 'never = fun () -> loop ()`
<d_bot> <ggole> Oh right, I messed up my foralls
aspe has joined #ocaml
olle has joined #ocaml
energizer_ is now known as energizer
<d_bot> <Butanium (@me on reply)> here for example I don't see how it matchs your pattern `'a ... (* no 'a in the ... *) -> 'a` as `int <> 'a`. For me, if you write `'a` at the beginning and at the end, it means the input and return type has to be the same
bartholin has joined #ocaml
<d_bot> <ggole> The idea is that if you can get an value of type `'a` then you can return a value of that same type; if you can't, then a return value of that type means 'never returns'
<d_bot> <ggole> A function of type `'a -> int` cannot produce an `'a` but only accept one, so an `'a` there doesn't count for the purposes of telling whether a function never returns.
aspe has quit [Quit: aspe]
aspe has joined #ocaml
aspe has quit [Remote host closed the connection]
aspe has joined #ocaml
<d_bot> <octachron> @Butanium , you are misreading the dot in ` 'a. ... -> 'a` maybe `'a. <typ> -> 'a ` would be clearer? `'a. <typ> ` means for all types `'a`, `<typ>`.
gravicappa has quit [Ping timeout: 248 seconds]
andreypopp has quit [Ping timeout: 276 seconds]
recherche has quit [Quit: Client closed]
Tuplanolla has joined #ocaml
<d_bot> <Butanium (@me on reply)> Oh ok
<d_bot> <Butanium (@me on reply)> I'm not used to those notations sorry
bartholin has quit [Ping timeout: 244 seconds]
DNH has joined #ocaml
bartholin has joined #ocaml
mro has joined #ocaml
mro has quit [Ping timeout: 276 seconds]
gravicappa has joined #ocaml
andreypopp has joined #ocaml
DNH has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DNH has joined #ocaml
bartholin has quit [Ping timeout: 248 seconds]
gravicappa has quit [Ping timeout: 246 seconds]
bartholin has joined #ocaml
mro has joined #ocaml
mro has quit [Remote host closed the connection]
rgrinberg has joined #ocaml
gio123 has joined #ocaml
<gio123> hi all
gravicappa has joined #ocaml
<gio123> can someone help me with threads
tiferrei has quit [Remote host closed the connection]
tiferrei has joined #ocaml
<olle> gio123: print to stdout didn't work? :D
<gio123> stdout?
<gio123> what is that?
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rgrinberg has joined #ocaml
TakinOver has joined #ocaml
waleee has joined #ocaml
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp- has joined #ocaml
Sankalp- is now known as Sankalp
raskol has joined #ocaml
waleee has quit [Ping timeout: 244 seconds]
bartholin has quit [Ping timeout: 255 seconds]
spip has joined #ocaml
bobo_ has quit [Ping timeout: 258 seconds]
waleee has joined #ocaml
bartholin has joined #ocaml
raskol has quit [Ping timeout: 255 seconds]
<gio123> help?
mro has joined #ocaml
mro has quit [Client Quit]
<d_bot> <leviroth> gio123: if you have a question about threads, just ask it.
<d_bot> <leviroth> It's hard to respond to things like "can someone help me with threads" because nobody knows in advance if they're going to have the knowledge or time to help with your particular question.
azimut has joined #ocaml
<gio123> should I ask to bot?
<gio123> is here real user :)?
<d_bot> <darrenldl> the bot is bridge to discord
<gio123> with whom I am talking?
<d_bot> <darrenldl> this is darrenldl, previous advice was from leviroth
<d_bot> <darrenldl> (thought the bot would attach discord names(?))
<gio123> I am unable to trace this code
<gio123> how does it workes
<gio123> what it does
<d_bot> <darrenldl> what do you mean by "trace"?
<d_bot> <darrenldl> and did printf not work?
<gio123> is it clear what this prorgam does?
<d_bot> <zakkor> :ocaml_hug:
<gio123> par_unary (fun x -> x + 1) [8;1;1];;
<gio123> if I give this input it returns [9;2;2]
<gio123> c = new_channel ()  creats new channel, it is clear
<gio123> create (fun () -> sync (send c (f a))) ()  - what is happening here?
waleee has quit [Ping timeout: 250 seconds]
<d_bot> <darrenldl> sync and send are from Event module
<d_bot> <darrenldl> send gives you an event for pushing something onto the channel (c is the channel in this case)
<d_bot> <darrenldl> sync means the function blocks until this is completed
<d_bot> <darrenldl> (similar to await or force in other concurrency environments
<d_bot> <darrenldl> create is from Thread module
<d_bot> <darrenldl> so overall worker is a function that applies f on a in parallel by creating a thread
<d_bot> <darrenldl> you use that to apply to all elements in a list in parallel
<gio123> so, here par_unary (fun x -> x + 1) [8;1;1];; worker applies  (fun x -> x + 1) to every element of list?
<gio123> in parallel
<d_bot> <darrenldl> correct
<d_bot> <darrenldl> (in principal anyway, you're capped by the number of cores etc
<gio123> once again :)
<gio123> let c = new_channel ()
<gio123> creates a new chanel
<gio123> btw, what is a relation between chanel and event module?
<d_bot> <darrenldl> channel is under Event module
<gio123> aha
<d_bot> <darrenldl> perhaps would be clearer if the code does not open Thread and Event at the top
<gio123> did not get
<gio123> does it changes smt?
<gio123> if i remove
<gio123> open Thread
<gio123> open Event
<gio123> from code?
<d_bot> <darrenldl> open Thread "imports" all the names into your current scope
<d_bot> <darrenldl> so you can do create instead of Thread.create
<d_bot> <darrenldl> and so on
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<gio123> aha clear, let me check things again
<gio123> :)
<gio123> thanks
<d_bot> <darrenldl> if this is not a one-off encounter with ocaml, it might be advisable to check some of the free books/resources
omegatron has quit [Read error: Connection reset by peer]
omegatron has joined #ocaml
xgqt has quit [Ping timeout: 248 seconds]
xgqt has joined #ocaml
<gio123> send c (f a) means we push f a in the channel c?
<gio123> darrenldl:
<d_bot> <darrenldl> correct
<d_bot> <geoff> https://v2.ocaml.org/api/Event.html sounds like the docs would be useful
<gio123> somehow
<gio123> but, still do not understand some concepts :(
<gio123> if I trace the program by giving input: par_unary (fun x -> x + 1) [8;1;1];;
<gio123> send c ((fun x -> x + 1) [8;1;1]))
<gio123> retunr what?
<gio123> List.map (fun c -> sync (receive c) a what will return this for this particualr input
<gio123> ?
<d_bot> <darrenldl> usual approach would be to check the corresponding type signatures first
<gio123> it seems send always retunr ()
bartholin has quit [Ping timeout: 260 seconds]
<olle> () means the unit type
<olle> Kinda like "void" in Java
<gio123> yes
<gio123> val send : 'a channel -> 'a -> unit event
<gio123> this is type of send
<olle> gio123: Link to your code paste?
<olle> gio123: Sorry, dunno enough about threads in OCaml, can't help you
<olle> You can also try the forum
<gio123> ok
<d_bot> <darrenldl> might be easiest to try running the snippets you want in utop and see for yourself
bartholin has joined #ocaml
DNH has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Anarchos has joined #ocaml
rgrinberg has joined #ocaml
<gio123> darrenldl: it is almost impossible to trace how operationaly ocaml treats input
<gio123> par_unary (fun x -> x + 1) [8;1;1];;
<gio123> for this input
<d_bot> <darrenldl> so you want a breakdown in big step semantics of sorts?
<gio123> big step semantic gives value
<gio123> I prefer to see step by step how it computes
<gio123> like:
<gio123> par_unary (fun x -> x + 1) [8;1;1];; calls
<gio123> worker [8;1;1]
<gio123> which in turn creates new chanel c
<d_bot> <darrenldl> not sure if #trace in utop does anything close to that hm...
<d_bot> <darrenldl> but worker does not get the full list in any case
<d_bot> <darrenldl> and tracing in concurrent code hm...
<gio123> let c = new_channel () in
<gio123>     let _ = create (fun () -> sync (send c (f a))) () in
<gio123>     c
<gio123> I have problem to undesrtan this part
<gio123> a is passed to worker, which means worker gets full list.  No?
<d_bot> <darrenldl> worker is called as `List.map worker a`
<gio123> really?
<gio123> I parse this: List.map worker a |> List.map (fun c -> sync (receive c))
<gio123> List.map worker List.map (fun c -> sync (receive c)) a
<d_bot> <darrenldl> sorry what is the context of this endeavour?
<gio123> to understand parallel programming
<d_bot> <darrenldl> that is not the correct parsing of |> in any case
<gio123> a |> f  parssing is fa
<gio123> no?
<d_bot> <darrenldl> yes, but lower precedence
<gio123>  List.map (fun c -> sync (receive c)) List.map worker a
<gio123> like this?
aspe has quit [Quit: aspe]
<d_bot> <darrenldl> with more parentheses but yes
<gio123> btw
<d_bot> <darrenldl> anyway, i dont know if jumping head first into this code is the best way to pick up parallel programming if you dont already use ocaml
<gio123> I understand ocaml code and prorgamming without problem
<gio123> I have problem to understand parallel prorgamming in ocaml
<gio123> could you please tell me
<gio123> when c is created
<gio123> when new chanel is assigned to c
<gio123>  sync (send c (f a)) - here as you said (f a) is pushed in c
<gio123> sync blocks what? not clear :(?
<gio123> create (fun () -> sync (send c (f a))) ()
<gio123> creats threads
<gio123> totally how many threads are created? does it depends to the length of list?
<d_bot> <darrenldl> bed time for me, perhaps someone else will be able to answer
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
Haudegen has joined #ocaml
<gio123> :(
<d_bot> <octachron> There is one thread created by element of the list, since threads are created by the worker function.
<d_bot> <octachron> `sync` blocks the current thread until the events receive a communication.
<d_bot> <octachron> Also there is no parallelism going on in this program, only concurrency (since the runtime before OCaml 5 has a global lock)
<gio123> octachron
<gio123> <There is one thread created by element of the list, since threads are created by the worker function.
<gio123> to clarify this (sorry for my english) if we have 5 element of input list how many threads will be created?
<octachron> 5
Haudegen has quit [Quit: No Ping reply in 180 seconds.]
<gio123> and in each thread worker applies f function to the element of the list
aspe has joined #ocaml
aspe has quit [Remote host closed the connection]
waleee has joined #ocaml
Haudegen has joined #ocaml
<octachron> And send the computed value to the channel `c` created to hold this result.
<gio123> chanel is single. is not?
<gio123> only single channel c is created
<octachron> There is one channel created for each element of the input list.
DNH has joined #ocaml
<gio123> it means if we have 5 element list, then 5 chanels and 5 threads are created totally?
<octachron> Yes.
<gio123> octachron: Many thanks
<gio123> sync (send c (f a)))
<gio123> here f a is sent to c. If a is 5 element list then it together with f will be in c
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<gio123> no?
<octachron> I am not sure what you mean? The element `a` is never sent to the channel.
<gio123> let _ = create (fun () -> sync (send c (f a))) ()
<gio123> here, what does send do?
<octachron> It sends the value `f a` to the channel `c`.
rgrinberg has joined #ocaml
<gio123> if a is a [1;2;3;4;5] it send f  [1;2;3;4;5]  to c
<gio123> ok?
<octachron> Not at all.
<octachron> Except if your input list is something like [[1];[2;3];[1;2;3;4;5]]
<gio123> if the input is par_unary (fun x -> x + 1) [8;1;1]
<octachron> But if your input list is `a=[1;2;3;4;5]`, since you are calling `List.map worker a`, worker is called separately on each element of the list.
<gio123> clear!
<gio123> many thanks
<octachron> (you should really rename your function arguments to avoid `a` being either the list of inputs or one element of this list depending on the context)
<gio123> ok, thx
<gio123> clear just one question
<gio123> if we have 5 threades and chanels
<gio123> for what sync is needed at all?
<gio123> in each threads we have function applied single element, let say f 5
<gio123> or f
<octachron> This is unrelated to the number of threads?
<gio123> I mean, when sync might be used ?
<octachron> Whenever you want to synchronize your program to after the point where the event happened.
<gio123> It is clear now... many thanks again
Tuplanolla has quit [Ping timeout: 258 seconds]
bartholin has quit [Ping timeout: 255 seconds]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Tuplanolla has joined #ocaml
kakadu has quit [Read error: Connection reset by peer]
bartholin has joined #ocaml
bartholin has quit [Ping timeout: 246 seconds]
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gio123 has quit [Quit: Client closed]
bartholin has joined #ocaml
rgrinberg has joined #ocaml
tiferrei has quit [Remote host closed the connection]
raskol has joined #ocaml
tiferrei has joined #ocaml
rgrinberg has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DNH has quit [Ping timeout: 250 seconds]
mro has joined #ocaml
gravicappa has quit [Ping timeout: 276 seconds]
raskol has quit [Ping timeout: 246 seconds]
mro has quit [Quit: Leaving...]
bartholin has quit [Quit: Leaving]
olle has quit [Ping timeout: 260 seconds]
Tuplanolla has quit [Quit: Leaving.]