systems changed the topic of #ocaml to: OCaml 3.07 ! -- Archive of Caml Weekly News: http://pauillac.inria.fr/~aschmitt/cwn , A tutorial: http://merjis.com/richj/computers/ocaml/tutorial/ , A free book: http://cristal.inria.fr/~remy/cours/appsem, Mailing List (best ml ever for any computer language): http://caml.inria.fr/bin/wilma/caml-list
mattam_ has quit [Read error: 110 (Connection timed out)]
kwmarc has quit [Remote closed the connection]
olczyk has quit [Read error: 104 (Connection reset by peer)]
cjohnson has joined #ocaml
mimosa has quit ["J'ai fini."]
gim has quit []
olczyk has joined #ocaml
bk_ has quit ["I'll be back"]
Nutssh has joined #ocaml
gauchopuro has joined #ocaml
kinners has joined #ocaml
buggs has quit [Connection timed out]
wazze has quit ["--- reality is that which, when you stop believing in it, doesn't go away ---"]
buggs has joined #ocaml
keenan has joined #ocaml
<keenan> hello
yeoh has joined #ocaml
<keenan> ok i have a question
<keenan> how do you make a function do different things when applied to data of different types?
<keenan> like how could you difine a function sum so that "sum a b" would return "a + b" if they're both ints, "a +. b" if they're both floats, and "a +. float_of_int b" if a is a float and b is an int?
<Riastradh> You can't.
<keenan> oh, ok
<keenan> so there's no way to just tell what type an expression is?
<Riastradh> Not at run-time. All type information is eliminated after compile-time.
<keenan> aha
<keenan> ok that makes sense
<keenan> so if you want a function to operate on different types of data, it can't do anything on them that depends on the type
<Riastradh> You could have a special type for the argument with constructors for each possible type.
<Riastradh> type Int_or_float = Int of int | Float of float
<Riastradh> let sum = function Int i -> function Int j -> Int (i + j) | Float g -> Float ...
yeoh has quit ["User pushed the X - because it's Xtra, baby"]
<keenan> ok what does the "|" symbol mean in this context?
<keenan> pattern matching, right?
<keenan> i haven't really got that far yet
<Riastradh> Formatting might help some.
<Riastradh> let sum = function
<Riastradh> Int i -> (function
<Riastradh> Int j -> Int (i + j)
<Riastradh> | Float j -> Float (float_of_int i +. j))
<Riastradh> | Float i -> (function
<Riastradh> Int j -> ...
<Riastradh> etc.
<pattern> "|" is like "or".... the pattern matches "Int j -> Int (i + j)" _or_ it matches "Float j -> Float (float_of_int ..."
vegai has quit [Read error: 110 (Connection timed out)]
<pattern> also, instead of saying "function" it might be clearer to make explicit that there's a function argument being matched... so that it would be "let sum x = match x with" instead of "let sum = function" (which are equivalent)
<keenan> oh weird
<keenan> ok
vegai has joined #ocaml
<keenan> ok and then after you do that you can't just say "sum 2 3;;"
<keenan> you have to construct a new object of type "int_or_float"
<keenan> ok it works
<keenan> it's just more trouble than it's worth in this case
lam has quit [kornbluth.freenode.net irc.freenode.net]
cmeme has quit [kornbluth.freenode.net irc.freenode.net]
Smerdyakov has quit [kornbluth.freenode.net irc.freenode.net]
The-Fixer has quit [kornbluth.freenode.net irc.freenode.net]
<olczyk> A couple of questions: is there something like nm/objdump for ocaml?
<olczyk> Is there a way of getting the loaded modules?
The-Fixer has joined #ocaml
lam has joined #ocaml
cmeme has joined #ocaml
Smerdyakov has joined #ocaml
<kinners> olczyk: there are a couple of programs in the tools dir of the ocaml source tree
<kinners> olczyk: like dumpobj and objinfo
<olczyk> Sigh. Not in the Windows binary. I'll have to look at the source.
<olczyk> What about listing the loaded modules?
Riastradh has quit [Remote closed the connection]
Riastradh has joined #ocaml
srv has quit [Remote closed the connection]
Nutssh has quit ["Client exiting"]
<kinners> olczyk: I don't know about that
srv has joined #ocaml
smkl has quit [kornbluth.freenode.net irc.freenode.net]
Nutssh has joined #ocaml
smkl has joined #ocaml
Nutssh has quit [Client Quit]
Nutssh has joined #ocaml
lam has quit [kornbluth.freenode.net irc.freenode.net]
cmeme has quit [kornbluth.freenode.net irc.freenode.net]
Smerdyakov has quit [kornbluth.freenode.net irc.freenode.net]
The-Fixer has quit [kornbluth.freenode.net irc.freenode.net]
<keenan> ok so this thing: "type Int_or_float = Int of int | Float of float" works just like a union in C, right?
The-Fixer has joined #ocaml
lam has joined #ocaml
cmeme has joined #ocaml
Smerdyakov has joined #ocaml
<keenan> only better, because there's no danger of trying to access the data as the wrong type and getting garbage
<keenan> pretty nifty
<olczyk> It's a tagged union.
<keenan> ok thanks for the help
keenan has left #ocaml []
olczyk has quit [Read error: 60 (Operation timed out)]
kinners has quit ["leaving"]
bernard has quit [Read error: 110 (Connection timed out)]
gauchopuro has quit ["Leaving"]
Nutssh has quit ["Client exiting"]
LordJ|m has quit [Read error: 110 (Connection timed out)]
mimosa has joined #ocaml
LordJ|m has joined #ocaml
gim has joined #ocaml
The-Fixer has quit ["Goodbye"]
olczyk has joined #ocaml
<olczyk> Is there a way of getting a list of loaded modules in a toplevel? How about functions etc. in one of those modules?
cjohnson has quit [Remote closed the connection]
olczyk has quit [Read error: 54 (Connection reset by peer)]
<LordJ|m> what's wrong with this : let test p = match p with parser [< '(Kwd "WORD1"); '(Int n) > ] -> function ?
<LordJ|m> i get a syntax error
<pattern> just a wild guess... but should "> ]" be ">]" ?
srv has quit ["Lost terminal"]
srv has joined #ocaml
<LordJ|m> i tried but it didn't work
<LordJ|m> it's an example from the oreilly book about developing applications in ocaml
<pattern> sorry, i don't know anything about parsers
<LordJ|m> ok
<pattern> did you try running your code through the preprocessor?
<LordJ|m> yes i have the same error
<LordJ|m> i think the problem lies in the keyword "parser"
<LordJ|m> is there a module to load or something ?
<LordJ|m> i load ocamlp4o.cma
<pattern> i just add "-pp camlp4o" to ocamlc's arguments
The-Fixer has joined #ocaml
kwmarc has joined #ocaml
<kwmarc> hello
<LordJ|m> pattern: it worked, thanks :)
<LordJ|m> i was adding -I +camlp4 and so on
mimosa has quit ["J'ai fini."]
mimosa has joined #ocaml
LordJ|m has quit [Read error: 54 (Connection reset by peer)]
wazze has joined #ocaml
bk__ has joined #ocaml
bk__ has quit [Client Quit]
bk__ has joined #ocaml
olczyk has joined #ocaml
<olczyk> In a toplevel, is there a way to ask for a list of all loaded modules?
bernard has joined #ocaml
olczyk has quit [Read error: 54 (Connection reset by peer)]
two-face has joined #ocaml
<two-face> hi
cjohnson has joined #ocaml
jonka is now known as rox
olczyk has joined #ocaml
<olczyk> In a toplevel, is there a way to ask for a list of all loaded modules?
two-face has quit [Remote closed the connection]
pattern has quit [Connection timed out]
olczyk has quit [Read error: 104 (Connection reset by peer)]
Nutssh has joined #ocaml
pattern has joined #ocaml
kwmarc has quit ["Leaving"]
pattern has quit [Read error: 110 (Connection timed out)]
Nutssh has quit ["Client exiting"]
Nutssh has joined #ocaml
bernard has quit ["leaving"]
Nutssh has quit ["Client exiting"]
pattern has joined #ocaml
pattern has quit [Read error: 60 (Operation timed out)]
pattern has joined #ocaml
mattam_ has joined #ocaml
maihem has quit ["Client exiting"]
mattam has quit [Nick collision from services.]
mattam_ is now known as mattam