<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(?))
<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>
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…]