ayrnieu changed the topic of #ocaml to: OCaml 3.08.4 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
mlh_ has joined #ocaml
jMCg has left #ocaml []
vezenchio has quit [""The law, in its majestic equality, forbids the rich as well as the poor to sleep under bridges, to beg in the streets, and t]
threeve has quit []
_fab has joined #ocaml
threeve has joined #ocaml
bzzbzz has quit [Client Quit]
_fab has quit [Remote closed the connection]
CruX has joined #ocaml
CruX_ has quit [Read error: 104 (Connection reset by peer)]
pango__ has joined #ocaml
Codename_V has quit ["Free will is just an illusion"]
pango_ has quit [Read error: 104 (Connection reset by peer)]
AndroFlux has quit ["leaving"]
humasect has quit ["Leaving.."]
threeve has quit []
_shawn has joined #ocaml
shawn_ has quit [Read error: 110 (Connection timed out)]
Snark has joined #ocaml
<twobitsprite> gah! building up multiple lists while remaining tail recursive hurts my head...
<Nutssh> You don't *have* to be tail recursive. :)
<twobitsprite> but I plan to decend quite a ways...
<twobitsprite> mabe it would be easier if I just implement without tail calls, just to get my thoughts down, and then tried to optimize with tail calls...
<Nutssh> That works. Or build the lists directly and reverse them as appropriate.
<Nutssh> On linux you can assume 8-16mb of stack, thats a few hundred thousand recursions.
<twobitsprite> do function arguments go on the stack? i.e. is it bad if I pass a lot of large data structures to a function?
<twobitsprite> Nutssh: true...
<Nutssh> Those are passed by reference, so ~4 bytes/argument.
<twobitsprite> right on
<twobitsprite> all arguments, or just large ones? i.e. are ints passed on the stack?
<twobitsprite> maybe my problem is I'm trying to kind of inline all of my conses, instead of using lets or something
<twobitsprite> for some reason, I feel I have to make my functions as efficient as possible and declare as few names as possible... very bad habbit
<Nutssh> Very bad habit, names can be free, depending on the compiler.
<twobitsprite> maybe I'm in the wrong field, maybe I should just program micro controllers, I'd be great at that! I bet I could cram all kinds of fun algorithms ins 4k of flash RAM...
<Nutssh> Useful tip if you care about performance: Avoid any bad datastructures and just write the code. Only after a component is implemented do you worry, and *then* profile it, and optimize based on what you see.
<twobitsprite> yeah... that's what the people in #python were always chanting at me... it's still sinking in...
<twobitsprite> btw, what do you mean by "bad datastructures"?
<Nutssh> Using lists instead of hashtables. That sort of thing.
<twobitsprite> yeah... I find myself using array's more often than lists...
<Nutssh> Same here... You can tell a newbie lisp programmer, if they use cad/cdr/cons inappropriately.
<twobitsprite> or caddaadar as is supplied by some lisp compilers...
<Nutssh> Ewww! :/
<twobitsprite> indeed
<Nutssh> I like oprofile cause it is non-invasive.
<twobitsprite> oprofile?
<Nutssh> google. :)
* twobitsprite is.
<twobitsprite> :P
<twobitsprite> looks fun
<twobitsprite> but looks addictive... I could see myself recompiling my kernel indefinately trying out different compiling options just to get peak performance... maybe I'll avoid that... :P
<Nutssh> Very useful. I'm a firm believer in profiling and looking at the result. I always find some surprise.
<Nutssh> It also can give me an idea where hotspots are, That way I know which lines of code I know I should think carefully about the code there and.think about other ways of doing it. (I did that for the mythtv compressor and replaced a switch with an if/then and some arithmatic for a 1% gain overall.
<twobitsprite> right on... do you ever find yourself tweeking the generated asm code of a program you write?
<Nutssh> No point in that. Its a gool to tell you what parts to focus on. If you want to do microtweaking, there *is* a way that that could be useful --- internal kernel parameters. In particular, say, the vm caching infrastructure. Save a 1% of diskseeks and you've saved a lot.
<Nutssh> No.
<twobitsprite> maybe I should just seek counseling for my OCD... :P
<Nutssh> Not worth spending 10 hours optimizing a program that may only get only a few hundred hours of CPU time in its life.
<twobitsprite> I haven't found myself doing that yet, but this is my first time in years messing with a compiled language, and the urge it there...
<twobitsprite> s/it/is
<Nutssh> I don't bother. I try for the big wins, and forget about the small stuff. A lot of my code was bottlenecked on Array.sort, passed an array of integers. Main problem was that with seperate compilation it had to compile it with the generic comparison function. Copy&paste and add in a few declarations made it about 3x faster, about doubling my overall performance. Even now, I know in that program that about 40% of the runtime is in 'pick a random subset from
<Nutssh> this array', with about 75% of that in the random number generator. But its not worth going to C for a 30-50% speedup.
<twobitsprite> what about compiler hacks? think you could muck with the compiler and send in your source for all to use? that might be a worth while optimization...
<Nutssh> The ocaml compiler isn't easily amenable to adding in an optimization pass --- it has the wrong intermediat elangauge for it. It would be awesome though if the native compiler did even basic optimization. Even something as simple as value numbering (or removing redundant computation) would be a huge win. Similar win from moving invariant code out of loops.
<twobitsprite> I thought ocaml did do optimizations...?
<twobitsprite> the Shootout shows Ocaml to be very fast...
<Nutssh> Nope. It is a native compiler. Try compiling 'let foo x = x*x*x*x*x' and just cry at the assembly.
* twobitsprite fears.
<twobitsprite> I thought that was one of the big points of Ocaml, its speed...
<Nutssh> I credit that to modern superscalar CPU's having surplus execution resources. And that Ocaml is a more advanced language making it easier to use more efficient algorithms.
<Nutssh> Its not slow, but more than a bit of my code could have had its inner loops done in C and been 50-200% faster. If the compiler did basic optimizations, I suspect the penalty would be a LOT less.
<twobitsprite> what is the Ocaml compiler writen in... is it bootstrapped or just a yacc program?
* twobitsprite peeks the source
<Nutssh> ocaml
<twobitsprite> I see...
__DL__ has joined #ocaml
ski has joined #ocaml
pango__ has quit [Remote closed the connection]
Snark has quit ["Leaving"]
humasect has joined #ocaml
Skal has joined #ocaml
pango has joined #ocaml
tonio has joined #ocaml
<tonio> hi
<haakonn> hi
<tonio> i do have a problem with ocamlopt
<tonio> the makefile for a caml software uses ocamlopt -pack
<tonio> but -pack is not supported under darwin (lack of gnu binutils)
ejt has joined #ocaml
<Nutssh> Its grotty, but I think that -pack is equivalent to defining a new module that encloses the others. So a file foo.ml containing 'module A=A;; module B=B;; ...', when compiled, should be almost equivalent. You'll also have to do somethign similar to create foo.mli
<Nutssh> I *think*.
mlh_ has quit ["who are you people and what are you doing in my computer!?"]
revision17_ has quit [Read error: 110 (Connection timed out)]
jave has quit [Remote closed the connection]
Gueben has joined #ocaml
Tamerlang has joined #ocaml
Tamerlang has quit [Read error: 104 (Connection reset by peer)]
m3ga has joined #ocaml
<tonio> thanks Nutssh
tonio has left #ocaml []
vezenchio has joined #ocaml
juri has quit [niven.freenode.net irc.freenode.net]
bacam has quit [niven.freenode.net irc.freenode.net]
slashvar[lri] has quit [niven.freenode.net irc.freenode.net]
ejt has quit [niven.freenode.net irc.freenode.net]
mflux_ has quit [niven.freenode.net irc.freenode.net]
Smerdyakov has quit [niven.freenode.net irc.freenode.net]
oracle1 has quit [niven.freenode.net irc.freenode.net]
pattern has quit [niven.freenode.net irc.freenode.net]
Hadaka has quit [niven.freenode.net irc.freenode.net]
noj has quit [niven.freenode.net irc.freenode.net]
Skal has quit [niven.freenode.net irc.freenode.net]
TaXules has quit [niven.freenode.net irc.freenode.net]
shrimpx has quit [niven.freenode.net irc.freenode.net]
Hipo has quit [niven.freenode.net irc.freenode.net]
ax has quit [niven.freenode.net irc.freenode.net]
skylan has quit [niven.freenode.net irc.freenode.net]
det has quit [niven.freenode.net irc.freenode.net]
CruX has quit [niven.freenode.net irc.freenode.net]
descender has quit [niven.freenode.net irc.freenode.net]
twobitsprite has quit [niven.freenode.net irc.freenode.net]
pnou has quit [niven.freenode.net irc.freenode.net]
ejt has joined #ocaml
Skal has joined #ocaml
CruX has joined #ocaml
Hadaka has joined #ocaml
bacam has joined #ocaml
juri has joined #ocaml
descender has joined #ocaml
slashvar[lri] has joined #ocaml
mflux_ has joined #ocaml
Smerdyakov has joined #ocaml
twobitsprite has joined #ocaml
pnou has joined #ocaml
shrimpx has joined #ocaml
TaXules has joined #ocaml
oracle1 has joined #ocaml
Hipo has joined #ocaml
ax has joined #ocaml
skylan has joined #ocaml
det has joined #ocaml
pattern has joined #ocaml
noj has joined #ocaml
revision17 has joined #ocaml
m3ga has left #ocaml []
threeve has joined #ocaml
ski_ has joined #ocaml
_fab has joined #ocaml
zigong has joined #ocaml
ski has quit [Nick collision from services.]
ski_ is now known as ski
zigong has quit [Remote closed the connection]
zigong has joined #ocaml
faigo has joined #ocaml
<faigo> let i=1;; Is that possible to get the type of variable "i"?
<haakonn> i is not a variable :)
<haakonn> but in most cases you don't need the type. if you do, you may want to use variants instead
<ski> ?
<haakonn> as in type foo = Int of int | String of string, then use matching
<ejt> faigo: what are you trying to do ?
* ski would think 'i' there is a variable (not an imperative one, though)
<ejt> well it doesn't vary
<ski> faigo: do you want to know the type so you know what to code ? or do you (dynamically) want to know the type when the code is running ?
* ski thinks it varies as in isn't here determined what it is/will be
<haakonn> it will be 1 ;)
<ski> ejt : as in let f n = n * n - 2;; there i'd specifically say n varies
<ejt> it _is_ 1
<ski> yes, but at *uses* of 'i', unless we happen to know definition, we don't know
<ski> in <expression which mentions i> we cannot, in isolation determine 'i', so this allows the interpretation of the whole to vary with varying 'i' (short : it's parameterized)
<haakonn> faigo: feel free to ask more if all that didn't help :)
zigong has quit [Remote closed the connection]
<faigo> Thanks all.
<faigo> I want to dynamically check variable, for example, let check x=if x is_int then do something.
<ejt> the do as haakon said and use a sum type
<faigo> that checking is in running time.
<ejt> does that make sense ?
teiax has quit ["This computer has gone to sleep"]
<haakonn> faigo: i'm assuming x have to be of one of only a few types, right? you should look into sum types/variants, they are very useful
<pango> let check (i:int) = () if it compiles, i is an int
<pango> or just (i:int)
<pango> you could use Obj.is_int (Obj.repr i) but I doubt it's useful in real life
teiax has joined #ocaml
<faigo> thanks pango, Obj.is_int works. how is there is_string checking?
<faigo> and, type checking with args. let s1="aaaa"; let s1 s2="bbbb"; I want to match case a variable or function which return string and have no args..
<teiax> The stuff in the Obj module should be used with great care
<faigo> sorry for my wires questions, but ocaml is really great in dynamic programming.
<teiax> IMHO it should not even be exposed
<teiax> I'm curious, what are you checking with your if that they type system can't check for you?
<teiax> s/they/the/
<teiax> :-)
<faigo> :-), those variable/variant I am going to check is dynamic generate by an other program.
<faigo> not typing from me. :)
<teiax> ah... you are reading it from shared memory or something?
<faigo> yep, shared menory, socket or files.
<faigo> sine if there is gramma wrong(type checking) cause errors on compiling time, the program will abort while got type errors.
<teiax> yes, it will
<faigo> ehmm, I found on is_string on module Obj.
<faigo> s/on/no/
_exa has joined #ocaml
_exa has quit [Remote closed the connection]
Smerdyakov has quit [Read error: 110 (Connection timed out)]
ski is now known as skiAFK
ramkrsna has joined #ocaml
<pango> faigo: because most types don't exist at runtime
<pango> faigo: just enough informations to keep the memory manager, etc, happy
exa has quit [Read error: 110 (Connection timed out)]
pango has quit ["Leaving"]
ramkrsna has left #ocaml []
Smerdyakov has joined #ocaml
<Smerdyakov> faigo, no good will come of using anything from Obj.
zigong has joined #ocaml
<mflux_> ;)
<mflux_> I've used it to convert Unix.fd to an integer
<mflux_> for debugging purposes though, but I imagine when interacting with other unix processes it could be helpful
<Smerdyakov> A more appropriate thing would be a to_string function for fd's in the library.
<mflux_> what if you want to execute another process and on command line tell numbers of certain fd's it's going to inherit? that's numeric information..
<mflux_> or atleast the transformation to string should basically be defined to be the same as a conversion to integer and then to string
<Smerdyakov> You would want more than stdout/stdin/stderr, which should be defined in the Unix library?
<mflux_> I would want.
<mflux_> s/w/c/
<mflux_> I think for example irssi uses that trick
<mflux_> to upgrade itself
<mflux_> it inherits sockets to the resulting process
<Smerdyakov> Well, perhaps in this goofy UNIX environment, that would make sense.
<Smerdyakov> Ideally, you shouldn't have to go through an ASCII bottleneck to spawn a new process with arguments.
<mflux_> well, you wouldn't actually need to use command line arguments
<mflux_> the resulting process could read a binary parameter block from standard input
<Smerdyakov> For instance, to upgrade an OCaml program, load a new version dynamically in the same process and start a thread with the right arguments, then stop the old threads.
<mflux_> I suppose you could use the builtin to-binary-from-binary conversion routines in that case
<mflux_> I'm not sure if that works perfectly if for example some dynamic library dependencies have been upgraded
<Smerdyakov> It can be made to work perfectly with attention at all levels of the dependency tree.
mrsolo has joined #ocaml
pango has joined #ocaml
Nutssh has quit ["Client exiting"]
Snark has joined #ocaml
znutar has joined #ocaml
Psion has joined #ocaml
Smerdyakov has quit [Read error: 110 (Connection timed out)]
CruX has quit [Nick collision from services.]
CruX_ has joined #ocaml
Psion has quit [Read error: 110 (Connection timed out)]
ski has joined #ocaml
skiAFK has quit [Read error: 110 (Connection timed out)]
mikeX has joined #ocaml
Nutssh has joined #ocaml
Snark has quit ["Leaving"]
vezenchio has quit [""The law, in its majestic equality, forbids the rich as well as the poor to sleep under bridges, to beg in the streets, and t]
ejt has quit ["bye"]
mikeX has quit ["Leaving"]
Smerdyakov has joined #ocaml
Gueben has quit [Remote closed the connection]
ski_ has joined #ocaml
threeve has quit []
ski has quit [Connection timed out]
Smerdyakov has quit [Connection timed out]
ski_ has quit [Connection timed out]
Gueben has joined #ocaml
threeve has joined #ocaml
zigong has quit [Remote closed the connection]
Nutssh has quit ["Client exiting"]
mikeX has joined #ocaml
<mikeX> is there a way I can declare a variable without having to give a value?
<teiax> Yes, use the built in option type
<teiax> let x = ref None
<teiax> then when you want to assign something to it, just do x := Some (val)
<mikeX> I see, thanks
<teiax> hopefully that method is suitably annoying that you will try to avoid having to use it :-)
<teiax> sufficiently annoying rather
<mikeX> ;D
<mikeX> it's only a temporary workaround
mikeX has quit ["Leaving"]