shp changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 4.00.1 http://bit.ly/UHeZyT | nohttp://www.ocaml-lang.org | Public logs at http://tunes.org/~nef/logs/ocaml/
<wmeyer> troydm: I like that you asked, but there is no definitive answer for this
<troydm> wmeyer: ic, thx
<troydm> well putting something into opam is not a difficult task
<troydm> i think ocaml monad library will be eventually added to it
<wmeyer> troydm: write your library yourself, we would be delighted to see it
<wmeyer> there is pa_monad_custom which is a Camlp4 syntax exension to write monadic code
<troydm> ic but that means in need to figure out how to use camlp4 etc
<wmeyer> troydm: in general yes
<troydm> well not that i want to use monads anyway
<wmeyer> troydm: monads are good for introduction to functional programming in general
<troydm> wmeyer: yeah, i know, i've learned using them in haskell
<wmeyer> troydm: in OCaml maybe State or IO monad is less useful, but monads usually are customised for needs
<troydm> i'm still learning ocaml ways so :)
<troydm> actually i'm reading o'really developing in ocaml
<wmeyer> sure, good luck. Purity has some certain advantage
<troydm> but i've find a little bit boring to read
<troydm> i've only read 100 pages so far
<wmeyer> that's just because you already know Haskell
<troydm> so i'm not even near stuff that interests me :)
leoncamel has joined #ocaml
<troydm> like toplevel and tools
nickmeharry has joined #ocaml
lolcathost has quit [Quit: leaving]
<wmeyer> troydm: tools are equally important
<Qrntz> OCaml could probably have some use for the Maybe monad, but that's still pretty subjective
<wmeyer> seems to better than exceptions at a cost (or not) staying inside it
<wmeyer> (and runtime costs)
<thelema> Qrntz: batteries has 'a result, which encapsulates an exception or a result value
<Qrntz> nice
<thelema> plus all the natural functions on it, including monadic ones
emmanuelux has quit [Remote host closed the connection]
lolcathost has joined #ocaml
xavierm02 has quit [Quit: Leaving]
<wmeyer> gtg, see you all
wmeyer has left #ocaml []
lolcathost has quit [Quit: leaving]
<hongboz> monad is not that useful, since we don't have type class..
Yoric has joined #ocaml
Yoric has quit [Ping timeout: 272 seconds]
lolcathost has joined #ocaml
madroach has quit [Ping timeout: 244 seconds]
madroach has joined #ocaml
wks has joined #ocaml
ftrvxmtrx has joined #ocaml
oriba has quit [Quit: oriba]
Automorphism has joined #ocaml
milosn has quit [Ping timeout: 244 seconds]
milosn has joined #ocaml
Automorphism has quit [Quit: leaving]
lolcathost has quit [Quit: leaving]
<wks> Is it possible to create a "one-tuple" in ocaml?
Automorphism has joined #ocaml
<thelema> wks: no, tuples are created with ,
<_habnabit> (1,) is a one-tuple in python. that's no excuse!
<thelema> wks: you can create a one-field record or one-enry array
<thelema> _habnabit: it's a syntax error in ocaml
<thelema> *entry
<rwmjones> 6
<rwmjones> oops
Automorphism has quit [Quit: leaving]
milosn has quit [Ping timeout: 264 seconds]
mye has joined #ocaml
ftrvxmtrx has quit [Ping timeout: 248 seconds]
lolcathost has joined #ocaml
ftrvxmtrx has joined #ocaml
tac has joined #ocaml
weie has joined #ocaml
Guest81435 has joined #ocaml
lolcathost has quit [Ping timeout: 264 seconds]
Guest81435 has left #ocaml []
lolcathost has joined #ocaml
hongboz has quit [Ping timeout: 255 seconds]
mye_ has joined #ocaml
mye has quit [Ping timeout: 264 seconds]
mye_ is now known as mye
Yoric has joined #ocaml
wks has quit [Quit: Konversation terminated!]
Automorphism has joined #ocaml
lolcathost is now known as Guest15717
Automorphism is now known as lolcathost
Guest15717 has quit [Ping timeout: 272 seconds]
tac has quit [Quit: Page closed]
hongboz has joined #ocaml
gour has joined #ocaml
lolcathost is now known as Playground
hongboz has quit [Ping timeout: 265 seconds]
Cyanure has joined #ocaml
Kakadu has joined #ocaml
ttamttam has joined #ocaml
Yoric has quit [Remote host closed the connection]
Yoric has joined #ocaml
weie has quit [Ping timeout: 255 seconds]
Cyanure has quit [Remote host closed the connection]
djcoin has joined #ocaml
BiDOrD_ has joined #ocaml
tac-tics has joined #ocaml
BiDOrD has quit [Ping timeout: 244 seconds]
mye has quit [Ping timeout: 240 seconds]
mika1 has joined #ocaml
weie has joined #ocaml
cago has joined #ocaml
tac-tics has quit [Quit: Page closed]
Cyanure has joined #ocaml
milosn has joined #ocaml
jbrown has joined #ocaml
tac has joined #ocaml
ontologiae has joined #ocaml
ontologiae has quit [Ping timeout: 240 seconds]
thomasga has joined #ocaml
Playground has quit [Quit: b(not so)rb]
Submarine has joined #ocaml
Submarine has quit [Changing host]
Submarine has joined #ocaml
RagingDave has joined #ocaml
shp has joined #ocaml
<shp> hi
<shp> i'd like to do a "and" filter in ocaml. Something like "0x231322 & 0xFF;;"
<flux> use the land-operator
<flux> (similarly, lor)
<flux> or let (&) = (land) ;-)
<shp> ty!
tac has quit [Ping timeout: 245 seconds]
_andre has joined #ocaml
myx has joined #ocaml
ontologiae has joined #ocaml
jbrown has quit [Ping timeout: 276 seconds]
jbrown has joined #ocaml
middayc has joined #ocaml
mika1 has quit [Quit: Leaving.]
pango has quit [Remote host closed the connection]
pango has joined #ocaml
RagingDave has quit [Quit: Ex-Chat]
jbrown has quit [Ping timeout: 272 seconds]
jbrown has joined #ocaml
RagingDave has joined #ocaml
pango has quit [Ping timeout: 252 seconds]
ttamttam has quit [Quit: ttamttam]
pango has joined #ocaml
pango has quit [Read error: Operation timed out]
_andre has quit [Quit: leaving]
_andre has joined #ocaml
pango has joined #ocaml
mcclurmc_away is now known as mcclurmc
mika1 has joined #ocaml
mika1 has quit [Quit: Leaving.]
ttamttam has joined #ocaml
<emias> 4
<emias> (Sorry.)
<orbitz> 5
fraggle_ has joined #ocaml
xavierm02 has joined #ocaml
q66 has joined #ocaml
mika1 has joined #ocaml
Yoric has quit [Quit: Instantbird 1.4a1pre -- http://www.instantbird.com]
beckerb has joined #ocaml
chambart has joined #ocaml
Yoric has joined #ocaml
philed` has joined #ocaml
philed has quit [Read error: Operation timed out]
Oejet has joined #ocaml
fraggle_laptop has joined #ocaml
troydm has quit [Quit: What is hope? That all of your wishes and all of your dreams come true? (C) Rau Le Creuset]
smerz has quit [Remote host closed the connection]
beckerb has quit [Ping timeout: 264 seconds]
pango has quit [Ping timeout: 240 seconds]
beckerb has joined #ocaml
pango has joined #ocaml
RagingDave has quit [Read error: Connection reset by peer]
<philed`> Though troydm's quit, I've got a monad library here: https://github.com/Chattered/ocaml-monad and would welcome feedback.
pango has quit [Ping timeout: 264 seconds]
RagingDave has joined #ocaml
_s_l_a_c_k has joined #ocaml
<shp> how create a function that takes no argument ? (let function = [ ... ] ;; does not seem to work as a function)
<Qrntz> you can't have zero-arity functions in OCaml
<Qrntz> only unit-taking functions
<Qrntz> «let f () = …»
<Qrntz> methods of classes can have zero arguments, though
suyu has quit [Quit: suyu]
pango has joined #ocaml
<thelema> shp: no arguments = value, need an argument like unit for it to be a function, as Qrntz said.
<thelema> shp: while there are reasons for unit functions (such as to trigger side effects), try to make real functions (that compute their output from their input) as often as possible
smondet has joined #ocaml
<shp> ok thanks
<xavierm02> I get this error
<xavierm02> Fatal error: exception Match_failure("BooleanExpressionFiles/AlgebraicManipulation.ml", 29, 10)
<xavierm02> it's on line 13 here
<Qrntz> non-exhaustive pattern matching
<xavierm02> since I only paste the relevant bit
<xavierm02> well
<xavierm02> I match _
<xavierm02> so it shouldn't >_<
<Qrntz> it does
<Qrntz> you should parenthesize the matches
<Qrntz> both the more indented and the less indented «_»s are interpreted as branches of «match r with…»
<xavierm02> ok
<Qrntz> branches that have equal patterns, to the latter one is eliminated and «match l with …» ends up having no catch-all
<xavierm02> ty :)
<xavierm02> it fixed it
<Qrntz> np
jewel has joined #ocaml
troydm has joined #ocaml
<thelema> xavierm02: maybe you should use: match l,r with ...
<thelema> instad of nesting the matches
<xavierm02> well
<xavierm02> then it would be slower
<xavierm02> because it would have to match several times
<xavierm02> the same thing on the left
<orbitz> is this a pefromance bottleneck currently?
<xavierm02> no
<xavierm02> idk
<orbitz> then who cares?
<xavierm02> okay
<orbitz> write the cleanest code, make it ugly for speed when you need to
philed` is now known as philed
<thelema> matching is surprisingly fast; this is one place that's been well optimized in the compilr
tane has joined #ocaml
<Qrntz> does matching on a tuple still allocate one?
<orbitz> no
shp has quit [Quit: kit]
<thelema> Qrntz: matching on tuples is great.
<Qrntz> okay, thanks
<orbitz> I can't find the link, someone posted a blog post about wanting benchmarks, but they talked about tuple optimizations in it
<xavierm02> BinOp (ll, lo, lr), BinOp (rl, ro, rr) when lo <> o and ro <> o ->
<xavierm02> how do I write this?
<orbitz> thelema: yep that's the one
<thelema> s/and/&&/
<xavierm02> ty :0
<xavierm02> :)
Cyanure has quit [Remote host closed the connection]
<madroach> I'm getting ounit test failures for current oasis on OpenBSD. Now I'm wondering how to debug them.
<xavierm02> is this better http://pastebin.com/T0wvjav2 ?
<thelema> madroach: pastebin them?
<xavierm02> and any other suggestions to improve it?
<thelema> xavierm02: this is getting a bit verbose, but you can probably inline even further
<orbitz> Is this just supposed to execute an AST?
<xavierm02> no
<thelema> | binop(l,o,r) when o <> times -> binop_ o (loop l) (loop r)
<xavierm02> it's supposed to transform
<xavierm02> (a+b)(c+d) into ac+ad+bc+bd
<xavierm02> where + is either ^ or v
<orbitz> ah, neat
<thelema> | binop(binop(ll,lo,lr),o,binop(rl,ro,rr)) when ... ->
<xavierm02> hm
<xavierm02> i got it thelema
<thelema> also, it may make things easier to go from <> times to = times
<xavierm02> i don't understand
<xavierm02> that last setence
<thelema> if only times was a variant constructor known statically, then the matching would be much easier
ulfdoz_ has joined #ocaml
<thelema> the last sentence refers to how the tests are all o <> times
<xavierm02> yeah
<xavierm02> I should write o = plus instead?
<xavierm02> times and plus
<xavierm02> are from type
jbrown has quit [Ping timeout: 264 seconds]
<xavierm02> And | Or
<thelema> are these fixed?
<xavierm02> no
<xavierm02> times can be either
<xavierm02> and plus is the other one
<thelema> ah, ok.
<xavierm02> i just wrote times and plus
<xavierm02> because with or and and I keep forgetting how to distribute
<xavierm02> whereas times and plus fixes ideas
<thelema> instead of "when lo <> o && ro <> o", "when lo <> o", and "when ro <> o", reverse the order and use "when lo = o && ro = o", "when lo = o", and "when ro = o"
ulfdoz has quit [Ping timeout: 255 seconds]
ulfdoz_ is now known as ulfdoz
<xavierm02> thelema
<xavierm02> I dont think I can
<xavierm02> because the _ could be other things
<xavierm02> like Not
<xavierm02> they don't have to be BinOp
<xavierm02> and if I start filtering all those case, I'll have like 20 match cases
<madroach> ok, here are the test logs: http://hpaste.org/80168
<madroach> (of the oasis regression tests.
<xavierm02> I updated again http://pastebin.com/vsFC8D1U
<thelema> xavierm02: when lo = plus && o = times && ro = plus
<xavierm02> you mean they should appear in the same order as in the pattern?
alxbl has quit [Ping timeout: 255 seconds]
<thelema> xavierm02: I think that makes the logic clearer
<thelema> it's not necessary at all
<xavierm02> k
jbrown has joined #ocaml
_s_l_a_c_k has quit [Quit: leaving]
mika1 has quit [Quit: Leaving.]
cago has left #ocaml []
<xavierm02> any ideas on what I could do to make that code more idiomatic? http://pastebin.com/C4AENver
<xavierm02> it prints a boolean expression represented by a tree
<xavierm02> trying to avoid to put useless parenthesys
<xavierm02> so instead of (0v1)v2 this should print 0v1v2
<xavierm02> because v is associative
<thelema> xavierm02: pass in the current op, and parenthesize if the current node is not the same op
<thelema> also, use a sub function to simplify the last case's duplication
<ontologiae> Hi, i have a stupid question : I have a file Myfile.ml, and would like to make a module Myfile with signature and a struct, but without to have to write Myfile.Mymodule.function
<ontologiae> how i can do that ?
<thelema> madroach: I think these failures will have to be dealt with by sylvain; can you post with a bit more detail to https://forge.ocamlcore.org/tracker/?atid=291&group_id=54&func=browse
<thelema> ontologiae: you can specify the signature for myfile in myfile.mli
<thelema> ontologiae: you can use 'open Myfile' to simplify the naming
<thelema> ontologiae: why do you want the function in a submodule?
<ontologiae> thelema: i don't want the function in submodule. Ok, so i have to make an mli
<thelema> ontologiae: just put the sig you want in the .mli
tac has joined #ocaml
pango has quit [Read error: Connection reset by peer]
thomasga has quit [Quit: Leaving.]
pango has joined #ocaml
milosn has quit [Remote host closed the connection]
shp has joined #ocaml
<shp> hi
<orbitz> hi
<shp> i'd like to know the type of OImages.rgb24 in camlimages
<shp> (i need to make an empty reference)
<orbitz> check the source?
<orbitz> what is an empty reference?
<orbitz> OImages.rgb24 option ref ?
<shp> let variable = ref NULL; then later variable := 0Images.rgb24 arguments ;;
<shp> i checked the source but found nothing useful with grep
<orbitz> what is NULL?
<adrien_oww> noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
<shp> orbitz: matter of speaking
<orbitz> shp: why do you want this?
<shp> i want to put the equivalent to null
<shp> but i don't know the type of OImages.rgb24
<pippijn> shp: you want option
<orbitz> WHy do you need to kno whe type of OImages.rgb24 to do this?
<shp> option ? what do you mean ? orbitz: how do otherwise ?
<orbitz> shp: how will knowing the type of OImages.rgb24 (which is a type of its own) allow you to set a NULL?
<shp> ?
<Qrntz> ?
<shp> i want to declare a reference that will receive "OImages.rgb24 argument". How can i do so?
<orbitz> shp: I don't understand why you think you need to know more about OImages.rgb24 in order to have 'NULL'
<orbitz> OImages.rgb24 ref
<jonafan> short answer: let variable = ref None, then later variable := Some (OImages.rgb24 args)
<shp> thank you, i didn't know that i could do that
<orbitz> Do you understand what is going on?
<pippijn> shp: why do you need a variable?
<shp> for my program , i don't understand your question
<orbitz> why do you need something that changes?
<pippijn> why do you need a mutable variable
<orbitz> I have used a reference in Ocaml like 3 times in 3 years
<shp> ?
<shp> i need a variable in a for loop
<jonafan> o no he didannnntt
<orbitz> Why do you have a for loop?
<shp> that will change each time the program enters the loop
<shp> why not?
<orbitz> because recursion is generally how people loop i nfunctional languages
<pippijn> also
<shp> too heavy
<shp> there would be too many variables on the stack
<pippijn> no, actually that's lighter
<orbitz> why do you think recursion is too heavy?
<shp> i presume it works like that
<pippijn> and that's incorrect
<orbitz> it doesn't
<pippijn> anyway, you can loop
<pippijn> but do you need access to the variable outside the loop?
<shp> in C, recursion is bad, because it "pop" "pop" pop" .... on the stack, and the stack become far too big
<pippijn> shp: ocaml is not C
<jonafan> using a reference is less efficient
<pippijn> shp: in ocaml, there is guaranteed tail recursion optimisation
<orbitz> shp: i think you mean 'push push push', and that isn't even entirely correct in C
<jonafan> in ocaml, the recursion will essentially be a loop at runtime
<pippijn> and in C, modern compilers also do that
<shp> yes push sure
<shp> ok, so someone told me craps
<jonafan> (assuming you write your recursive function correctly)
<orbitz> which part?
<shp> i'm gonna try a recursion so thx
<pippijn> write it tail-recursively
<shp> what do you mean ?
<pippijn> this
<mk270> shp: every call to the recursive function has to be the *final* thing the function does (in that code path)
<mk270> otherwise yo ucan't optimise away the previous applications of the function so easily
<shp> i see
<mk270> (in practice, if you write a recursive function which isn't tail-recursive, you will oftne run out of stack at runtime, if it recurses a couple of miilllion times
<mk270> )
<thelema> in practice, non-tail recursive functions usually don't get the chance to blow the stack, except in limited circumstances
<shp> so there's really no difference of optimization between a recursion and an iterative program ? only the length of code that is smaller in the first case ?
<mk270> i should have said "sometimes, i.e., in some real-world non-contrived situations"
<shp> how modify a variable in a function already used ? an equivalent to "let a = 3;; let a = 4;;" but in a function because of the "let a = 3 IN" i'm not sure we can modify a
<shp> i used to use references but <orbitz> I have used a reference in Ocaml like 3 times in 3 years
<tac> You need to ask yourself why you want to modify a to begin with.
<shp> to use less variables tac
<thelema> shp: instead of modifying a variable, enter a new function contxt where that variable has a new value
<shp> let img = (OImages.rgb24 (OImages.load "X.jpeg" []));; let img = (transform img);; let img = reduction img;;
<thelema> it's a different way of thinking about programming.
<shp> i prefer that than using 3 different variables
<thelema> shp: if you define (|>) as usual, you can write
<tac> btw, shp, do you have a link to the code you're working on or anything like that?
<thelema> let img = OImages.load "X.jpeg" [] |> IOmages.rgb24 |> transform |> reduction in...
<shp> let img = (OImages.rgb24 (OImages.load "X.jpeg" [])) in let img = (transform img) in let img = reduction img;; would work ?
<thelema> shp: the usual definition of (|>) is: `let (|>) x f = f x`
<thelema> yes, that would work as well.
<shp> tac: i'm just beginning a new one, so nothing elaborate, it isn't worth copy past
<thelema> be aware that you're not modifying the value of "img", but instead making a new scope in which img refers to a different value
<shp> ok, so if i give a different names, it's exactly the same in term of memory use ?
<shp> -s
<thelema> yes
<thelema> the |> pattern allows the old values to be GC'ed
<mk270> why not:
<mk270> reduction (transform (OImages.rgb24 (OImages.load "X.jpeg" [])))
<thelema> mk270: it's backwards of the order of execution and has too many ()
<thelema> at least that's why I prefer |>
<mk270> yes yes i know :)
<mk270> i wasn't aware of |>
<thelema> batteries and core both provide it, although core spells it |!
<mk270> aahhh
<mk270> the forbidden fruits
RagingDave has quit [Read error: Connection reset by peer]
RagingDave_ has joined #ocaml
<mk270> my life was happier and simpler before i knew this :)
<thelema> |> or batteries/core?
<shp> thelema: last thing: if reduction takes 3 arguments (reduction image n p) let img = firstFunction |> reduction n p ?
<thelema> shp: wrong order; piped in value must be last argument
<shp> ok
<thelema> otherwise, just interrupt your pipeline, giving a name to the value, and use that name where you need it
<thelema> easier is to just change order of arguments
<shp> Error: Illegal character (\160)
clam has joined #ocaml
<thelema> shp: ocaml source files are latin-1
<thelema> and only alphabetic chars can be in identifiers
<shp> Unbound value |>
<thelema> did you add the `let (|>) x f = f x` line?
<thelema> |> is not built in to ocaml
<shp> ah ok!
thomasga has joined #ocaml
<shp> is this a tail recursion : "let rec blabla argument = [...] [liste]::(blabla buff);; " ?
<thelema> no
<thelema> because the return value of blabla isn't directly returned
mcclurmc is now known as mcclurmc_away
<shp> and how can i fix that? i need to concatenate the return to a list
<orbitz> concatenate or cons?
<orbitz> does this fit into map or fold?
_andre has quit [Quit: Lost terminal]
<orbitz> Does the order of the list matter?
<shp> the order does not matter orbitz
<orbitz> shp: so how to maek that tail recursive depends on a bunch of factors. One might have to see the whole code to give you concrete tips.
<thelema> shp: pass the partial list along as an additional argument:
<gour> labelled params and args are used often in ocaml?
<orbitz> I use them all the time
<thelema> let ref bla acc arguments = ... blabla ([liste]::acc) buff;;
<orbitz> Core makes heavy useof them
<thelema> gour: they're easy to add to functions and good documentation (as well as sometimes convenient) when calling the function. Their only downside is functions like map and fold, which work best with unlabeled arguments
<orbitz> shp: no need to PM me, unelss you're hiding the code from the rest of the channel
<gour> the above looks as haskell's 'as'...the examples in the hickey's book were not so convincing
<thelema> gour: the pipelining with |>?
<orbitz> s/let ref/let rec/
<gour> thelema: no, but separating list
<thelema> the accumulator? yes, this is common practice in functional languags
<orbitz> what is haskells 'as'?
<thelema> orbitz: haskellers often use a b for single items and as, bs for lists
<thelema> or xs ys
<thelema> I've been caught using such identifiers at times
<orbitz> oh, i use those all the time
<thelema> it's a kind of hungarian notation
<adrien> hungarian is unreadable
<orbitz> i think of it more like plurals
<philed> Hmm...I much prefer writing "let rec publishSubscribeNotificationSchemaList accumulationOfMessageSessionFactory ..."
<orbitz> oh, ys you are talking abotu something idfferent
<orbitz> I'm not sure what you're talking about actually
<thelema> orbitz: oh, gour is talking about something different.
<orbitz> yeah
<thelema> in ocaml, :: is cons (also pattern matching), @ is list concatenation, and 'as' is reversed @
<thelema> (reversed haskell @)
_andre has joined #ocaml
<orbitz> gour: what idd hickey not make very convincing?
clam has left #ocaml []
andre has joined #ocaml
andre has quit [Client Quit]
_andre has quit [Client Quit]
_andre has joined #ocaml
_andre has quit [Client Quit]
_andre has joined #ocaml
djcoin has quit [Quit: WeeChat 0.3.9.2]
milosn has joined #ocaml
<xavierm02> updated
<xavierm02> is this what you meant thelema?
<xavierm02> it's already much prettier :)
<thelema> xavierm02: yes, that's what I meant. It looks much better
<thelema> although you might want to reverse the logic so that the not has ()
<thelema> i.e. when po <> Some o -> "(" .. ")"
<thelema> although that doesn't work with your use of None.
<thelema> because the following two are printed the same: Not(X Or Y) and (Not X) Or Y, no?
<xavierm02> yes
<xavierm02> I only tested on input that had been through distribute_not
<xavierm02> so I didn't see it
<xavierm02> but yes
<thelema> maybe just put the "(" ")" on line 5
<thelema> that should fix.
<xavierm02> hm
<xavierm02> yeah
<xavierm02> I removed it from there because I thought I could do a general case
<xavierm02> so that I don't need a special one for Not(Var i)
<xavierm02> but if I do it
<troydm> is there a variant of List.exists which returns 'a option ?
<troydm> instead of just boolean?
<xavierm02> then expressions have to be always parenthized
<thelema> ok, so add a special case: | Not (Var i) -> ...
<xavierm02> yeah
<thelema> troydm: not built in, but it's easy enough to define in terms of List.find
<xavierm02> had that in the last version :)
<troydm> thelema: i guess List.find will suffice
<xavierm02> another question: If I have a match where some options can be made tail recursive (Not) and some can't (BinOp), is there a point to making whatever I can tail recursive
pango has quit [Read error: Connection reset by peer]
pango has joined #ocaml
<xavierm02> or doesnt tail recusion get transformed into a loop only when all the options are tail recursive?
<thelema> troydm: batteries has List.Exceptionless.find; unless you're using a funny comparison function, returning the found value is useless, as you already have the value.
<thelema> xavierm02: any tail-recursive branches will be optimized
<xavierm02> cool :)
<thelema> s/branches/self-calls/
<troydm> thelema: ic, thx
<xavierm02> | Not e -> "¬(" ^ loop None e ^ ")"
<xavierm02> and this isnt tail recursive right?
<xavierm02> I have to use the accu thing
<thelema> correct, it will take up a stack frame to implement
<xavierm02> ty :)
<thelema> xavierm02: Since you're using a tree, your stack depth should be logarithmic in the size of the expression (if it's balanced), so stack overflow isn't a big deal
<xavierm02> so
<thelema> I guess if you had an amazing number of Not(Not(Not(Not(...))))) chained, you could overflow
<thelema> but I wouldn't worry about rewriting to use tail recursion
<xavierm02> I should use tail recursion only when it can overflow?
<thelema> yes
<xavierm02> ok
<thelema> well, you should work to rewrite things using tail recursion when it's not natural only when needed
<thelema> tree functions rarely need to be tail recursive
Reventlov has joined #ocaml
<thelema> because of the logarithmic factor
chambart has quit [Ping timeout: 244 seconds]
RagingDave_ is now known as RagingDave
_andre has quit [Quit: leaving]
Kakadu has quit []
thomasga has quit [Quit: Leaving.]
tac has quit [Quit: I miss my monads.]
milosn_ has joined #ocaml
milosn has quit [Ping timeout: 264 seconds]
ontologiae has quit [Ping timeout: 264 seconds]
<gour> orbitz: the examples of labelled/optional params/args are not such as to think those are really required in the language along with the 'rules of thumb' how they could/should be mixed
<orbitz> oh
<orbitz> gour: core uses them alot, well IMO
<orbitz> fold is a good example of a function I can never remember how to call
<gour> orbitz: good. i trust you there is usage for them
<orbitz> I don't use optional params too much myself
<gour> foldr 0 (+) for sum, iirc?
<gour> ..as far as i remember from haskell
Cyanure has joined #ocaml
<orbitz> gour: I have no idea. Core's takes f and init params, which work well for my memory of such trivialities
<gour> orbitz: it seems that it' same in haskell...function first then init-param
<orbitz> also, fold_left is the tail recurisve one
<orbitz> gour: so you had it backwards
<gour> her, we're not yet concerned so much with ocaml's performance...deciding to use ocaml, means returning back to emacs which involves some other changes in our daily-setup :-)
<gour> *heh
<orbitz> is that a quote fom somewhere?
<gour> nope. why?
<orbitz> oh, just seemd non-sequitor
<troydm> how do i access a value of 'option
<troydm> ?
<troydm> without using match with
<troydm> is there a function to do that?
<troydm> well never mind
<gour> tail-recursiveness is about performance, right? our emacs-based setup is consequence of deciding to use ocaml 'cause it looks it provides best mode for ocaml code
<orbitz> troydm: You'll have to match itat soem point
<orbitz> gour: the optimzation is about performance, yes
jewel has quit [Ping timeout: 265 seconds]
* gour just found out about news - http://www.realworldocaml.org/
<gour> ...but no access :-/
<orbitz> gour: i think it will be opened up soon
<gour> orbitz: great...i sent email asking for access ;)
<thelema> gour: tail recursiveness has to do with correctness in the presence of stack limits too.
<gour> thelema: you mean it the sense of stack not blowing in one's face?
<thelema> to remember argument order of folds, just remember that fold left has the accumulator on the left, _right on the right. This should put all the needed pieces in place.
<thelema> gour: yes, exactly.
<gour> thelema: ohh. thanks...that's helpful
<thelema> I learned it only in the last few months from gasche
<gour> gasche? i believe i noticed one of his answers at SO 10mins ago
tac has joined #ocaml
<troydm> say i want to match some arbitary first and second elements of tuple that is in option
<troydm> let a = Some (1,2);;
<troydm> how do i do that?
<troydm> i want to extract 1 and 2 from a into some variables;
<orbitz> match a with Some (x, y) -> ... | None -> ...
<troydm> not working :(
<orbitz> define "not working"
<gour> what did you try so far?
<gour> iow. paste(bin) some code
<troydm> orbitz: it says that type This pattern matches values of type 'a option
<troydm> but a pattern was expected which matches values of type
<troydm> float * myobjt
lolcathost has joined #ocaml
<troydm> well the second pair in tuple is some custom type
<troydm> i mean the second element of tuple
<troydm> i want only first
<thelema> troydm: that shouldn't be a problem; are you sure you're passing a pair option, and not just a pair?
<orbitz> troydm: match a with Some (x, _) -> ...
<troydm> let me recheck
weie has quit [Quit: Leaving...]
tac_ has joined #ocaml
<troydm> orbitz: actually i've tried that too
<orbitz> troydm: please provide more information then.
<thelema> troydm: that's what the error says: your pattern matches something option, and it is expected to match float * myobjt, which is just a pair.
<gour> just show (some) code instead of using so many words ;)
<orbitz> which line is it upset about?
tac has quit [Ping timeout: 245 seconds]
<orbitz> troydm: if 'no' is an option type, then line 10 would be wrong
<troydm> | Some (d,_) -> if dt < d then (dt,o) else no
<troydm> dat line ^
<orbitz> ctually the probelm is line 12
<orbitz> Some (dt, o)
<gour> else clause has 'wrong' type?
<troydm> ohhh you are right
<troydm> thx alot
<troydm> i was like dumb for 30 mins trying to figure out what's wrong
<troydm> and didn't looked at that
<troydm> my mistake
<orbitz> troydm: I would remove your type annotations, be less compact in your code
<tac_> troydm: So close to the terms you can't see the types.
<troydm> orbitz: hmm, it'll become a mess if i do that
<orbitz> troydm: it is a mess...
<troydm> no i mean a real mess ;)
<orbitz> it is a real mess..
<thelema> it's not bad to leave in the type annotations.
<thelema> Although re-defining fold_left seems unnecessary
<orbitz> the ones in the fold are pretty nasty IMO
<thelema> also, using an if immediately inside a match case is usually avoidable by the when syntax
<thelema> i.e. | Some st when dt <= epsilon -> no
<troydm> thelema: i need object value
<troydm> so standart fold_left won't do me a favor
<troydm> ohh wait
<troydm> i think it can work
<troydm> well atleast i could try
<thelema> It looks to me like it should work with just List.fold_left
<thelema> also, for large folding functions like this; don't put them inline the fold left; define them outside it, please
<tac_> What are your guys favorite aspects of Ocaml as a language?
<thelema> i.e. `let folder no o = match intersect ... in List.fold_left folder None s.objects
tac_ is now known as tac
<thelema> tac: high level + safe + efficient
<tac> Efficient in what sense exactly?
<thelema> tac: runs fast
<orbitz> tac: ocaml code tends to perform well without much effort
<tac> Don't you need to break some safety to get the full performance?
<tac> Or is it just that you have the luxury to go low-level imperative when needed
<thelema> tac: sometimes, but usually performance is very good without breaking any safety.
<orbitz> tac: You have to do ugly thigns in any language to get the 'full performance', whatever that means
<tac> for sure
<orbitz> but the point is ocaml tend sto perform well without effort
<tac> I guess I'm just poking around here, hoping to get a feel for the Ocaml community.
<tac> And what you guys like and dislike about languages (and of course, why you guys choose Ocaml :)
<lolcathost> tac: I am a very sloppy programmer, so I like languages that prevent me from making too many mistakes - languages with advanced static type systems are the best at that.
<tac> lolcathost: I like your name and your reasoning :D
<lolcathost> tac: And I chose OCaml because of the module system! I think typing effects as in Haskell is a good idea, but Haskell's module system is really, really subpar.
<thelema> I really like OCaml's type system myself; the ease of making and using tuples is great, and variant types allow so much to be expressed.
<tac> lolcathost: Indeed. Separate compilation sounds amazing.
<orbitz> i likethat ocaml is very light weight on syntax and very expressive
<thelema> Batteries 2.0 release! yay!
<orbitz> thelema: ^5!
<tac> just today?
<gour> tac: what do you have on the menu?
<tac> gour: on the menu? What do you mean?
<gour> i went the haskell --> D(2) --> OCaml route
<gour> tac: which language do you consider along the OCaml?
<gour> oops forgot to mention .. D --> Ada --> OCaml
<thelema> tac: just *now*
<tac> thelema: neato
<thelema> still in the process of putting it everywere.
<tac> gour: I am on the Haskell -> Agda track
<tac> But I'm very fascinated by Ocaml
<thelema> Ada -> Perl -> OCaml.
<adrien> thelema: congrats!
<gour> thelema: quantum leaps :-)
<gour> tac: i've decided to use OCaml over Ada due to FP
<tac> Ocaml sits in a very cozy spot, I feel. It seems accessible to "mortal" programmers (unlike the hairy ends of Haskell), but yet, it's still very functional and streamlined (unlike maybe Scala)
<thelema> gour: awesome types all the way; Ada spoiled me with its nice type system, Perl was the closest I could come, and I fell in love with map, and came to OCaml
<gour> thelema: you haven't considered Perl-6?
<thelema> I still miss Ada's 'new type' and how arrays could be indexed by an enumeration in a typesafe way
* gour grins
<thelema> gour: perl6 is too... in progress.
* gour thinks Ada is nice imperative lang
<gour> thelema: for how many decades?
<thelema> gour: ada is too painful to use for large projects; too many t's to cross and i's to dot.
<gour> thelema: you mean, a bit verbose :-)
<thelema> or maybe it's painful to use for small projects that will grow to be large projects, but want to just get things done now.
<thelema> not just too verbose, its strings are just a bit off from what I want.
<gour> more i read about OCaml, it's very fine & pragmatic language
Yoric has quit [Ping timeout: 246 seconds]
<orbitz> you should use it then :)
<thelema> definitely spoiled by perl there.
<gour> orbitz: me?
<orbitz> yes
<tac> Is there an index of modules provided by the batteries pack?
<gour> orbitz: sure. i'll do...have to get some better overview, to tackle bindings for the 3rd party C lib I'll need for the project...
<gour> but i've to sleep some time as well, which we're going to do now...
<gour> 'night folks
<tac> night gour
<tac> How long has everyone here been using Ocaml for?
<tac> thanks thelema!
<orbitz> I've only gotten decentat ocaml in the last 6 months - yr
gour has quit [Quit: WeeChat 0.3.8]
<thelema> tac: I started only 12 years ago, and am still working towards being decent at it.
<tac> thelema: High standards? :)
<orbitz> It also depends on what you mean by good at ocaml, you can probably get a long way without knowing the type system in terrible detail
<tac> My knowledge is somewhat backwards in that regard
<tac> I know much, much more theory for Ocaml than even the basic syntax
<orbitz> I know enough type system to get what I care about doen, but I'm sure someone would find my knowledge lacking
chambart has joined #ocaml
shp has quit [Quit: kit]
<tac> Do either of you have an understanding of monads at all?
<tac> And how do you guys feel about monads mixed with your programming?
<tac> Interesting? Pointless? Somewhere in between?
<adrien> depends :P
<orbitz> I use the Either (Result) monad all the time
beckerb has quit [Ping timeout: 240 seconds]
chambart has quit [Ping timeout: 246 seconds]
<thelema> tac: maybe high standards; I keep being impressed at the abilities of other ocaml programmers
<thelema> I generally program pretty monad free, although I'm comfortable using monadic libraries
<tac> what kinds of abilities do good ocaml programmers exhibit?
<tac> The same kind of things that a good C programmer can do hacking Linux? Or something a bit more theoretical, like a good haskeller programmer writing up some category theory implementation?
<orbitz> Read anything by Oleg, and feel small
<adrien> hahahaha
Submarine has quit [Remote host closed the connection]
<tac> hehe. What has he done?
<adrien> well, find something from him
<adrien> read
<adrien> cry
emmanuelux has joined #ocaml
lolcathost has quit [Quit: brb gaize]
watermind has joined #ocaml
tane has quit [Quit: Verlassend]
<orbitz> How do blog posts make it to ocaml.org?
jbrown has quit [Ping timeout: 272 seconds]
suyu has joined #ocaml
myx has quit [Ping timeout: 248 seconds]
<thelema> orbitz: probably through planet.ocamlcore.org
suyu has quit [Quit: suyu]
smondet has quit [Ping timeout: 264 seconds]
RagingDave has quit [Quit: Ex-Chat]
<philed> tac: If you want my opinion, :) , I use monads a lot in Haskell, not very much in Ocaml. I find monad code in Ocaml to be a bit too much of a syntactic burden.
<tac> philed: oh? How so exactly :)
Cyanure has quit [Remote host closed the connection]
<orbitz> tac: here is an example of the monad i use the most in ocaml (sans any concurrency monad): https://github.com/orbitz/blog_post_src/blob/master/intro_return_t/ex5.ml
<philed> tac: Perhaps for a very simple example, Haskell's higher-order kinding makes things a bit easier.
<tac> Higher order kinding?
<philed> Yes. A monad is formally a polymorphic type constructor. In Haskell, these things are just part of the type language. In Ocaml, if you want something similar, you have to wrap it in a structure.
<tac> Ah yes. Since Ocaml doesn't have typeclasses
<philed> Have I just compounded jargon with more jargon?
ikaros has joined #ocaml
<tac> I don't believe so.
<philed> It's slightly more than just typeclasses. For instance, in Haskell you can define the type data Foo x = Foo (x Int).
<tac> Right
<tac> Where x :: * -> *
<philed> Right. So that extra typing relation is kinding.
<tac> a la Fω
<tac> yeah
<tac> ok
<tac> I didn't know if you meant that, or the weird fake dependent typing Haskellers have been playing with lately
<philed> Type families and stuff?
<tac> yeah
<tac> I don't mess with any of those really weird extensions at all
<philed> No. They scare me.
<tac> I consider them a distraction from anything useful
<philed> Though GHC makes me put "FlexibleContexts" everywhere when I'm doing Parsec.
<tac> hm. I don't even know what that extension does
<philed> Nope. Neither do I.
<philed> It's the "make parsec compile" extension.
<tac> hah
<tac> yeah
<tac> That fear of Haskell's looming madness is one of the reasons I want to know how things work in Ocamlland.
<philed> tac: By the way, if you want to know why I chose Ocaml, it's because I do formalised maths at Edinburgh, and it's pretty much the only active Standard ML.
<tac> cool
<tac> Do you have any feelings on F#?
<tac> as a corporately supported ML-like language
<philed> Yes, I think F# is awesome.
<philed> I guess I meant "only active Standard ML except F#."
beckerb has joined #ocaml
<philed> I don't think it would be too much of a headache to put our theorem prover HOL Light into F#. The only fuss is all the preprocessing that we do.
<philed> *port
<tac> HOL Light?
<philed> (although, it's not Standard ML, because it doesn't have modules and functors)
<philed> Yeah, it's just our theorem prover.
<tac> Does it work over all of Ocaml?
<tac> Or is it just implemented in Ocaml?
<philed> It was originally implemented in CAML light, so there's no functors in there whatsoever. That should make it easier to port.
<tac> Time to run
<tac> Thanks for chatting with me guys
ikaros has quit [Quit: Ex-Chat]
<tac> Enjoy your functors until next time.
RagingDave has joined #ocaml
<philed> :) Will do.
lolcathost has joined #ocaml
tac has quit [Ping timeout: 245 seconds]
hongboz has joined #ocaml
iratsu has quit [Read error: Connection reset by peer]
emmanuelux has quit [Remote host closed the connection]
<ImAlsoGreg> orbitz, thanks for the blog post. Interesting read.
<orbitz> ImAlsoGreg: welcome
<orbitz> I'm working on another one, actually detailing my exprience using the method in real software. The good and the bad.
q66 has quit [Quit: Quit]
iratsu has joined #ocaml
<ImAlsoGreg> Would love to read that. Kind of learning haskell and ocaml simultaneously, and about a week ago monads started to 'click'. Seeing them in ocaml context is nice, and (to me) makes your point about returns & readability very solid.
<ImAlsoGreg> Look forward to your thoughts about it in real-software context.
<orbitz> great, glad you like! I got annoyed with this post on reddit a few days ago wehre this guy argued for 'if-less programming' and his whole argument was based on about 3 lines of code with no indication of how it scaled. I thought "I can do better"
<ImAlsoGreg> Oh, haha - I should have read the context above - you, thelema, and tic all talking about monads before I chimed in.
<ImAlsoGreg> Got a link to the reddit?
hongboz has left #ocaml []
hongboz has joined #ocaml
<ImAlsoGreg> orbitz, Oh man, that guy's post (reading the reddit comments and the comments on his blog) wasn't very well received! I'm not sure I get the connection between subclassing away all your if statements, and preferring returns over exceptions.
<ImAlsoGreg> orbitz, But either way, you certainly succeeded in making a better blog post!
fayden has quit [Ping timeout: 265 seconds]
suyu has joined #ocaml