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 quit [Remote host closed the connection]
ziyourenxiang has joined #ocaml
spew has quit [Quit: Connection closed for inactivity]
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
keep_learning has joined #ocaml
silver has quit [Read error: Connection reset by peer]
keep_learning has quit [Client Quit]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Read error: Connection reset by peer]
keep_learning has joined #ocaml
FreeBirdLjj has joined #ocaml
ygrek has joined #ocaml
oni-on-ion has joined #ocaml
mfp has quit [Ping timeout: 244 seconds]
FreeBirdLjj has quit [Remote host closed the connection]
Jeanne-Kamikaze has quit [Quit: Leaving]
gravicappa has joined #ocaml
kvda has joined #ocaml
_whitelogger has joined #ocaml
_whitelogger has joined #ocaml
bitonic has quit [Ping timeout: 252 seconds]
timeless has quit [Ping timeout: 258 seconds]
bytesighs has quit [Ping timeout: 244 seconds]
jyc___ has quit [Ping timeout: 252 seconds]
wildsebastian has quit [Ping timeout: 252 seconds]
chenglou has quit [Read error: Connection reset by peer]
lynn has quit [Read error: Connection reset by peer]
jeroud has quit [Ping timeout: 264 seconds]
andreypopp has quit [Ping timeout: 276 seconds]
angerman has quit [Ping timeout: 248 seconds]
Guest47930 has joined #ocaml
jyc___ has joined #ocaml
angerman has joined #ocaml
lynn has joined #ocaml
timeless has joined #ocaml
jeroud has joined #ocaml
bytesighs has joined #ocaml
chenglou has joined #ocaml
bitonic has joined #ocaml
wildsebastian has joined #ocaml
unyu has quit [Quit: unyu~]
unyu has joined #ocaml
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
brettgilio has joined #ocaml
brettgilio has quit [Remote host closed the connection]
keep_learning_M has joined #ocaml
caltelt_ has joined #ocaml
jao has quit [Ping timeout: 248 seconds]
ggole has joined #ocaml
_whitelogger has joined #ocaml
narimiran has joined #ocaml
caltelt_ has quit [Ping timeout: 272 seconds]
kakadu has joined #ocaml
narimiran has quit [Ping timeout: 258 seconds]
luna_is_here has joined #ocaml
ygrek has quit [Ping timeout: 248 seconds]
dr_df0 has joined #ocaml
ravenousmoose has joined #ocaml
dr_df0 has quit [Ping timeout: 248 seconds]
oni-on-ion has quit [Remote host closed the connection]
kvda has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ravenousmoose has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kvda has joined #ocaml
mfp has joined #ocaml
ravenousmoose has joined #ocaml
Guest53369 has joined #ocaml
FreeBirdLjj has joined #ocaml
kvda has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jnavila has joined #ocaml
Guest53369 has quit [Remote host closed the connection]
Haudegen has joined #ocaml
dimitarvp has joined #ocaml
kvda has joined #ocaml
pierpal has joined #ocaml
Anarchos has joined #ocaml
jnavila has quit [Ping timeout: 272 seconds]
_whitelogger has joined #ocaml
cedricvr has joined #ocaml
<cedricvr> Hi everybody, can I sak a nood question? Trying to implement a very simple “binary expression tree” in OCaml and the solution I have is not as concise as I would like. Could not find anything with Google.
<cedricvr> *ask
dimitarvp has quit [Quit: Bye]
<cedricvr> Here is what I have: type binOp = Sum | Mult
<cedricvr> type tree = Leaf of int | Node of tree * binOp * tree
<cedricvr> let t = Node(Leaf 2, Mult, Node(Leaf 3, Sum, Leaf 4))
<cedricvr> If I would do this in Python, I would create "Mult" and "Sum" classes then do "t = Mult(2, Sum(3, 4))" which is much more concise
<cedricvr> is there a way to get to the same level of concision using OCaml ?
<ggole> The int can't be bare like that, no
<ggole> You can make helper functions that avoid some of the boilerplate though
<cedricvr> OK. Can I at least not have to say "Mult" AND "Node" ? this feels redundant, a Multiplication will always be a tree node
<ggole> eg, let i x = Leaf x let mul x y = Node (x, Mult, y) let add x y = Node (x, Sum, y) and then you can write let t = mul (i 2) (sum (i 3) (i 4))
<cedricvr> ahaaan nice
<cedricvr> I also had this: type tree = Leaf of int | Mult of tree * tree | Sum of tree * tree
<ggole> Yeah, that's another alternative
<ggole> But that can make some kinds of pattern matching annoying.
<cedricvr> but then when I want to implement a lot of different binary operations I get a lot of redundance as well
<ggole> (When you have eight or nine binary ops.)
<cedricvr> true
<ggole> So I would do it the way you have here, and use functions to make constructing the tree shorter.
<cedricvr> ok, thanks
kvda has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kvda has joined #ocaml
<cedricvr> It's me again, trying to be even more concise. I would like to get rid of the "i" thing. So I would like my helper functions "mul" and "sum" to have the following behavior:
<cedricvr> if an input is an int, we make a Leaf out of it; otherwise if it's a tree (be it Leaf or Node), we insert it as-is
<cedricvr> here is my (failed) attempt:
<cedricvr> let leaf_if_int x = function | int -> Leaf x | tree -> x
<cedricvr> compiler is not very happy:
<cedricvr> Error: This expression has type int but an expression was expected of type tree
<ggole> Yeah, that's not going to work.
<ggole> You can't dispatch on the type of a variable in OCaml.
<cedricvr> I was trying to get inspiration from this:
<cedricvr> (and the few previous pages)
<cedricvr> so the behavior I am trying to obtain is just not possible ? sort of "casting"
Anarchos has quit [Quit: Vision[0.10.3]: i've been blurred!]
zolk3ri has joined #ocaml
jao has joined #ocaml
<ggole> Not in any sane way, no.
<ggole> An OCaml value can't be either an int or a tree, that's a type error.
<ggole> The way you express 'either int or tree' is to use a variant, eg, put in the constructor that you are trying to get rid of.
<cedricvr> ok, thank you for these explanations
<ggole> You're coming from the dynamic language world, I take it?
zmt00 has joined #ocaml
zmt01 has quit [Ping timeout: 250 seconds]
Guest47930 has quit []
andreypopp has joined #ocaml
<cedricvr> yes
<cedricvr> Yeah I guess this is for the same reason that there is "+" and "+." in OCaml, even tough we say that the "+" function "casts integers to floats if there is a float in the inputs"?
<cedricvr> *we *could* say that
AtumT has joined #ocaml
<ggole> More or less, yeah
jbrown has quit [Remote host closed the connection]
narimiran has joined #ocaml
jnavila has joined #ocaml
int-e has quit [Ping timeout: 276 seconds]
int-e__ has joined #ocaml
int-e__ has left #ocaml [#ocaml]
int-e has joined #ocaml
kvda has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jbrown has joined #ocaml
iovec has joined #ocaml
cedricvr has quit [Quit: Bye]
luna_is_here has quit [Ping timeout: 252 seconds]
pierpal has quit [Ping timeout: 246 seconds]
_whitelogger has joined #ocaml
dr_df0 has joined #ocaml
keep_learning_M has quit [Quit: This computer has gone to sleep]
oni-on-ion has joined #ocaml
jbrown has quit [Remote host closed the connection]
FreeBirdLjj has quit [Remote host closed the connection]
keep_learning_M has joined #ocaml
keep_learning_M has quit [Quit: This computer has gone to sleep]
dr_df0 has quit [Ping timeout: 258 seconds]
amosbird has quit [Remote host closed the connection]
amosbird has joined #ocaml
zolk3ri has quit [Remote host closed the connection]
amosbird has quit [Quit: ZNC 1.8.x-git-unknown - https://znc.in]
amosbird has joined #ocaml
dr_df0 has joined #ocaml
ziyourenxiang has quit [Ping timeout: 248 seconds]
dr_df0 has quit [Ping timeout: 245 seconds]
niklasl2 has joined #ocaml
niklasl has quit [Ping timeout: 268 seconds]
niklasl has joined #ocaml
andrewlitteken has joined #ocaml
niklasl2 has quit [Ping timeout: 248 seconds]
narimiran has quit [Ping timeout: 248 seconds]
KeyJoo has joined #ocaml
KeyJoo has quit [Quit: KeyJoo]
ravenousmoose has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ravenousmoose has joined #ocaml
gravicappa has quit [Ping timeout: 272 seconds]
dr_df0 has joined #ocaml
ravenousmoose has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ravenousmoose has joined #ocaml
oni-on-ion has quit [Ping timeout: 252 seconds]
dr_df0 has quit [Quit: leaving]
dr_df0 has joined #ocaml
<dr_df0> Hi All! I have a problem that hopefully someone could help me with. I'm trying to build (via ocamlopt) simple app that is using sqlite3 library installed via opam
<dr_df0> when I open the library from utop it works fine after issuing #require ... and then Open Sqlite3;;
<dr_df0> but when placed in .ml file (without #require of course) I get an error
<companion_cube> ocamlfind ocamlopt -package sqlite3 -linkpkg foo.ml -o foo
<dr_df0> ok, I was using: ocamlfind ocamlopt -package sqlite3 test.ml
<dr_df0> let me check
<companion_cube> (this builds an executable, if you want multiple files in the project it gets more complicated and I'd suggest to use a modern build system)
<companion_cube> -linkpkg is needed for the final binary :)
<companion_cube> (not for intermediate files)
<dr_df0> @companion_cube: perfect!! thanks a million
<dr_df0> works like a charm
<companion_cube> :)
ravenousmoose has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dr_df0> companion_cube: by modern build system you mean e.g. dune?
<dr_df0> companion_cube: or ocamlbuild?
<Armael> dune :)
<companion_cube> I mean dune, yes :)
<dr_df0> ok, need to do some reading ... but at first glance it looks a little bit ... lispy ?
<companion_cube> yeah, the config is s-exprs
silver has joined #ocaml
jbrown has joined #ocaml
jack5638 has quit [Ping timeout: 246 seconds]
ggole has quit [Quit: Leaving]
jack5638 has joined #ocaml
sapristi has joined #ocaml
sapristi has quit [Remote host closed the connection]
sapristi has joined #ocaml
silver_ has joined #ocaml
silver has quit [Ping timeout: 244 seconds]
JimmyRcom has joined #ocaml
sapristi has quit [Remote host closed the connection]
iovec has quit [Quit: Connection closed for inactivity]
jnavila has quit [Ping timeout: 246 seconds]
Netsu has joined #ocaml
<Netsu> companion_cube: >>> you can't go from existential to universal :) <<< welp, what do you think about: https://gist.github.com/Pitometsu/33e394c9b50a8259bbf3ecbb1c0c2599
<companion_cube> your "universal" is just an existential in continuation passing style :)
<Armael> looks like a double negation encoding
<companion_cube> ^
kakadu has quit [Remote host closed the connection]
<Netsu> so is it Skolem normal form there?
<companion_cube> I'd say it's a Church encoding
silver_ has quit [Ping timeout: 272 seconds]
narimiran has joined #ocaml
dr_df0 has quit [Ping timeout: 246 seconds]