<exarkun>
I can't seem to find any docs explaining why "type symbolType = ..." is legal but "type SymbolType = ..." isn't
<cymonts>
exarkun: afaik, only constructors may begin with capital letters
<exarkun>
thought it might be something like that... constructors, those are for classes right?
<cymonts>
I think they're needed even for simple user-defined types
<exarkun>
ah
<mike_>
exarkun: only constructors for union (sum) types and module names may begin with capital letters
<exarkun>
hmmm, unions...
<exarkun>
When defining functions that operate on sum types, can you take additional parameters unrelated to the sum type? Or combine multiple sum types?
<exarkun>
Like, the docs has the card type example that defines "let string_of_card = function King c -> (...) | Queen c -> (...) ...;;"
<exarkun>
Could you expand that definition so that string_of_cards takes an integer as well?
<exarkun>
and if so, what's the syntax?
<mike_>
the function keyword has one implicit argument
<mike_>
you could add more after string_of_cards but before =
<exarkun>
ok, cool. When calling it, those arguments would come before the sum type argument?
<mike_>
compare function with fun and the let shorthand for fun
<mike_>
yes
<exarkun>
thanks
<mike_>
ocaml >= 3.04 has labeled arguments too
<mike_>
in which case the order doesn't matter
* exarkun
nods.
<exarkun>
Can I depend on Lisp.map applying the function to the list in sequential order?
<exarkun>
or should I use an explicit loop?
<mike_>
i'm pretty sure List.map is guaranteed to proceed in order
<mike_>
traversing a list in order is the only way you can do it in linear time anyway
<mike_>
so it would be pretty retarded not to do it in order
<mike_>
if you're going to do anything with side effects though, you might want to be using List.iter instead
<mike_>
(the list returned by List.map is by definition the map of the same order of the list given to it as an argument, so if that was your question, then certainly yes)
<exarkun>
Ah, i/o, so I guess I'll use that
<exarkun>
thanks
<timmy>
List.map returns a list
<timmy>
maybe List.iter is what you were looking for if you were thinking about a for loop?
<exarkun>
yea
bbdab has quit [Read error: 110 (Connection timed out)]
cymonts has quit [Connection timed out]
gl-limsi has joined #ocaml
gl-limsi has quit [Killed (NickServ (Nickname Enforcement))]
vect- has joined #ocaml
gl-limsi has joined #ocaml
gl-limsi has quit [Remote closed the connection]
vect- has quit [Remote closed the connection]
mr_bubbs has joined #ocaml
gene9 has joined #ocaml
gene9 has quit ["Client Exiting"]
<exarkun>
Hmm. Is there a unit test framework available for o'caml?
Beleg has joined #ocaml
cymonts has joined #ocaml
Beleg has quit []
Dalroth has joined #ocaml
<smkl>
exarkun: try sf.net/projects/fort
<exarkun>
excellent, thanks
Belgarion has joined #ocaml
<Belgarion>
I have a tuple of 4 elements (1,2,3,4).. how do I access the elements in that tuple?
<Dybbuk>
Belgarion: Use a pointy stick!
<Belgarion>
Dybbuk: you're a lot of help :)
<Dybbuk>
Belgarion: Fine, then you can't borrow mine. :)
<Belgarion>
ok!
* exarkun
snickers.
<Dybbuk>
Belgarion: Sometimes the OCaml experts aren't around all the time.
<Belgarion>
Dybbuk: no worries. I figure if I keep looking through this book i'll find it eventually.
<Dybbuk>
Belgarion: Did you try the index?
<Belgarion>
the best way I've found to accomplish it so far is to define a function for it, which seperates the tuple into seperate variables.
<Belgarion>
Dybbuk: no i haven't... good idea!
<Dybbuk>
Mmm, you could do that.
<Dybbuk>
I'm wondering if maybe a four-element tuple isn't the best thing to be returning.
<Belgarion>
it's more of a curiosity than an actaul practice.
<exarkun>
return a 2-tuple of 2-tuples or an int * (int * (int * int)) tuple
<smkl>
try "let (x,y,z,w) = tuple in ..."
<mr_bubbs>
would an Array be more efficient than a List for random access to an element?
<smkl>
sure
<exarkun>
Can one concatenate a character to a string?
<Dybbuk>
You can do this: "foo" ^ (String.make 'x' 1)
<Dybbuk>
Err... (String.make 1 'x')
<Dybbuk>
There might be a more elegant way. :)
<exarkun>
yea, was hoping for a more elegant way :)
<Dybbuk>
If you need to do it a bunch, you might want to look at the Stream package.
<Dybbuk>
Or the Buffer package, rather.
<Dybbuk>
Stream looks like it's mainly for output.
<smkl>
streams are mostly useful for parsing
<smkl>
and you don't need pars in "foo" ^ String.make 'x' 1
<Dybbuk>
I like the parens for readability...but I'm a Lisp programmer, so that's probably just me. :)
<exarkun>
How do I generate the file ocamldebug wants? It says it wants bytecode. i thought those were .cmo files but it won't take them.
<smkl>
first compile with -g, then it just wants the executable
<exarkun>
ahhh, that did it. thanks
derfy has joined #ocaml
derfy has quit ["Leaving"]
<exarkun>
Is it possible to do a forward declaration for a function? Basically I have a couple of mutually recursive functions..
<exarkun>
ahh, double ; messing me up, nevermind :)
Dalroth has quit []
cymonts has quit [Read error: 60 (Operation timed out)]
cymonts has joined #ocaml
cymonts_ has joined #ocaml
cymonts has quit [Read error: 110 (Connection timed out)]
cymonts_ has quit [Read error: 110 (Connection timed out)]