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> Any help would be appreciated
<reynir> what library?
<reynir> psacrifice: ^
<psacrifice> Std like how ocaml had Core.Stf
<psacrifice> *Core.Std
<reynir> you can find Core documentation here (select your version) https://ocaml.janestreet.com/ocaml-core/
<reynir> psacrifice: you can also use ocp-index, it can print doc strings from the installed files (press alt+h when runnng ocp-browser)
<psacrifice> reynir: What is the recommended way to use it inside ReasonML?
<reynir> I also made a total hack so you can use ocp-index to lookup documentation in the toplevel/utop https://github.com/reynir/ocp-index-top
<reynir> psacrifice: use what?
<psacrifice> Looking into ocp-index, Thanks
<psacrifice> Use OCaml Core.Std inside ReasonML?
<reynir> Uh, use it in the same way as if it was OCaml?
<psacrifice> Oh
<reynir> Reason basically *is* OCaml
<reynir> There's some 'reason' tool for translating OCaml into the equivalent Reason code - you can use that if you're in doubt about the syntax
<psacrifice> reynir: Can you point me to the write docs translating ocaml code to Reason with this 'reason' tool?
<psacrifice> *Can you point me to some docs..
<psacrifice> Pardon the typos
<reynir> I don't remember the name, but I can take a quick look...
<psacrifice> Also, Printf.printf didn't work in reason. Am I to link with any library during compilation?
<reynir> Maybe it's refmt
<reynir> No, that should just work, I think
<reynir> What is the error?
<psacrifice> File "Hello.re", line 1, characters 14-33:
<psacrifice> but an expression was expected of type
<psacrifice> Error: This expression has type 'a * 'b
<psacrifice> ('c, out_channel, unit) format =
<psacrifice> ('c, out_channel, unit, unit, unit, unit)
<psacrifice> CamlinternalFormatBasics.format6
<psacrifice> Command exited with code 2.
<psacrifice> Printf.printf ("Hey %s", "Foobar");
<reynir> It's a type error
<reynir> So, in OCaml you should write »Printf.printf "Hey %s" "Foobar"« and I think it's exactly the same in reasonml
<reynir> The error is a bit misleading. OCaml has special compiler magic for format strings. This format/format6 business is what "Hey %s" turns into.
<psacrifice> Removing the parentheses helped
<reynir> the type of ("Hey %s", "Foobar") is string * string, i.e. a pair of strings
<reynir> Not sure why the compiler generalized it to 'a * 'b though
<psacrifice> so I read (hopefully not misread) that the parentheses are optional
<reynir> Where does it say that?
<psacrifice> let double = fun x => x + x; Example
<reynir> OK, I see. Yea, that's very misleading
<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
<reynir> Yea, pretty much
<reynir> tab-completion should work
<psacrifice> Can be installed with opam?
<reynir> Yes
<reynir> hold on
<reynir> opam pin add ocp-index-top https://github.com/reynir/ocp-index-top.git
<reynir> It's not released, so you have to pin it (sorry)
<reynir> It's a hack I made in two days, basically
psacrifice has quit [Ping timeout: 240 seconds]
psacrifice has joined #reasonml
<psacrifice> reynir: Reason:Ocaml::Elixir:Erlang?
<reynir> Uh
<reynir> I don't know Elixir that well, but I think it's more drastic than Reason
<psacrifice> I see
<reynir> Reason is a different syntax for OCaml + some tools, I would say
<reynir> I think Elixir:Erlang is more like Scala:Java
<reynir> Again, not sure
<psacrifice> Same bytecode underneath those languages, whereas Reason actually precompiles to Ocaml?
<psacrifice> think I have my answer https://facebook.github.io/reason/#how-reason-works
<reynir> Essentially, yes. Reason is OCaml with a different parser
psacrifice has quit []
Planet_EN has joined #reasonml
nomicflux has joined #reasonml
nomicflux has quit [Quit: nomicflux]
Planet_EN has quit [Quit: Textual IRC Client: www.textualapp.com]
copy` has joined #reasonml
FrigoEU has joined #reasonml
FrigoEU has quit [Quit: Textual IRC Client: www.textualapp.com]
hashpuppy has joined #reasonml
strykerkkd has joined #reasonml
stryker_kkd has joined #reasonml
strykerkkd has quit [Remote host closed the connection]
hashpuppy has quit [Quit: Connection closed for inactivity]
stryker_kkd has quit [Quit: Leaving]