Yurik changed the topic of #ocaml to: http://icfpcontest.cse.ogi.edu/ -- OCaml wins | http://www.ocaml.org/ | http://caml.inria.fr/oreilly-book/ | http://icfp2002.cs.brown.edu/ | SWIG now supports OCaml| Early releases of OCamlBDB and OCamlGettext are available
lament has joined #ocaml
polin8 has quit ["Lost terminal"]
polin8 has joined #ocaml
* intero is back (gone 06:43:44)
<intero> whee: i did that function
<intero> thanks
<whee> using fold_left?
<intero> nope :P
<intero> but thanks for support
<whee> it would be shorter
<whee> heh
<intero> probably
<intero> but i wasnt sure on how to use it
<intero> i'll review later :)
<intero> do you know the simplex algorithm?
<whee> never heard of it D:
<intero> heh it's something to find the best solution in a problem
<intero> nothing special
<intero> i may implement that in ocaml in the next month
<intero> so i am training
<intero> well i'll go to sleep now
<intero> thanks again for support, take care
<whee> night
intero has left #ocaml []
malc has joined #ocaml
malc has quit [brunner.freenode.net irc.freenode.net]
merriam has quit [brunner.freenode.net irc.freenode.net]
malc has joined #ocaml
merriam has joined #ocaml
Kinners has left #ocaml []
malc has quit [Read error: 110 (Connection timed out)]
mattam has quit ["leaving"]
lament has quit ["<Liam> cocks || <Liam> gigantic cocks || <Liam> slapping me in the face"]
lament has joined #ocaml
listener has joined #ocaml
<listener> Anyone here?
<listener> How do I write a function that raises an exception.
<listener> I tried
<listener> exception my_ex;;
<listener> let raise_my=raise my_ex;;
<listener> That didn't work.
listener has left #ocaml []
mattam has joined #ocaml
asqui has quit [Read error: 110 (Connection timed out)]
intero has joined #ocaml
<intero> hi all
systems has joined #ocaml
systems has left #ocaml []
__mattam__ has joined #ocaml
mattam has quit [Read error: 113 (No route to host)]
__mattam__ is now known as mattam
<intero> what does '_a mean?
<smkl> it is so called weak type variable
<smkl> it means that there exists one type '_a that can be bound to it
<smkl> for example: let x = ref [] => x : '_a list ref ... x := [1] => x : int list ref
<intero> mmm
<intero> i still dont see the huge difference between 'a and '_A
<intero> '_a
<intero> i mean, if it's not 'a, then why not 'b?
<intero> thanks smkl anyway, i am a newbie :P
<intero> later
<smkl> say you have functions of type '_a -> '_a and type 'a -> 'a ... first time you use the first function with for example int argument, the functions type becomes int -> int .. the second functions type won't change
merriam has quit [brunner.freenode.net irc.freenode.net]
polin8 has quit [brunner.freenode.net irc.freenode.net]
whee has quit [brunner.freenode.net irc.freenode.net]
skylan has quit [brunner.freenode.net irc.freenode.net]
lindril has quit [brunner.freenode.net irc.freenode.net]
lam has quit [brunner.freenode.net irc.freenode.net]
mattam has quit [brunner.freenode.net irc.freenode.net]
Zadeh has quit [brunner.freenode.net irc.freenode.net]
Segora has quit [brunner.freenode.net irc.freenode.net]
xkb has quit [brunner.freenode.net irc.freenode.net]
Torquema1a has quit [brunner.freenode.net irc.freenode.net]
emu has quit [brunner.freenode.net irc.freenode.net]
nkoza has quit [brunner.freenode.net irc.freenode.net]
intero has quit [brunner.freenode.net irc.freenode.net]
lament has quit [brunner.freenode.net irc.freenode.net]
foxen5 has quit [brunner.freenode.net irc.freenode.net]
smkl has quit [Nick collision]
smkl has joined #ocaml
mattam has joined #ocaml
intero has joined #ocaml
lament has joined #ocaml
merriam has joined #ocaml
polin8 has joined #ocaml
whee has joined #ocaml
Zadeh has joined #ocaml
skylan has joined #ocaml
foxen5 has joined #ocaml
emu has joined #ocaml
Torquema1a has joined #ocaml
xkb has joined #ocaml
nkoza has joined #ocaml
Segora has joined #ocaml
lindril has joined #ocaml
lam has joined #ocaml
docelic|away has quit [Excess Flood]
docelic|away has joined #ocaml
clog has joined #ocaml
rox| has joined #ocaml
systems has joined #ocaml
asqui has joined #ocaml
mattam has quit [Read error: 60 (Operation timed out)]
mattam has joined #ocaml
mattam_ has joined #ocaml
mrvn_ has joined #ocaml
mattam_ has left #ocaml []
systems has quit [Read error: 110 (Connection timed out)]
dash has quit [Read error: 110 (Connection timed out)]
mrvn has quit [Read error: 110 (Connection timed out)]
lament has quit ["<Liam> cocks || <Liam> gigantic cocks || <Liam> slapping me in the face"]
<whee> bloop
<whee> figure out the exception stuff intero?
<intero> yes i am done thanks
<intero> still slow in coding though
Stapler has joined #ocaml
systems has joined #ocaml
<Stapler> I got a question. Can I create a list of functions, aka "let batch = [fib[x], power[y], relist]" ?
<whee> provided the functions are of the same types, yes
<whee> you could use variants (polymorphic variants would be nice) if you needed to do other things
<Stapler> whee: Alright. Just curious. I'm a newbie to OCaml.
<Stapler> whee: Is there a practical limit to just how far I can take that technique?
<whee> depends on what you're doing, I guess
<Stapler> whee: Well, I mean, if I gave the code to someone else to peruse, I dont want them going "What the f**k are you trying to do here?". Heh.
<whee> if the way you do it works well, then I wouldn't worry
<Stapler> whee: Gotcha.
<Stapler> whee: Right now I'm working on figuring out how to open a text file, chop it up, and sort the words into a dictionary/glossary.
<whee> that one's always fun :)
<Stapler> whee: Well, I figure it's good practice.
<whee> there's a lot of different ways you can do the actual parsing with that
<Stapler> First I gotta create a list of word delimiters. i.e. Space, Tab, comma, colon, etc...
systems has left #ocaml []
<Stapler> Would I delimit the delimiters using single or double quotes? [' '; ';';',';'.'] ?
<whee> single if you're parsing by characters
* Stapler nods
<Stapler> Alright, what part of the library reference do I look in for Unix file I/O?
Stapler has left #ocaml []
<mrvn_> unix
<mrvn_> file:///usr/share/doc/ocaml-doc/docs/ocaml.html/manual035.html
<mrvn_> Chapter 21 The unix library: Unix system calls
rox| is now known as rox
<intero> nite all, whee
intero has left #ocaml []
systems has joined #ocaml
Stapler has joined #ocaml
<Stapler> What's up?
<mrvn_> Stapler: file:///usr/share/doc/ocaml-doc/docs/ocaml.html/manual035.html
<mrvn_> Chapter 21 The unix library: Unix system calls
* Stapler nods
<Stapler> Looking it over right now.
<mrvn_> Pretty good interface
<Stapler> mrvn_: Quite a bit simpler than I had expected.
<Stapler> Trying to figure out the "fprintf" interface at the moment.
<mrvn_> Printf.printf "format" arg arg arg
<Stapler> Do I have to explicitly do "let show = open_out : stdout;;" before I can use fprintf?
<mrvn_> not that I now
<Stapler> mrvn_: mind if I post up a code snippet?
<mrvn_> no
<Stapler> let dlst = [' ';';';',';'.'];;
<Stapler> let x = open_in("Rev.txt");;
<Stapler> let show = Printf.printf "%s" y;;
<Stapler> let rec isin x dlst =
<Stapler> match dlst with
<Stapler> [] -> false
<Stapler> | y :: dlst -> x = y
<Stapler> show
<Stapler> || isin x dlst;;
<Stapler> Make sense?
<mrvn_> Unbound value y
<mrvn_> let show () ?
<mrvn_> let show y = ?
<Stapler> Yup. Actually I want to show everything that does not match dlst.
<Stapler> Trying to load in the text file Rev.txt
<Stapler> I dont suppose I would do "let x[] = open_in("Rev.txt");;" ?
<Stapler> And change show to "let show = Printf.printf "%s" x;;" ?
<Stapler> errr... x[y]?
<mrvn_> Warning: this pattern-matching is not exhaustive.
<mrvn_> Here is an example of a value that is not matched:
<mrvn_> _::_
<mrvn_> val x : 'a list -> in_channel = <fun>
<mrvn_> Never directly used in_channel.
<mrvn_> How do you get the first element?
<Stapler> mrvn_: Doesn't OCaml's open_in read in the file from the beginning?
<Stapler> mrvn_: Note...I'm an OCaml newbie. Formerly used to C and Ada.
<mrvn_> no. I think that opens the file so you can read from it.
<mrvn_> Imagine it would be a 12 TB big file and you would open it.
<Stapler> Ahhh...I see.
<Stapler> So I need two functions/procedures. One for creating a "handle" and another to actually read from the handle.
<Stapler> I'm checking to see if EOF is defined in the standard libs.
<whee> no, it isn't
<whee> you'll get an End_of_file exception raised if you hit eof while reading
<Stapler> whee: I can't just define EOF myself and avoid the exception altogether?
<whee> there's no way to read eof
<whee> by definition eof means there's nothing left to read, the proper thing is to raise an exception
<Stapler> whee: Well, your correct in that eof means theres nothing left to read. Not sure I agree that the "proper" thing(in all cases) is to raise an exception.
<whee> what would you do if not an exception?
<Stapler> whee: I would only raise an exception if there is no other behavior explicitly defined for when the stream hits eof.
<whee> you can define whatever behavior you want by catching the exception
<whee> and dealing with it
<whee> the reading function really has no idea what to do when there's nothing left, so it raises and hopes someone else knows
<Stapler> whee: True. But, if I was writing a time-sensitive app, I might not want to use an exception.
matkor has joined #ocaml
<matkor> Good evening.
<whee> they really aren't that much of a performance hit
<whee> how often do you hit eof?
<Stapler> whee: Of course, I'm assuming that exceptions are raised similiarly to Ada, which could be wrong.
<whee> they're likely compiled down to a setjmp/longjmp much like C
<mrvn_> How do I load ocamlp4 into a ocaml shell?
<Stapler> whee: What if I knew the size of the file before hand, and just declared a char list 1..size_of_file?
<whee> mrvn: #load "camlp4o.cma";; for normal syntax, camlp4r.cma for regular
<whee> Stapler: you wouldn't hit eof then
<whee> since you would know the size of the file, you wouldn't attempt to read past it
<mrvn_> #load "camlp4o.cma";;
<mrvn_> open Genlex;;
<mrvn_> let lexer = make_lexer [" ";";";",";"."];;
<mrvn_> let rec parse = parser
<mrvn_> [< 'Kwd x; >] -> ()
<mrvn_> | [< 'String x; >] -> print_string x
<mrvn_> | [< n1 = parse; n2 = parse >] -> ();;
<Stapler> Heh. Makes it nice and spiffy.
<mrvn_> That should do what you want.
<whee> exceptions are cleaner for things like that, anyway :p
* Stapler nods
<whee> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=fa.de6cumv.1egecb6%40ifi.uio.no&rnum=1&prev=/groups%3Fq%3Dexceptions%2Bgroup:fa.caml%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Dfa.de6cumv.1egecb6%2540ifi.uio.no%26rnum%3D1 there
<whee> haha, that's huge
<Stapler> mrvn_: Why did you use a string list instead of a character list?
<mrvn_> Thats how the lexer wants it.
<mrvn_> let lexer = make_lexer ["+";"-";"*";"/";"let";"="; "("; ")"]
<Stapler> I see.
<Stapler> Hmmm...once I get this down, I could rework it to look like K or J.
<whee> with that you throw the file through the lexer, and then through the parser
* Stapler nods
<whee> it's a bit easier to deal with when it hits the parser if you've got it down to a bunch of variants
<Stapler> I see.
<Stapler> No need to define my own match list explicitly, I just pull a subset out of the OCaml lexer.
<mrvn_> Stapler: Why don#t you use simple strings if the file is small?
<mrvn_> String.split_delim (regexp "[,; ]+") (string_of_file)
<whee> I wouldn't do that, :)
<mrvn_> why?
<whee> I'd definately go with using streams, which would lazily parse
<mrvn_> For anything <1K using a string, string list or char list is prefectly fine.
<Stapler> mrvn_: I dont suppose OCaml supports block allocation?
<mrvn_> You mean allocating an array of objects to be used in a list and saving the header of the individual objects?
<Stapler> mrvn_: In a nutshell. Can I be sure that the object will be de-allocated when it goes out of scope?
<mrvn_> Stapler: within some time.
<whee> not when it goes out of scope, but when the gc gets around to it
<mrvn_> The gc is pretty fast for short lived objects and slower for long lived ones.
<Stapler> Because I could use a string block for pulling in chunks of text at a time.
<mrvn_> Whats the complete problem you want to solve? Read in a list of strings seperated by the delimiters?
<Stapler> mrvn_: I want to chop up a text file according to the delimiters.
<Stapler> mrvn_: I'm just doing it for practice.
<Stapler> Put the words into a sorted list.
<Stapler> This whole recursive function thing has got me scratching me head. I'll figure it out.
<mrvn_> Find out how long the file is, create a string, read in the file, split it, sort the string list.
<whee> that could be hell for performance
<mrvn_> Not a single recursion in there but you need twice the filesyste amount of ram.
* Stapler nods
<Stapler> I'm just exploring the language right now.
<mrvn_> whee: Why? Reading in the file is O(n), spliting is O(n) and sorting O(n log n)
<whee> it uses a lot of ram :P
<mrvn_> You can'tdo it any faster
<whee> what if the file's 2gb? :P
<mrvn_> As I said, ~twice the file size.
<whee> I doubt the GC would like a huge block like that floating around
<mrvn_> Strings are probably limited to 1GB or even lesse.
<mrvn_> (on 32 Bit cpus)
<whee> it'd be a lot easier to get from a file to a list of words using the lexer/parser combination
<mrvn_> Arrays are limited to 4 billion.
<whee> plus the heap size would be relatively constant (while parsing)
<mrvn_> whee: sure. But much more complex.
<whee> and scalable, and flexible
<mrvn_> The best thing would probably to mmap the file and then split it into a string list.
<mrvn_> +bw
<mrvn_> +be even
<mrvn_> Also a suffix tree might be better for big files to save memory.
<mrvn_> Stapler: ever used lexx and yacc?
<Stapler> mrvn_: Nope. Never had a need to.
<mrvn_> Might be a good thing to look at now.
<Stapler> mrvn_: Something I outta check out then.
matkor has quit [Remote closed the connection]
<mrvn_> Of cause its realy overkill just to split a string but worth knowing
systems has quit ["Client Exiting"]
* Stapler nods
<mrvn_> Is it expensive to add a char to the end of a string in ocaml?
<Stapler> Lets see here. "let txtfl = string(67404);;"
<whee> a string's just an array, so it's the same as changing an array value in C
<whee> appending to a string requires allocating more space
<mrvn_> It also makes a new string instead of modifying the string, right?
<whee> yes, you should get a new string out of it
<mrvn_> Stapler: let str = String.create 20;;
<mrvn_> val str : string =
<mrvn_> "ø\027 @\000\011\000\000\128\028 @\001\000\000\000\000\011\000\000"
<mrvn_> lol
Kinners has joined #ocaml
<mrvn_> Good that I didn't allocate a 4MB string. That would scroll.
<mrvn_> So it would be better to make a char list during parsing and only when finding a delimiter allocate a properly sized string, right?
<whee> that's what I would do, yes
<mrvn_> Can you make a string of a list but in the reverse order?
<Stapler> Well, to be most efficient, it should be able to pattern match while the file is being loaded.
<whee> you'd have to reverse the list
<mrvn_> Stapler: are duplicate strings important?
<Stapler> mrvn_: No. Not in this case.
<mrvn_> Then a common suffix tree would be best for large files.
* Stapler is being paged
<mrvn_> aaa,abc,acc would give you [(a, [(a, [(a, [])]), (b, [(c, [])]), (c, [(c, [])])])]
<Stapler> Gotcha.
<Stapler> Be right back.
Stapler has left #ocaml []
Kinners has quit [Read error: 104 (Connection reset by peer)]
lament has joined #ocaml
gehel has quit ["My damn controlling terminal disappeared!"]
mattam has quit ["leaving"]