adrien changed the topic of #ocaml to: Discussions about the OCaml programming language | http://www.ocaml.org | OCaml 4.07.1 release notes: https://caml.inria.fr/pub/distrib/ocaml-4.07/notes/Changes | Try OCaml in your browser: http://try.ocamlpro.com | Public channel logs at http://irclog.whitequark.org/ocaml | Due to ongoing spam, you must register your nickname to talk on the channel
Haudegen has joined #ocaml
<quarters> I was wondering if someone can help clarify how this expression let double = map (( * ) 2) ;; yields the same as let double ls = (fun x -> 2 * x) ls ;; I understand how the latter works but am struggling with the former
TheRuralJuror has joined #ocaml
Haudegen has quit [Ping timeout: 268 seconds]
TheRuralJuror has quit [Remote host closed the connection]
<tautologico> is the second one missing a map?
<quarters> tautologico, oh yeah. thanks
<quarters> good catch
<tautologico> ok, so * is the multiplication function, right?
<tautologico> ( * ) turns the infix operator into a prefix function
<tautologico> int -> int -> int
<tautologico> it is a curried function with two arguments. ( * ) 2 is a function int -> int that is similar to ( * ) but with the first argument fixed to the value 2
<tautologico> ( * ) 2 is a function that, given an integer, will return the int multiplied by 2
<tautologico> you can check that in the REPL: (( * ) 2) 5;;
<quarters> tautologico, I think the prefix function portion is throwing me off due to unfamiliarity with that syntax. I'm used to seeing a variable being worked upon which I don't see here
<tautologico> so map (( * ) 2) is also a function with the first argument fixed, in this case the function (( * ) 2) which will be mapped in to the list
<quarters> are all functions capable of being prefix functions?
<tautologico> map is ('a -> 'b) -> 'a list -> 'b list
<tautologico> so fixing the first argument means that map (( * ) 2) is int list -> int list, the function that, given a list of integers, will return a list with the values doubled
<tautologico> if you write let f x = x * 2 you'd call f with f 5, right? so f is in prefix position
<tautologico> operators are different because they can be infixed
<tautologico> are you familiar with currying? if you're not, I imagine it will be difficult to understand your first snippet, because it uses the fact that functions are curried twice
<quarters> tautologico, I'm familiar with currying insofar as it involves a function returning another function and that ocaml's functions' "acceptance" of multiple arguments is syntactical sugar for what is basically currying
<tautologico> right, that's it
<tautologico> so * is an (infix) operator, ( * ) is the multiplication function, a 2-argument function.
<quarters> I'm wondering how I'd be able to write a filter even numbers function using this style. I know how to write it like so: let evens = filter (fun x -> x mod 2 = 0)
<tautologico> ( * ) 2 is a function that accepts only one argument and returns the value of the argument doubled.
<tautologico> in this case you're fixing the second argument to mod, so currying won't help
<quarters> tautologico, I think I'll need a bit more time to process what you just told me. ty!
<tautologico> np
<tautologico> for simple, pure functions you can think about them using a substitution model
<tautologico> so if you define let add a b = a + b, it is int -> int -> int, a function of two arguments
<tautologico> (sum 2), by substitution, would be the same as let sum b = 2 + b, a function with one argument, returning an int (int -> int)
<tautologico> curried functions are always single-argument, they may return other functions that accept other arguments
mfp has quit [Ping timeout: 250 seconds]
tormen_ has joined #ocaml
tormen has quit [Ping timeout: 250 seconds]
kotrcka has left #ocaml [#ocaml]
nopf has joined #ocaml
FreeBirdLjj has joined #ocaml
mengu has joined #ocaml
mengu has quit [Ping timeout: 246 seconds]
gravicappa has joined #ocaml
notnotdan has quit [Remote host closed the connection]
mengu has joined #ocaml
mengu has quit [Quit: Leaving...]
_whitelogger has joined #ocaml
recj has quit [Ping timeout: 246 seconds]
FreeBirdLjj has quit [Ping timeout: 246 seconds]
jao has joined #ocaml
_whitelogger has joined #ocaml
kakadu has joined #ocaml
jao has quit [Ping timeout: 246 seconds]
haesbaert has joined #ocaml
_whitelogger has joined #ocaml
_whitelogger has joined #ocaml
maattdd has joined #ocaml
emily has joined #ocaml
emily has quit [Client Quit]
maattdd has quit [Quit: WeeChat 2.2]
pierpal has quit [Read error: Connection reset by peer]
pierpal has joined #ocaml
pierpal has quit [Read error: Connection reset by peer]
pierpal has joined #ocaml
pierpal has quit [Read error: Connection reset by peer]
pierpal has joined #ocaml
pierpal has quit [Read error: Connection reset by peer]
pierpal has joined #ocaml
pierpal has quit [Ping timeout: 268 seconds]
initiumdoeslinux has joined #ocaml
pierpal has joined #ocaml
pierpal has quit [Ping timeout: 246 seconds]
initiumdoeslinux has quit [Remote host closed the connection]
pepesza has quit [Ping timeout: 250 seconds]
pierpal has joined #ocaml
pepesza has joined #ocaml
mfp has joined #ocaml
bartholin has joined #ocaml
estrom has joined #ocaml
<estrom> Hello, I am new to OCaml and was wondering if there is an opinionated way of rewriting lines 11 to 17 in this code: https://pastecode.xyz/view/7b747026
pepesza has quit [Ping timeout: 244 seconds]
pepesza has joined #ocaml
<lyxia> that looks pretty good to me
jnavila has joined #ocaml
<lyxia> you could fold this into a single match with: match line |> Option.map float_from_string with
<lyxia> it makes the code look a bit more regular but it's not really easier to understand IMO.
theglass has quit [Quit: ZNC - http://znc.in]
jao has joined #ocaml
iovec has joined #ocaml
dmiles has quit [Ping timeout: 245 seconds]
logicmoo has joined #ocaml
<estrom> lyxia: I see, it is nice to know -- having written some haskell, it seems preferrable to fold, even though less readable
jao has quit [Ping timeout: 245 seconds]
initiumdoeslinux has joined #ocaml
initiumdoeslinux has quit [Ping timeout: 268 seconds]
theglass has joined #ocaml
theglass has quit [Changing host]
theglass has joined #ocaml
ggole has joined #ocaml
logicmoo is now known as dmiles
Ptival has quit [Ping timeout: 250 seconds]
Ptival has joined #ocaml
_whitelogger has joined #ocaml
initiumdoeslinux has joined #ocaml
pierpal has quit [Quit: Poof]
pierpal has joined #ocaml
initiumdoeslinux has quit [Ping timeout: 250 seconds]
dtornabene has joined #ocaml
rwmjones|hols has quit [Quit: ZNC - 1.6.0 - http://znc.in]
rwmjones has joined #ocaml
jao has joined #ocaml
dtornabene has quit [Quit: Leaving]
recj has joined #ocaml
initiumdoeslinux has joined #ocaml
jao has quit [Ping timeout: 245 seconds]
initiumdoeslinux has quit [Ping timeout: 246 seconds]
pierpal has quit [Quit: Poof]
pierpal has joined #ocaml
JimmyRcom has joined #ocaml
JimmyRcom has quit [Max SendQ exceeded]
JimmyRcom has joined #ocaml
al-damiri has joined #ocaml
initiumdoeslinux has joined #ocaml
nullifidian__ has quit [Read error: Connection reset by peer]
nullifidian_ has joined #ocaml
initiumdoeslinux has quit [Ping timeout: 250 seconds]
JimmyRcom has quit [Ping timeout: 272 seconds]
JimmyRcom has joined #ocaml
JimmyRcom has quit [Excess Flood]
JimmyRcom has joined #ocaml
pierpal has quit [Quit: Poof]
pierpal has joined #ocaml
jnavila has quit [Ping timeout: 246 seconds]
marvin2 has quit [Ping timeout: 250 seconds]
kroot_ has quit [Ping timeout: 244 seconds]
jnavila has joined #ocaml
initiumdoeslinux has joined #ocaml
initiumdoeslinux has quit [Ping timeout: 246 seconds]
igitoor has joined #ocaml
marvin2 has joined #ocaml
igitoor has quit [Changing host]
igitoor has joined #ocaml
KeyJoo has joined #ocaml
KeyJoo has quit [Quit: KeyJoo]
jao has joined #ocaml
jao has quit [Ping timeout: 250 seconds]
gravicappa has quit [Ping timeout: 244 seconds]
ggole has quit [Quit: ggole]
initiumdoeslinux has joined #ocaml
pierpa has joined #ocaml
Serpent7776 has joined #ocaml
initiumdoeslinux has quit [Ping timeout: 272 seconds]
recj has quit [Ping timeout: 240 seconds]
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
dmiles has quit [Ping timeout: 246 seconds]
dmiles has joined #ocaml
nullifidian__ has joined #ocaml
nullifidian_ has quit [Ping timeout: 250 seconds]
kakadu has quit [Read error: Connection reset by peer]
kakadu_ has joined #ocaml
emias has quit [Ping timeout: 245 seconds]
kakadu_ has quit [Remote host closed the connection]
Jeanne-Kamikaze has joined #ocaml
jnavila has quit [Ping timeout: 252 seconds]
Austin_Liu has joined #ocaml
Austin_Liu has quit [Client Quit]
emias has joined #ocaml
Serpent7776 has quit [Quit: leaving]
emias has quit [Ping timeout: 240 seconds]