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
<Anarchos> no
<Anarchos> lst is a tuple because you match it with (_,[]) whose type is 'a * b list
<Anarchos> so it is a tuple
<guanohhh> Anarchos: sorry, I totally didn't understand the code I was writing, and now I do
<Anarchos> guanohhh you can understand type better in annotating your code : for each expression you are not sure of the type, write instead (e: guessed_type) where e is the expression you want to verify the type, and guessed_type is a valid type expression as written by the toplevel
<Anarchos> example : let f a b = (a:int) + (b:int)
<guanohhh> yeah, that's for the explicit signature definition, right? I was trying to find examples on google but I wasn't finding any obvious answers about how it works in general
<Anarchos> let (f: int -> int -> int) a b = a+b
<guanohhh> Anarchos: thanks!
<Anarchos> sorry, i mistyped again : let (f: int -> int -> int) = fun a b -> a+b;;
* Anarchos just tried in toplevel)
Tuplanolla has quit [Quit: Leaving.]
wonko7 has quit [Ping timeout: 272 seconds]
<d_bot> <EduardoRFS> someone knows an x86_64 in memory assembler for OCaml? I don't want to call `as`
<d_bot> <EduardoRFS> it's for a latency sensitive application
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
_whitelogger has joined #ocaml
Anarchos has quit [Excess Flood]
Jeanne-Kamikaze has quit [Quit: Leaving]
Jeanne-Kamikaze has joined #ocaml
mxns has joined #ocaml
amiloradovsky has quit [Remote host closed the connection]
ygrek has quit [Remote host closed the connection]
Haudegen has quit [Ping timeout: 240 seconds]
nullcone has joined #ocaml
vicfred has quit [Quit: Leaving]
Jeanne-Kamikaze has quit [Quit: Leaving]
waleee-cl has quit [Quit: Connection closed for inactivity]
<d_bot> <theangryepicbanana> yay doing some fancy stuff with objects https://github.com/ALANVF/star-vm/blob/master/lib/types.ml
<d_bot> <theangryepicbanana> they ended up being a better solution than having several recursive modules/records (gee, I wonder why?)
mfp has quit [Ping timeout: 246 seconds]
oni-on-ion has quit [Read error: Connection reset by peer]
oni-on-ion has joined #ocaml
narimiran has joined #ocaml
tianon has quit [Quit: brb]
tianon has joined #ocaml
objmagic_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tianon has quit [Client Quit]
tianon has joined #ocaml
ansiwen has quit [Quit: ZNC 1.7.1 - https://znc.in]
aaaaaa has joined #ocaml
ansiwen has joined #ocaml
terrorjack has quit [Remote host closed the connection]
greenbagels has quit [Quit: WeeChat 2.3]
mxns has quit [Ping timeout: 260 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 240 seconds]
copy has quit [Ping timeout: 264 seconds]
mxns has joined #ocaml
copy has joined #ocaml
mxns has quit [Ping timeout: 272 seconds]
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #ocaml
mxns has joined #ocaml
mxns has quit [Ping timeout: 258 seconds]
Tuplanolla has joined #ocaml
dmbaturin has quit [Remote host closed the connection]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
ptival[m] has quit [Quit: Idle for 30+ days]
wonko7 has joined #ocaml
dmbaturin has joined #ocaml
mxns has joined #ocaml
mxns has quit [Ping timeout: 264 seconds]
<def> EduardoRFS: I had an x86 in memory assembler, but I didn't port it to 64.
narimiran has quit [Ping timeout: 264 seconds]
tane has joined #ocaml
nullcone has quit []
Haudegen has joined #ocaml
TheLemonMan has joined #ocaml
mfp has joined #ocaml
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
webshinra_ has joined #ocaml
webshinra has quit [Ping timeout: 258 seconds]
BitPuffin has quit [Ping timeout: 260 seconds]
BitPuffin has joined #ocaml
jnavila has joined #ocaml
ggole has joined #ocaml
bartholin has joined #ocaml
madroach has joined #ocaml
mxns has joined #ocaml
mxns has quit [Ping timeout: 258 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 272 seconds]
narimiran has joined #ocaml
waleee-cl has joined #ocaml
objmagic has joined #ocaml
<d_bot> <EduardoRFS> def: I don't want to implement an assembler ... but that seems likely to happen
<d_bot> <ggole> You could write (or find, if you are lucky) bindings for a library like libyasm
steenuil has quit [Ping timeout: 272 seconds]
TheLemonMan has joined #ocaml
<d_bot> <EduardoRFS> Oh I didn't knew yasm, and it even has a gas-parser, that was my biggest problem with asmjit
mxns has joined #ocaml
steenuil has joined #ocaml
mxns has quit [Ping timeout: 258 seconds]
wonko7 has quit [Ping timeout: 260 seconds]
objmagic has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mxns has joined #ocaml
mxns has quit [Ping timeout: 272 seconds]
Jeanne-Kamikaze has joined #ocaml
mxns has joined #ocaml
defdom0 has joined #ocaml
<guanohhh> can someone help me with this code?: https://paste.ofcode.org/3EjW22HQxJxUmiV9zPHDua
<guanohhh> also I don't understand how to access functions that are declared `let square = ...`, how am I supposed to access the arguments passed to it?
<Jeanne-Kamikaze> You mean like let square = fun x -> x*x?
<Jeanne-Kamikaze> What's wrong with the paste?
<d_bot> <Deadrat> @guanohhh
<d_bot> <Deadrat> the code you linked is essentially
<d_bot> <Deadrat> ```ocaml
<d_bot> <Deadrat> let rec less_tr_3 e lst to_return =
<d_bot> <Deadrat> match lst with
<d_bot> <Deadrat> | [] -> List.rev(to_return)
<d_bot> <Deadrat> | x::y -> if x < e then less_tr_3 e y x::to_return
<d_bot> <Deadrat> else less_tr_3 e y to_return
<d_bot> <Deadrat> ;;
<d_bot> <Deadrat> let less_tr e lst =
<d_bot> <Deadrat> less_tr_3 e lst []
<d_bot> <Deadrat> ```
<d_bot> <Deadrat> you just create a internal recursive function and delegate to it when you call less_tr
<guanohhh> yeah, because I need to make it tail recursive, which means adding an accumulator, but keeping the original function signature
<d_bot> <Deadrat> so whats wrong with it?
<d_bot> <Deadrat> except that its not tail recursive
<guanohhh> that's the error I am getting
<guanohhh> what do you mean it isn't tail recursive?
<Jeanne-Kamikaze> Parenthesis around ::?
<d_bot> <Deadrat> first variant in if clause isn't recursive
<guanohhh> Jeanne-Kamikaze: you are right! thank you!
<Jeanne-Kamikaze> You might as well do: x::y -> less_tr_3 e y (if x < e then x::to_return else to_return)
defdom0 has quit [Quit: defdom0]
<guanohhh> Jeanne-Kamikaze: thank you!
defdom0 has joined #ocaml
defdom0 has quit [Client Quit]
<guanohhh> wait, that returns a function, it doesn't return the result...
<Jeanne-Kamikaze> And it is tail recursive? There's nothing going on after the recursive call.
<guanohhh> what is the difference in ocaml between a function is `let funct a b = ...` and `let funct(a,b) = ...`?
<Jeanne-Kamikaze> The first one "takes two arguments" (inasmuch as curried functions take more than one argument). The latter takes a single argument that is a 2-tuple.
<Jeanne-Kamikaze> If you type them in utop you'll see the function signatures and see the difference.
<guanohhh> oh, right, I remember reading how `let funct a b = ...` is equivalent to `let funct a = let funct b ...`, right?
<guanohhh> thank you
<guanohhh> but it is tail recursive right?
<Jeanne-Kamikaze> Yes, it is.
<Jeanne-Kamikaze> Yes. let add a b = a + b is semantically equivalent to let add = fun a -> fun b -> a + b
<guanohhh> Jeanne-Kamikaze: thank you!
<guanohhh> I would think it would be easy to switch between them
<Jeanne-Kamikaze> The second construct is more fun.
<guanohhh> I am getting a compiler error when I switch it from a tuple call to one that just takes an argument?
<Jeanne-Kamikaze> Function application is left-associative. So f x::xs = (f x)::xs. Here you want f (x::xs).
<guanohhh> Jeanne-Kamikaze: thank you1
<guanohhh> thank you!*
<Jeanne-Kamikaze> Sure. Your total is going to be $535 for today, sir.
<Jeanne-Kamikaze> What payment method should you prefer?
nore has quit [Ping timeout: 260 seconds]
raver has quit [Quit: Gateway shutdown]
<Jeanne-Kamikaze> guanohhh, Is this a school assignment or something?
aaaaaa has quit [Quit: leaving]
<guanohhh> how would I go about mapping or to a map of boolean values?
<guanohhh> `List.fold_left (||) lst` isn't working
<guanohhh> mapping or to a list of boolean values*
<Jeanne-Kamikaze> You need to pass the initial value of the accumulator too?
<Jeanne-Kamikaze> utop # List.fold_left;;
<Jeanne-Kamikaze> - : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
bartholin has quit [Quit: Leaving]
<Jeanne-Kamikaze> Look at what you wrote and compare it with the type signature.
<guanohhh> Jeanne-Kamikaze: thank you so much! I forgot to check the type signature like the idiot I am
DanC has quit [Ping timeout: 264 seconds]
mxns has quit [Ping timeout: 260 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 272 seconds]
mxns has joined #ocaml
mxns has quit [Ping timeout: 258 seconds]
objmagic has joined #ocaml
vesper11 has quit [Ping timeout: 256 seconds]
<guanohhh> right now I have this code https://paste.ofcode.org/jdy8fJUqmEz4Lr6ZFyHqJd
<guanohhh> but I am supposed to flatten a list of lists without using recursion or helper functions besides map, fold left/right, so I don't know how to do that. kind of hit a brick wall.
DanC has joined #ocaml
<octachron> Then you have to replace your flatten function with either a map or a fold. Do you think that flatten is a fold or a map?
<guanohhh> I think of map as changing the identity of a list, and fold as turning a list into a value
<guanohhh> so I guess a fold, since I want to extract item by item?
mxns has joined #ocaml
amiloradovsky has joined #ocaml
Anarchos has joined #ocaml
<octachron> Yes, a fold is the right option(note that this means reimplementing a basic solution from the List module)
<octachron> Another way to see that is that map does not change the number of elements of the list. Your function (you should really use a better name that flatten) certainly does.
mxns has quit [Ping timeout: 258 seconds]
narimiran has quit [Ping timeout: 256 seconds]
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
ggole has quit [Quit: Leaving]
<guanohhh> @octachron I am really stumped, I cannot figure out how to do it.
mxns has joined #ocaml
<octachron> First, what is the result of `flatten [1;2;3] [4;5;6]`?
hnOsmium0001 has joined #ocaml
<guanohhh> [1;2;3;4;5;6]
<guanohhh> wait sorry
<guanohhh> wait I was right, [1;2;3;4;5;6]
<octachron> So flatten is better named append. Then the question is how to implement append with a fold (if `@` is not allowed).
amiloradovsky has quit [Remote host closed the connection]
amiloradovsky has joined #ocaml
Yagotzirck has joined #ocaml
<guanohhh> right, which I am stuck on.
<guanohhh> thank you so much for helping me by the way.
<guanohhh> okay I got it
<guanohhh> List.fold_right (fun x acc -> x::acc) [1;2;3] [4;5;6];;
<octachron> Indeed.
amiloradovsky has quit [Remote host closed the connection]
<guanohhh> okay I have another problem. I am supposed to basically assign [false;true;false;true...] to a list, and then get the last item
<guanohhh> basically there is a 'parity' value that changes the true/false value of the next assignment, and the only one that matters is the last one
amiloradovsky has joined #ocaml
<guanohhh> I cannot use length to help
<Anarchos> guanohhh use List.rev and the only that matters is the first one...
<mrvn> List.fold_right (fun x acc -> x)
<mrvn> or fold_left for the other end
<guanohhh> mrvn: thanks!
<guanohhh> I just got: `List.fold_left (fun a b -> not a) true [1;2];;`
<mrvn> or just write out the recursion
<guanohhh> cannot use recursion or if
<mrvn> then just fold and ignore the acc. That gives you the last x
<guanohhh> mvrn: I have no idea how I could map your code to this problem, I am not that good with ocaml
<mrvn> let return_last default list = List.fold_left (fun acc x -> x) default list
wreed has joined #ocaml
DanC has quit [Ping timeout: 260 seconds]
objmagic_ has joined #ocaml
objmagic has quit [Ping timeout: 264 seconds]
GuerrillaMonkey has joined #ocaml
<guanohhh> how do you get the index of the first variable that make a function return true, when applied to a list?
Jeanne-Kamikaze has quit [Ping timeout: 265 seconds]
<guanohhh> okay I figured it out, used some old code
<guanohhh> what is the best way to write code so it isn't a bunch of `let f x y = ... in let z x y = ... in let a x y = ... in etc.`. I like the reasonml brackets, I am not used to ocaml's version.
GuerrillaMonkey has quit [Ping timeout: 256 seconds]
DanC has joined #ocaml
jnavila has quit [Ping timeout: 272 seconds]
nullcone has joined #ocaml
DanC has quit [Quit: ZNC 1.6.6+deb1ubuntu0.2 - http://znc.in]
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
mxns has quit [Ping timeout: 260 seconds]
DanC has joined #ocaml
<Anarchos> guanohhh let f,g,h = fun1, fun2,fun3 ?
<guanohhh> Anarchos: thanks!
tane has quit [Quit: Leaving]
<guanohhh> why does `index != -1` throw an error for me? it's not a type error, it's a 'integer subtraction. left associative ...` error
<Anarchos> guanohhh let f x = x != -1;; val f : int -> bool = <fun>
<Anarchos> guanohhh it works here
<guanohhh> huh vscode with the ocaml-lsp plugin is throwing an error
<Anarchos> (-1) should do the trick
<Anarchos> the vscode parser is not as efficient as the ocaml one maybe
<guanohhh> yeah that doesn't work either
wonko7 has joined #ocaml
<guanohhh> also what does `let () = ht.arr.(i) <- x in ...` mean? I don't understand why you have to do `let ()` or the `in` part. It is to run a side effect, right?
DanC has quit [Quit: ZNC 1.6.6+deb1ubuntu0.2 - http://znc.in]
<Anarchos> right
<Anarchos> the side effect being an assignment in your case
DanC has joined #ocaml
mxns has joined #ocaml
<mrvn> guanohhh: it's equivalent to "ht.arr.(i) <- x;"
Tuplanolla has quit [Quit: Leaving.]
<Anarchos> what is the best way to find the index in a list of the first item verifying a given predicate ?
<mrvn> none. fidning in a list is never the best.
<Anarchos> mrvn i know, but for now i am only prototyping
<mrvn> sounds more like homework.
<Anarchos> no it isnet
<Anarchos> mrvn you can look at my repo at github.com/Sylvain78/Preuves
<mrvn> then just recurse
<Johann> Anarchos: containers has a CCList.find_idx which does just that
<Anarchos> i use find_map with a ref on the index that i increment in the predicate. not clean but should work
<Anarchos> Johann anyway i would prefer a clean way
<mrvn> let rec find_idx ~i=0 pred = function [] -> raise Not_found | x::_ when pred x -> i | _::xs -> find_idx ~i:(i+1) pred xs
<mrvn> Anarchos: find_map? that's the worst.
<Anarchos> mrvn why ?
<mrvn> why do you build a new list? You never use it.
<mrvn> you also don't terminate when you find the index. So you call the predicate a lot more than needed
<Anarchos> mrvn List.find_map doesn't build a new list, it returns an option
<mrvn> Oh? got confused by the "map" part. That usualy when you change one list into another.
<Anarchos> mrvn not the find_map :)
<mrvn> Ah, it maps just the found element.
<Anarchos> yes
<mrvn> ok, I take it all back then. That's just bad because of the reference.
<mrvn> If ocaml where constistent in its standard library there should be a List.find_map_i
<mrvn> like there is filter and filteri
<Anarchos> mrvn yes
Haudegen has quit [Ping timeout: 256 seconds]
Yagotzirck has quit [Quit: Leaving]
objmagic_ has quit [Ping timeout: 272 seconds]