dark_light changed the topic of #ocaml to: OCaml 3.09.2 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/
dark_light has quit [Read error: 113 (No route to host)]
dark_light has joined #ocaml
<dark_light> can i set a labelled paramter to a class initializer?
<dark_light> and, the best way to create a new array of one element is Array.init 1 (fun x->element) ?
<dark_light> this seems to be overloaded to be just a simple array
<jeremy_c> pango: have been away. When I try to compile your example, I get:
<jeremy_c> This expression has type [> `CASELESS ] but is here used with type Pcre.rflag
b00t has quit [Remote closed the connection]
skyde has joined #ocaml
<skyde> can some one help me
<skyde> i need to understand how the type system work
<skyde> hello some one her ?
Ballin_105 has quit [Remote closed the connection]
<skyde> hi
<skyde> ?
<levi_home> What sort of help do you need?
<skyde> i am new to Ocaml
<skyde> in other programming language you do generic programming or type casting
<skyde> but in ocaml you dont need to
<skyde> so i need to understand how it work to understand why and how to best design my code
<skyde> should implement interface or have an inheritance tree
zetta has joined #ocaml
<levi_home> The ocaml compiler infers the types of your variables and functions by how you use them.
<levi_home> So you should keep types in mind as you program, but you shouldn't have to type them most of the time.
<levi_home> The type system does support polymorphism, though, so you can write generic algorithms.
<skyde> i know
<skyde> but the generic programming work like c++ template ?
<levi_home> Not quite.
<levi_home> My familiarity with both is fuzzy enough that I don't feel confident making definitive statements about how they compare.
<skyde> c++ template generate a version of the template for each type using it a compile time
<skyde> is it what ocaml does
<skyde> ?
<levi_home> I'm not sure what ocaml does, which is why I wouldn't want to say one way or the other.
<levi_home> You can do a lot of the same sorts of things in OCaml with type variables that you can with C++ templates, but I'm fairly sure they aren't identical.
<skyde> ok
<skyde> tanks
pango has quit [Remote closed the connection]
pango has joined #ocaml
<jeremy_c> Can I call a class method by only knowing the method by a string?
<skyde> humm
<skyde> i think no
<skyde> cause this would be late binding
<jeremy_c> skyde: yeah.
<jeremy_c> skyde: I didn't think I could, just making sure I am not missing something
<skyde> hehe
<skyde> :0
<jeremy_c> I'm still a newbie
<jeremy_c> but getting much better, day by day
Amorphous has quit [Read error: 104 (Connection reset by peer)]
Amorphous has joined #ocaml
<levi_home> jeremy_c: You can pattern-match on a string, or make a Map/Hashtbl mapping strings to functions.
<levi_home> let dispatch str = match str with "x" -> x | "y" -> y | ...
<jeremy_c> levi_home: I see.
<jeremy_c> levi_home: that may be a workable solution.
<levi_home> Perhaps you could make a camlp4 macro that defines a function and adds its name to a Hashtbl at the same time, or something like that.
<levi_home> But I've never used camlp4, so you'd have to verify that such a thing is reasonable.
<skyde> ocaml permits the creation of ad hoc interfaces
<skyde> can i see a example
shawn has quit ["This computer has gone to sleep"]
<levi_home> skyde: I'm not sure what you're referring to.
meng has joined #ocaml
<meng> How to define a struct in caml? In Lisp you can use defstruct, like (defstruct point x y z)
<meng> many thanks
<levi_home> With a record type: type point = { x : int; y : int; z : int}
<levi_home> Or you could use a tuple: type point = int * int * int
<meng> thanks for your help. i will read more textbook
<jeremy_c> I have a function that takes url func as params. url is a string, func is a function taking a request class as a parameter. Compile error says contains type that cannot be generalized. How can I specify the type for the function parameter? (url:string) is easy.
<levi_home> (func : <argtype> -> <returntype>), I would guess.
<levi_home> (I am still learning ocaml, so my answers may be incorrect)
<jeremy_c> levi_home: thanks, that did it. you must be learning more than I :-)
jcreigh has joined #ocaml
Ballin_105 has joined #ocaml
<Ballin_105> anyone up?
AI_coder has joined #ocaml
<levi_home> jeremy_c: Well, I've been working with it for a few weeks now and I've written a useful program, so I've picked some stuff up. :)
skyde has quit []
Hadaka has quit [Read error: 110 (Connection timed out)]
<Ballin_105> jeremy_c: the little open thing isnt all to sucessful over here
<jeremy_c> Ballin_105: what's up?
<Ballin_105> jer
<Ballin_105> jeremy_c: #use "xml.ml";;
<Ballin_105> i keep getitng that whe ni do open Globstuff
<jeremy_c> Ballin_105: keep getting what?
<jeremy_c> is Globstuff your .ml file? in Globstuff, does it have #use "xml.ml" in it?
<Ballin_105> globstuff is just a bunch of let dsfsd = dfdsfds
<Ballin_105> global variables i want used throughout
<jeremy_c> Ballin_105: I'm confused as to where the #use "xml.ml" is coming into play
<Ballin_105> the interpreter lol
<jeremy_c> Ballin_105: so, you are typing that in?
<Ballin_105> naw
<jeremy_c> Ballin_105: the source file you showed me, that's xml.ml?
<Ballin_105> thats what its saying to me
<Ballin_105> yes
<jeremy_c> how are you running this?
<Ballin_105> interpreter
<Ballin_105> ocamlc
<jeremy_c> Ballin_105: that's the compiler
<Ballin_105> well im using a ide but yea
Naked has joined #ocaml
<Ballin_105> i dont knwo i use camelia
Naked is now known as Hadaka
<jeremy_c> I don't know what that is.
<jeremy_c> something strange is going on there that I don't understand.
<jeremy_c> what happens if you ocamlc -o hello globstuff.ml xml.ml
<jeremy_c> ?
<Ballin_105> let me try
<jeremy_c> 3.09.3 is released now, update title?
<Ballin_105> grrrrrrr
<jeremy_c> ?
<Ballin_105> jeremy_c: hold on
<jeremy_c> Ballin_105: better make it quick, I'm going to bed soon. 1am here.
<Ballin_105> yea ........i dunno is seems opt be an IDE problem more or lesss
<Ballin_105> to be
<Ballin_105> like if i try to compile my xml.ml and have the open Globalstuff
<Ballin_105> it compiles both
<Ballin_105> as like seperate files
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
<Ballin_105> seemes like this isnt the exact way
<jeremy_c> what does ocamlc -o hello globstuff.ml xml.ml do?
jewel has joined #ocaml
shawn has joined #ocaml
<Ballin_105> jeremy_c: ok yea i got a hello
<Ballin_105> but how cna i see its output ?
<jeremy_c> hello
<jeremy_c> what OS are you on?
<Ballin_105> i run ./hello
<Ballin_105> and i get nothing
<Ballin_105> i diddnt have it do anything just a bunch of declarations
<jeremy_c> k. then your code is working.
<jeremy_c> it's something in your ide.
<Ballin_105> and what is all this cmi cmo stuff ?
<jeremy_c> compiled objects.
<jeremy_c> you have an executable now.
<Ballin_105> i mean when i distrubute my program can i jus distribute the one exe ?
<jeremy_c> So, the point is that ocaml compiled your code just fine. It's not a problem there.
<Ballin_105> or executeable
<jeremy_c> yes.
<jeremy_c> when you compile a c program, you get a bunch of .o or .obj files. You don't need them.
<jeremy_c> you can remove .cmo .cmi's right now if you want.
<jeremy_c> hello will still work.
<Ballin_105> whats hte purpose of having them ?
<Ballin_105> for making libraries and such ?
<jeremy_c> I don't understand the details of the compilation process. I know that they are intermediate object files that are a result of compiled code. Then they are linked together with libraries (ocaml runtime for instance) to create your final file, hello
<Ballin_105> dynamic or static ?
<jeremy_c> Ballin_105: look to your ide for the problem. I'm going to bed, sorry to leave you hanging but I gotta work tomorrow and not going to be any good if I don't get some zzzz's
<flux__> ballin_105, the point is that if you have a program of larger size, you want to be able to compile it in parts, so recompilation after changing one file won't take long
<Ballin_105> ahhhh
<Ballin_105> flux__: you ever yse camelia ?
<flux__> no
<Ballin_105> i seee
<Ballin_105> i like the ide alot except for this small problem
love-pingoo has joined #ocaml
<Ballin_105> right now my application is 208 KB
<Ballin_105> with ocamlopt
<Ballin_105> anyway to make it smaller .......without all the upx compression or anything?
<Ballin_105> not a big deal just something i would like to know
<flux__> binary compressors will propably work with the ocamlopt-compiled binary
<Ballin_105> is there any ocamlopt command used to make it a little smaller ?
<Ballin_105> better complination or something
<love-pingoo> nope
<Ballin_105> i seeeee
<love-pingoo> I wonder why this question comes up so often. I never cared about that.
<Ballin_105> me either
<Ballin_105> just curiocity
<love-pingoo> It would matter for portable devices, but OCaml isn't available for most of them anyway :\
<Ballin_105> i just hope Xml-light - labltgtk - unix stuff + my app doesnt come to like 4 MB
<flux__> I wouldn't infact mind if the binaries were smaller, it would allow targetting a system with limited resources (flash)..
<Hadaka> we have a potential project where minimizing ocaml code size is really paramount and we did some research on that
<Ballin_105> Hadaka: any luck ?
<love-pingoo> flux__: did you ever use ocaml for such a target ?
<Hadaka> Ballin_105: well, not directly, we'd have to write our own stuff to achieve anything decent
<love-pingoo> it'd be fun to build standalone palm or nds roms in ocaml ;)
<Ballin_105> i mean how would it be made smaller
<Hadaka> Ballin_105: take out the useless stuff in the code files, swap out the bytecode format to something more compact and make sure the native code files use as much shared as possible
<love-pingoo> ocaml only does static linking, but even with that, I suspect it statically links to every module in a cma even when you use only a few, which may be enhanced
<Hadaka> there just hasn't been much done in the way of minimizing code size
<Ballin_105> well i hope my app doesnt hit mb's
<love-pingoo> the prob with dynamic linking is that is would require dynamic type checkings
<Ballin_105> does size grow alot when you write ?
<love-pingoo> Ballin_105: no, it grows when you link gtk, then xml
<Hadaka> Ballin_105: the actual amount of code generated from your own ocaml files is not that big, so don't worry about that
<love-pingoo> the size of your code won't make the difference, unless you write a huge lot
<Ballin_105> yea i could also condesne the libraries
<Ballin_105> take out things i dont need
Snark has joined #ocaml
<Ballin_105> its a very small xml parser library too
<Ballin_105> also is it possible to optimize the .o file to make them smaller etc ?
<love-pingoo> I hit 2.6M with ocaml-mad/vorbis/shout/dtools, which are all quite tiny bindings
<Ballin_105> smaller then xml-light
<Ballin_105> or lablgtk ?
<love-pingoo> much smaller :\
<Ballin_105> wtf
<love-pingoo> but my app is 8-9000, with many strings.. I don't know if it's a lot.
meng has quit []
<Ballin_105> how cna i compile labtlgtk with ocamlopt ?
<Ballin_105> the ocaml hello world with lablgtk in byte code is 300 KB
<love-pingoo> that's cool
<love-pingoo> (btw I'm using bytecode, that may be the reason)
<love-pingoo> hope you get something thin
<Ballin_105> you were using bytecode and got 2.6 MB?
_velco has joined #ocaml
love-pingoo has quit [Remote closed the connection]
love-pingoo has joined #ocaml
<Ballin_105> -compact Optimize code size rather than speed
<love-pingoo> sorry about my answer then, I'm surprised
<Ballin_105> i wonder how well it works though
Wild_Cat has joined #ocaml
Revision17 has quit [" HydraIRC -> http://www.hydrairc.com <- Go on, try it!"]
<Ballin_105> this IDE is drivinbg me crazy
<flux__> I don't think that option will give you any significant decreases
<flux__> in size though
<Ballin_105> flux__: how can i see types etc all that when using the ocaml interpreter ?
<flux__> ballin_105, what do you mean? there is no command to enumerate all types..
<Ballin_105> i meant
<Ballin_105> flux__: i meant show all debug info
<Ballin_105> #
<Ballin_105> val sock_send : Unix.file_descr -> string -> int = <fun>
<Ballin_105> val sock_recv : Unix.file_descr -> int -> string = <fun>
<Ballin_105> val client_sock : Unix.file_descr = <abstr>
<Ballin_105> like that
<Ballin_105> in the interpreter
<Ballin_105> i cant figure out how to tell this camelia also how to open other files
<Ballin_105> like it expectes everything ot be a single file or something
<Ballin_105> flux__: ^^
<flux__> in the interpreter you can type a value (or a function) and get its type
Revision17 has joined #ocaml
<Ballin_105> is there any way i can run a file and see all the vals and types ?
<flux__> infact, there is a way, it's sort of a kludge: module Foo = YourModule
<flux__> it'll output the module signature
<Snark> ocamlc -i module.ml should do it too, doesn't it ?
<flux__> yes
asmith has quit [Read error: 104 (Connection reset by peer)]
Wild_Cat has quit []
<Ballin_105> flux__: how can i run a script that has multiple files
Snark has quit ["Leaving"]
<Ballin_105> main.ml being the main thing .......then globalstuff.ml and tcp.ml
<flux__> just use #use multiple times
<flux__> I would rather just compile an execultable out of them
<flux__> like with ocamlc -c globalstuff.ml tcp.ml main.ml
<flux__> scrap that -c
<flux__> and maybe replace with -o main
<pango> dark_light: Array.create 1 element
<flux__> Array.of_list [element] :-)
<pango> jeremy_c: it's strange that it compiled fine here (3.08.3)
<pango> Ballin_105: let dsfsd = dfdsfds doesn't define a variable, that's a let-binding
<pango> Ballin_105: and using upx is not that great under Linux; The executable is temporarily decompressed in /tmp before it can be run...
<pango> so you only save space when you're not running it
<flux__> uh, some of those 3.09.3 fixes seem very important
<flux__> stdlib: memory leak in Sys.readdir PR#4093
<flux__> otherlibs/unix: crash in gethostbyname PR#3043
<flux__> hm, that could actually be related to one of my problems..
<Ballin_105> pango: how would i define a variblae then
f78 has quit [Remote closed the connection]
slipstream has quit [Read error: 104 (Connection reset by peer)]
<pango> the equivalent of a 'variable' of imperative languages (= something mutable) would be let dsfsd = ref dfdsfds
<Ballin_105> i seeee
<pango> that said, maybe let-bindings are correct for your needs, I don't know all your code
<Ballin_105> pango: have you ever used camlia ?
<love-pingoo> but you don't often need that, in most cases creating a new (constant) definition is enough
<pango> Ballin_105: I mainly use emac
<pango> emacs
<pango> in fact, most of your xml.ml (http://phpfi.com/154067) look like functions
slipstream has joined #ocaml
<Ballin_105> pango: any other way to achieve that ?
<pango> to achieve what ?
<Ballin_105> storing XML
<Ballin_105> with my vlaues inside of them
<pango> obviously, send_message_xml will depend on the message to be sent, among things. So it's not a variable, but a function of jabber_message and friends
_ziggurat_ has quit ["Leaving"]
<flux__> hmm.. are ocaml bug reports publicly available?
<love-pingoo> the tracker is open as far as I know
<flux__> ah, caml.inria.fr/mantis/
<flux__> hm
<flux__> there's bug PR#3043
<flux__> but I can't find it with the tracker
<Ballin_105> pango: sock_send client_sock "%s" establish_connect_xml << but establish_conn etc is a function
<flux__> a-ha
<flux__> it is supposed to be 4043 :)
<pango> Ballin_105: .cmi and .cmo are useful for separate compilation; As your application grows bigger, it becomes a time saver to only recompile the modules that changed, so compilers are keeping the result of the compilation of each module separate
<pango> Ballin_105: yes, that one is
<pango> Ballin_105: but I suppose others should be, too
<Ballin_105> pango: what the send_sock is looking for a variable not a function
<Ballin_105> but a function is needed
<pango> no, it's looking for a value
<pango> a function can return a value, too
<Ballin_105> i seee
jewel has quit [Read error: 110 (Connection timed out)]
_fab has joined #ocaml
<Ballin_105> i think this camelia IDE is slwoing me down
love-pingoo has quit ["Leaving"]
<pango> not as much as not reading ocaml docs ;)
jewel has joined #ocaml
tld has joined #ocaml
<Ballin_105> pango: this camelia is a cool ide cause you can run scripts fast ........and check syntax in a flash
<Ballin_105> but if i try to use another file ........ like open Globstuff or something like that it wont work
<Ballin_105> casue the file has ot be added at runtime
<Ballin_105> and for osme reason it cant accomplish this grrrrrrrr
<tld> Anyone know if ocaml offers anything comparable to Pythons Twisted framework? (for event driven net framework)
<pango> Ballin_105: tried to compile camelia, but I get "Instance already open: There is already an instance of Camelia running." whenever I try to run it
<pango> tld: not sure what twisted does, but I suppose it's something like ocamlnet... It seems there's a (not yet released) v2 with lots of neat features
<tld> thanks, looking it up
<tld> hmm
<tld> OCaml NAE seems potentially interesting
jewel has quit [Read error: 110 (Connection timed out)]
<pango> but potentially dead... Is there still development going on ?
<pango> mmmh July... not that old
<Ballin_105> pango: never got that
<Ballin_105> pango: offers syntax highlighting and instant syntax check ........and one button you can run the application
<pango> well, nothing new there ;)
<tld> pango, seems like it might be alive, but not quite following the 'release early; release often' ideas
<ppsmimou> I think that ocnae is alive
<pango> that's worth checking then
<tld> :)
jewel has joined #ocaml
gene9 has joined #ocaml
gene9 has quit ["Leaving"]
<Ballin_105> i didnt get crap accomplished tonight
b00t has joined #ocaml
Schmurtz has joined #ocaml
b00t has quit [Remote closed the connection]
Schmurtz has quit ["L'énergie semble manquer : dodo !"]
shans_home has joined #ocaml
<shans_home> is there a more recent version of the camlp4 tutorial than 3.07?
<shans_home> some of the examples no longer work
b00t has joined #ocaml
Schmurtz has joined #ocaml
AI_coder has quit [Client Quit]
zetta has quit ["ircII EPIC4-2.2 -- Are we there yet?"]
jeremy_c has quit [Client Quit]
jeremy_c has joined #ocaml
_JusSx_ has joined #ocaml
<pango> @all: Have you tips/links on how to profile the memory usage of a (large) ocaml program ?
jewel has quit [Read error: 110 (Connection timed out)]
b00t has quit [Remote closed the connection]
_fab has quit [Remote closed the connection]
<jeremy_c> pango: just out of curiosity, what do you consider a large ocaml program? line count?
<pango> well, it doesn't even really matter if it's large... And to answer your question, other parameters count too, like the lack of strong modularity ;)
<pango> but in that case it would be for a 200k lines program
<pango> (thinking of it, I'm not sure if that's modularity that's the main problem; No matter what, liveliness is a global property)
Schmurtz has left #ocaml []
<pango> Ballin_105: a-ha found why Camelia wouldn't start. Didn't like the presence of /tmp/camelia directory... Where I compiled it! ;)
shawn has quit ["This computer has gone to sleep"]
<pango> uh, Camelia is not for heavy duty yet... It got totally confused by jeremy_c's PCRE test code (\n's ?)... And I see no support for separate compilation either
<buggs> pango, like C programs?
<pango> buggs: just like, compile more than one module :)
<buggs> i was wrt memory usage
<pango> buggs: it seems to be some sort of learning editor... Fine interface, but not ready for even moderately large projects
<jeremy_c> How do I open a module as an alias?
* jeremy_c has seen it done but cannot find the info anywhere.
<jeremy_c> open Ocamlodbc as Odbc for instance.
<flux__> module Alias = Module
<jeremy_c> flux__: thanks.
<pango> buggs: oh, no, 90% ocaml I'd say
<pango> for the C parts, valgrind is enough in that case; But for Gc managed memory...
<buggs> why is valgrind not good for the Gc managed memory ?
<ulfdoz> Mein Auto ist schon wieder in der Werkstatt.
<ulfdoz> ECHAN, sorry
<pango> because it debugs the Gc itself, and since the Gc is fine, it just finds nothing
<pango> it doesn't work at the right allocation level
<buggs> pango, would you like to have info about which data structures hold how much memoty ?
<pango> yes, that kind of informations
<flux__> hmm.. I suppose you could do something like alloc : 'a -> string -> 'a which would do bookkeeping, with the assitance of Gc.finalise
<pango> and "how much memory is used by data structures of type t"
<flux__> and maybe automate sprinkling those everywhere with camlp4 :)
<pango> problem is, you can construct new datastructures in many (syntactic) ways
<flux__> yes
<flux__> but not in infinitely many ways :)
<pango> with a weak hash table, finalizers may not be necessary
<jeremy_c> connection -> string -> int * (string * sql_column_type) list * string list list
<jeremy_c> the int * (string * sql_column_type) list part ..... is that a tuple where first element is a int, second element is a list of tuples?
<jeremy_c> hm, then the last is a list of a string list... how do I access the 3rd part?
<pango> break the 3-tuple with pattern matching
<pango> let a, b, c = 1, 2, 3 ;;
<buggs> pango, dunno, i usually get alond with printf
<pango> jeremy_c: tuples aren't a recursive datastructure; you can't break a 3-tuple in a 2-tuple and an another element
chessguy has joined #ocaml
<jeremy_c> pango: k.
chessguy has quit [" HydraIRC -> http://www.hydrairc.com <- The professional IRC Client"]
Leonidas has joined #ocaml
smimou has joined #ocaml
shawn has joined #ocaml
postalchris has joined #ocaml
postalchris has left #ocaml []
f78 has joined #ocaml
<jeremy_c> How do I extend a module? Say I want to add a "Join" method to List?
Snark has joined #ocaml
Wild_Cat has joined #ocaml
Wild_Cat has quit []
<pango> jeremy_c: you can "include" a module in another
<jeremy_c> pango: I am really enjoying OCaml. Things are starting to snap and make sense.
jeremy_c has quit [Client Quit]
cjeris has joined #ocaml
gim_ has joined #ocaml
ziggurat has joined #ocaml
shawn has quit [No route to host]
Leonidas has left #ocaml []
newbcoder has joined #ocaml
<newbcoder> how do I open up a file; consume every line up until the last "Loading" line; then print everything else out?
<newbcoder> trying to make ocaml my new scripting language instead of perl
<newbcoder> I hope someone will be kind ehough to walk me through it
<pango> have a look at the Cookbook (in the topic)
jeremy_c has joined #ocaml
<pango> it shows how to program common Perl tasks in different languages, including OCaml
<pango> Well, it's not complete, but that should be more than enough to give you an idea
<jeremy_c> Anyone use ocamldbi? I'm having problems linking.
<jeremy_c> I've installed it via godi and am using OCamlMakefile
<pango> newbcoder: I also remember reading a page evaluating different languages for "scripting tasks", and OCaml was just in the middle (in a scale ranging from "true shells" *sh to C, if I remember well)
<jeremy_c> ocaml-odbc was working great for me, but trying to select from my claims table, I get a bus error no matter what I do :-(
mauke has joined #ocaml
<pango> newbcoder: but I'm not sure I'll find it again :/
<mauke> you can run but you cannot hide
<newbcoder> thanks
<pango> newbcoder: it should be noted about the Cookbook that some tasks are Perl-centric, so translations in other languages do not always give them justice
<pango> on the other hand, it could be exactly what you're looking for :)
chessguy has joined #ocaml
<pango> some people have also tried writing libraries helpful for scripting tasks: Cash (http://pauillac.inria.fr/cash/), shell (http://www.ocaml-programming.de/packages/)...
rodrigo has joined #ocaml
chessguy2 has joined #ocaml
<rodrigo> can i do gui programming in ocaml? like with buttons, dialogs..
<pango> rodrigo: they're wrappers for Tk and Gtk, at least
<rodrigo> what are wrappers?
<buggs> bindings
<pango> well, the core of those libs are written in C, so they're not purely OCaml code; mostly interfaces to those cores
<rodrigo> hmm.. ok
<rodrigo> thanks
chessguy has quit [Nick collision from services.]
chessguy2 is now known as chesguy
chesguy is now known as chessguy
danly has quit [Remote closed the connection]
danly has joined #ocaml
f78 has quit ["Leaving"]
<pango> newbcoder: with only immutable values, your program could be written as such: http://nopaste.tshw.de/11586101643cba8/
smimou has quit [Remote closed the connection]
smimou has joined #ocaml
<pango> newbcoder: functional and imperative (in OCaml too, there's more than one way to do things ;) ): http://nopaste.tshw.de/11586107903cba8/
chessguy has quit [" HydraIRC -> http://www.hydrairc.com <- The dawn of a new IRC era"]
rodrigo has quit [Nick collision from services.]
rodrigo_ has joined #ocaml
rodrigo_ has quit [Remote closed the connection]
Snark has quit ["Leaving"]
_velco has quit ["I'm outta here ..."]
<jeremy_c> 3.09.3 is released, anyone change the channel topic?
<jeremy_c> I know that a particular result (database query) has 10 fields. I want to get the field name and field type of those 10 fields. What's the best way to loop through 1-10 building a List in the process?
<jeremy_c> I know I can use a for loop, but not certain of building the list through the for loop. I could build a recursive function but not sure how to cap it at 10 (actually a variable number) except using an if statement. Any thoughts?
<pango> what's wrong with an if expression ? it's not uncommon for recursive functions to have to test for the base case ;)
<jeremy_c> pango: I thought it was an Imperative feature of ocaml that ocaml programmers shyed away from.
<pango> notice you said statement, and I said expression ;)
<jeremy_c> yeah, true. also in the pasted example, I did have other lines in there thus the begin end that's not needed.
cjeris has left #ocaml []
<pango> last like can also be written List.iter (Printf.printf "%i,") r but I'm not sure it helps with readability. Just mentionning it for completeness.
<pango> s/like/line/
<pango> and your build function is not tail recursive, but it doesn't matter for 10 elements...
<jeremy_c> s was also a string to begin with, later changed to an int. That is cool your example w/printf. I am still getting use to incomplete functions
<jeremy_c> it's not always going to be 10, one table has 258 fields.
<pango> that's still probably ok
<jeremy_c> I'm a bit confused how I would do it another way, do you have an example?
<pango> this should give the same result: http://pastie.caboo.se/13881
<pango> the main trick is to use an accumulator
<pango> the other is to build the list from the other end... Since the we're constructing the list by adding elements to the head, we'd otherwise need to reverse the list in the end
<pango> List.rev is tail-rec, but still, that's additional work ;)
<jeremy_c> pango: what platform are you on? Here, I am mac.
<pango> Linux
<jeremy_c> pango: just wondering because of the diff in our pastes to pastie. In textmate, I hit Ctrl+Alt+T, paste... it takes my selected text (or whole file), pastes it to pastie, then pops up a dialog with all the people online on my IM software, and also my open channels on my IRC app. Selecting one will cause it to paste the URL in as an action.
shans_home has quit ["Leaving"]
<jeremy_c> I wonder why your selection doesn't have a color theme selector?
<jeremy_c> your pastie I mean.
<pango> no idea, it's probably too smart ;)
<jeremy_c> I just realized when creating a new post on pastie, it does't have an option for OCaml. Hm. Must be textmate colorizing the code.
<pango> version with the List.rev: http://pastie.caboo.se/13884
<pango> looks more like your original function
<jeremy_c> pango: and the benefit to this would be not having to rebuild the list every iteration, right? Just appends on the end, then rebuilds once during the reverse?
smimou has quit ["bli"]
<pango> the point is that stack usage is bound, no matter the value of min and max
<jeremy_c> pango: I don't understand what that means.
<pango> because tail recursive calls are optimized into "jumps" instead of adding a function call frame on the stack
<pango> let's go back to your original function
<pango> # build 0 100000 ;;
<pango> Stack overflow during evaluation (looping recursion?).
<pango> problem happens because calling itself is not what build does last in x :: build (x + 1) max
<jeremy_c> got it.
<jeremy_c> pango: I appriciate the help you've been these last few days, you've been answering a lot of questions
<pango> np
<pango> that said, with the default stack size, your version does not croak with 50000 elements
<pango> and since tail recursive version is arguably less readable, you can keep your non tail-rec version
<pango> several functions of the standard library are not tail recursive either (that's usually mentionned in the module interfaces)
<dbueno> pango: You seem to be a knowledgeable person. I've been writing a lot of tree-traversal code lately, none of which is tail-recursive.
<dbueno> Is there a well-known, general way of doing tail-recursive tree transformations?
<Ballin_105> pango: when building an application is it better to use Ocaml or ocamlc ?
<pango> I don't know, it usually involves adding extra parameters ("accumulators"). I suspect there's no purely automatic way of transforming functions in tail recursive form however, otherwise I'm sure it would be a nice compiler feature :)
<pango> Ballin_105: native binaries are faster, if slightly slower to compile
<Ballin_105> i meant whenb building as in developing
<pango> Ballin_105: bytecode binaries should be portable, but require an installed runtime. Unless you compile them with -custom to embbed the runtime environment, but you lose the portability ;)
<Ballin_105> i meant for developing
<pango> Ballin_105: as I said, bytecode is slightly faster to compile
<pango> Ballin_105: but nothing to kill for
<Ballin_105> man i wish that camelia let you have more then one file
<pango> if you like IDEs, there's also cameleon, but I have no personal experience with it
<Ballin_105> well i like ide for certai things
<Ballin_105> only thing i wish is that binaries were not so large
<pango> on native binaries, or bytecode build with -custom, there's a fixed cost related to the runtime
<pango> so binaries may appear big because your program is short
<Ballin_105> what do you mean
<pango> binary size as a function of source size is something like b(s) = b0 + k*s
<pango> if you take their ratio b(s)/s = b0/s + k
<Ballin_105> is there any way to make binary size smaller ?
<pango> so when s is small, the ratio is large because of b0/s term
<Ballin_105> i seeee
<Ballin_105> is there any modifed ocamls or anything that result in smaller binariues
<pango> I compiled the small program I wrote for newbcoder earlier
<Ballin_105> how small ?
<pango> * native, unstripped: 129kB
<pango> * native, stripped: 85kB
<pango> * bytecode: 20kB
<pango> * bytecode + -custom: 174kB
<pango> so if you have the runtime installed, and can afford the cost of bytecode interpretation, you can save space by using bytecode compiled executables
<pango> but then again, things get different as programs get larger
<Ballin_105> what exactly does strip do ?
<pango> remove informations mainly used by debuggers
<Ballin_105> i sssseeeeeee
<Ballin_105> doesnt the native compile like output .o and stuff ?
<pango> to get an idea, try "nm" on some unstripped binary
<Ballin_105> i wonder if it would be possible to modify the language or havr it not include stuff i wouldnt use in the outputed executeable
<pango> they're things in the runtime, like the garbage collector, that you can't really remove ;)
_JusSx_ has quit ["leaving"]
<Ballin_105> i mean anything else you think ?
<pango> it would be great if they could be dynamically linked, like in the bytecode case; But that's not currently available
<Ballin_105> i wonder if theres anyways to cut out stuff thats not needed
<Ballin_105> maybe for my next project i will use Ada
<pango> lol
<Ballin_105> ?? lol bad ?
<pango> it's extremely verbose, there's probably few languages more cumbersome to write with than Ada (Java maybe ? :) )
<pango> it probably has its use, but none fits the "5 minutes hacks" description :)
<dark_light> pango, i saw, very good that book
<dark_light> pango, i was thinking that i need to read it in paper, that kind of text isn't very good to read in pc
<dark_light> and i realized that actually i was considering in buy it:)
<dark_light> but i never bought a book written in english before
<pango> dark_light: you mean the oreilly book ? I've been told that only the french version was printed
<pango> dark_light: the english version is a translation of the french book, but never got in print
<Ballin_105> so Ada is bad ?
<dark_light> pango, :(
<pango> Ballin_105: I don't know what you plan to do with it, but I suspect it won't fit
shawn has joined #ocaml
<Ballin_105> pango: i dunno i was just htinking
<dark_light> i am very curious on what a ada code might look like
<Ballin_105> pango: what are good general purpose programming langs besides C c++ ocaml etc ?
<pango> Ballin_105: that said, I don't want to stop you
shawn has quit [Remote closed the connection]
<Ballin_105> i remember i took a Pascal class way back
<dark_light> but i like the good way ocaml asks things to programmer
shawn has joined #ocaml
<Ballin_105> FreeBasic is also compiled and ranks pretty high on there on speed test
<pango> Ballin_105: if you know Pascal, you won't be totally lost with Ada; Still, Ada is much more featureful
<pango> it had to replace lots of languages for many people, so it's even one of its properties :)
shawn__ has joined #ocaml
shawn has quit [Success]