chenglou changed the topic of #reasonml to: facebook.github.io/reason/. Public channel logs at irclog.whitequark.org/reasonml. Discord: discord.gg/reasonml
nomicflux has quit [Quit: nomicflux]
nomicflux has joined #reasonml
nomicflux has quit [Quit: nomicflux]
nomicflux has joined #reasonml
nomicflux has quit [Quit: nomicflux]
copy` has quit [Quit: Connection closed for inactivity]
psacrifice has joined #reasonml
rseymour has quit [Ping timeout: 240 seconds]
<psacrifice>
Hi. I just got started with ReasonML. I'm looking for library docs. C
<psacrifice>
What is the right way to call functions?
<psacrifice>
let addTupleFields = fun (first, second) => {
<psacrifice>
first + second
<psacrifice>
};
<psacrifice>
let five = addTupleFields (4, 1);
<psacrifice>
let myTuple = (4, 1);
<psacrifice>
let five = addTupleFields myTuple;
<psacrifice>
I assumed function args are just tuples
<reynir>
You can use tuples everywhere, but it's way more common to use currying, that is, pass one argument at a time
<reynir>
So, it's more common to write »let add = fun first second => { first + second }; let five = add 4 1«
<psacrifice>
Is it common in all functional langs are only ML. I'm a functional prog newbie.
<psacrifice>
Wait
<psacrifice>
Isn't that two args?
<psacrifice>
fun first second => { first + second };
<reynir>
In StandardML it's common to use tuples, but in OCaml and Haskell (and more) it's common to use currying
<reynir>
psacrifice: strictly speaking it's two arguments. It's equivalent to »fun first => { fun second => { first + second } }«
<reynir>
Try this: »let add = fun first => { fun second => { first + second } }; let five = add 4 1«
rseymour has joined #reasonml
<reynir>
(Sorry if I got the syntax wrong; I don't use reasonml)
<psacrifice>
That add 4 1 is more like add(4)(1) in JS?
<reynir>
Yes
<psacrifice>
Ah. Looked like add(4, 1)
<psacrifice>
My bad
<reynir>
But it's less heavy syntax-wise than in JS heh
<psacrifice>
So why currying over multiple args?
<reynir>
»function add(first) { return function (second) { return first + second } }« D:
<psacrifice>
> less heavy syntax. yes yes. Love it
<psacrifice>
As we were speaking, why currying over multiple args?
<reynir>
psacrifice: Currying is super useful when you use higher order functions. Like, »let add = fun first second => first + second; let myList = [1, 2, 3]; let myBetterList = List.map (add 1) myList«
<psacrifice>
I guess for an OO programmer I'll have to rewire my perspective here
<reynir>
^ myBetterList returns [2, 3, 4], i.e. we've added 1 to each element in myList
<psacrifice>
Got that
<reynir>
Without currying we would have to write a wrapper function
<reynir>
So, »let add = fun (first, second) => first + second; let myList = [1, 2, 3]; let myBetterList = List.map (fun x => add (1, x)) myList«
<psacrifice>
Is this because many primitives are built around single arg accepting HO functions, like the List.Map?
<reynir>
Yea
<psacrifice>
Thank you. Thats some fresh perspective
<psacrifice>
Also just one more thing. Confirming again add (first, second) is like add(first)(second)
<psacrifice>
I'm still a little confused
<psacrifice>
add is of type int -> int -> int
<reynir>
No, add(first,second) is not the same
<reynir>
Hmm
<psacrifice>
ok
<psacrifice>
Please correct me on add(first,second)
<psacrifice>
What is add(first,second) ?
<reynir>
So, javascript doesn't have tuples, so I'll use arrays for this example since it's the closest. add (first, second) is equivalent to add([first, second]) in javascript
<psacrifice>
Oh
<reynir>
add (first, second) is calling first with a single argument that is a new tuple consisting of first and second
<psacrifice>
Damn! Thank you so much. Is it me or the docs?
<psacrifice>
What was that they were trying to say in the docs
<reynir>
No, I don't think it was you
<reynir>
at least, I fully understand how you could interpret it like you did
<psacrifice>
Never use parens in function call unless you're passing a tuple - make this the take away from this convo?
<psacrifice>
And ofc, currying :)
<reynir>
Yea, I would never use parens unless it's required. One is tuples, another is when applying functions: so in JS: f(g(x)) would be f (g x), and f(1 + 2) would be f (1 + 2)
<psacrifice>
Oh yes, that too
<reynir>
function application (»f x«) binds stronger than operators like '+' so you need parens in that case
<reynir>
ok cool
<psacrifice>
Is it fine to assume that functions don't take multiple args in ML?
psacrifice has quit [Remote host closed the connection]
psacrifice has joined #reasonml
<reynir>
psacrifice: Yes, well. In a sense *all* functions in OCaml take one argument only. How they then "take" multiple arguments anyway is either by tuples or, more commonly, through currying
<reynir>
psacrifice: there's a slack or gitter or whatever next new thing they're using where most people hang out
<reynir>
You can probably find more help there (if you don't mind your browser hogging your system)
<psacrifice>
Haha
<psacrifice>
I realise that
<psacrifice>
And thanks :)
<reynir>
No problem, you're welcome
<reynir>
psacrifice: you can also consider joining #ocaml, lots of helpful people there. It's better for OCaml questions, though
<reynir>
(so use refmt to translate back and forth between the syntaxes I guess :D)
<psacrifice>
Reminds me
<psacrifice>
Your hook
<psacrifice>
to translate syntax
<reynir>
you mean ocp-index-top? Sorry, that's not for translating syntax - only for lookup up types and documentation
<psacrifice>
I little lost going throught the ReadMe
<psacrifice>
How is it meant to be used?
<reynir>
Wait, what hook are you talking about?
<psacrifice>
ocp-index-top
<psacrifice>
#doc <function>
<psacrifice>
Is that right
<psacrifice>
?
<reynir>
In utop (or rtop? I guess), you first require it »#require "ocp-index-top"«, and then you can use the #doc directive