<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
<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
<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
<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>
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
<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
<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>
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...
<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]
<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]
<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
<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>
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!