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
kinners has joined #ocaml
bk_ has quit ["I'll be back"]
kinners_ has joined #ocaml
bk_ has joined #ocaml
kinners has quit [Read error: 60 (Operation timed out)]
reltuk has quit ["User disconnected"]
<LittleDa1> what are functors?
<Riastradh> Essentially, they're functions that exist only at compile-time whose inputs & outputs are structures.
<LittleDa1> so they're macros that operate on structures?
<LittleDa1> do they dispatch on types or something?
<LittleDa1> I've heard they can provide structured polymorphism somehow
denshi has joined #ocaml
<LittleDa1> riastradh?
<Riastradh> There's no type dispatch; rather, your functor can generalize over any type by putting it in the structure in the functor's arguments.
<LittleDa1> So the type is an argument?
<Riastradh> No, the type is in a structure, which is passed to the functor.
<LittleDa1> What kind of structure is this? It's not a regular record, is it?
<LittleDa1> is there something in the manual about this? I can't find anything
<LittleDa1> Is there a completely different syntax for these compiletime functions?
<Riastradh> If you don't know what a structure is, you should be reading the manual, not asking me about the module system.
<LittleDa1> sorry
<Riastradh> The tutorial at the beginning of the manual has a fairly decent introduction to the module system, if my memory serves.
<pattern> littleda1, "What are functors?" thread on the ocaml-beginners list -> http://groups.yahoo.com/group/ocaml_beginners/message/1614
<LittleDa1> thanks
<LittleDa1> so those have to be at compiletime to preserve static typing, right?
<Riastradh> They have to be at compile-time because they play a role in the module system.
<LittleDa1> oh
<LittleDa1> and modules have to be compiletime to preserve static typing or something else?
<LittleDa1> because IIRC modules are runtime in Python
<Riastradh> Python's architecture is not designed to operate well with static compilation.
<LittleDa1> It seems like each programming language has a completely different concept of modules
<Riastradh> Most programming languages themselves are pretty different.
<LittleDa1> So do functors accomplish something similar to Ruby's use of modules as mixins, but in a less dangerous, more efficient, and more module-oriented way?
<Riastradh> And aside from the aqueducts, the roads, et cetera as well?
<LittleDa1> what?
<Riastradh> Monty Python reference.
<LittleDa1> which one
<Riastradh> _Life of Brian_
<LittleDa1> so is that statement correct?
<Riastradh> What statement?
<LittleDa1> Are functors analogous to mixins in Ruby?
<Riastradh> That's an interrogative, not a declarative; a question, not a statement.
<LittleDa1> Functors are analogous to mixins in Ruby.
<LittleDa1> better?
<Riastradh> Given that I'm not very familiar with Ruby, I can't say.
<LittleDa1> ok
<Smerdyakov> LittleDa1, are mixins related to multiple inheritance?
<LittleDa1> yes, but you're including a module, and it's expected that you have certain functions implemented in the class
<Smerdyakov> Functors are not related to multiple inheritance.
<Smerdyakov> Please, just read the manual.
<LittleDa1> I know they're not related to multiple inheritance
<LittleDa1> but they are used in similar situations
<LittleDa1> I read the manual
<Smerdyakov> OK
<Smerdyakov> To me, it's clear that "expecting to have some things implemented" is a lot worse than having a type system enforce proper use of functors.
<LittleDa1> I know, it's very dangerous
<LittleDa1> but somewhat simpler
<Smerdyakov> Not simpler to code, since there are more possibilities for confusing errors.
<LittleDa1> I haven't had much trouble debugging Ruby; you rarely make errors of that sort. I don't want to get in a big debate about typesaftey, though
Jaundice has joined #ocaml
pattern has quit []
LittleDa1 has left #ocaml []
pattern has joined #ocaml
denshi has quit ["leafChat IRC client: http://www.leafdigital.com/Software/leafChat/"]
Jaundice has quit ["Leaving"]
wazze has quit ["--- reality is that which, when you stop believing in it, doesn't go away ---"]
Lemmih has joined #ocaml
cjohnson has joined #ocaml
cjohnson has quit ["Drawn beyond the lines of reason"]
cjohnson has joined #ocaml
housetier has quit ["#breaks @ irc.highteq.de"]
themus has joined #ocaml
reltuk has joined #ocaml
kinners_ has quit ["leaving"]
bk_ has quit ["I'll be back"]
reltuk has left #ocaml []
mrsolo has joined #ocaml
gim has joined #ocaml
mrsolo has quit [Read error: 104 (Connection reset by peer)]
Banana has quit [Read error: 104 (Connection reset by peer)]
reltuk has joined #ocaml
mrsolo has joined #ocaml
__DL__ has joined #ocaml
bk_ has joined #ocaml
__DL__ has quit [Read error: 104 (Connection reset by peer)]
Jaundice has joined #ocaml
mrsolo has quit [Read error: 54 (Connection reset by peer)]
mrsolo has joined #ocaml
SpookRijder has joined #ocaml
smimou has joined #ocaml
smimou has quit [Remote closed the connection]
smimou has joined #ocaml
reltuk has left #ocaml []
Banana has joined #ocaml
mijdrol has quit [Read error: 110 (Connection timed out)]
mijdrol has joined #ocaml
<slashvar[lri]> Hi
<Banana> Hello.
<gl> Hu.
<bk_> hello
buggs^z has joined #ocaml
buggs has quit [Read error: 60 (Operation timed out)]
mrsolo has quit ["Leaving"]
slashvar[lri] is now known as slashvar[kf]
Jaundice has quit ["Leaving"]
SpookRijder has quit ["Client Exiting"]
slashvar[kf] is now known as slashvar[typage]
kinners has joined #ocaml
LordBrain has joined #ocaml
<LordBrain> Hello, i am a beginner in ocaml. For writing a simple program which accepts connections on a given port on a network, what module should i use and read?
<smimou> Unix
<LordBrain> ty
<LordBrain> what does { mean?
<LordBrain> i see it in someone else's source
<LordBrain> ({ listen_sock = sock; trans_sock = None;
<LordBrain> buf = " "; buf_off = 0; sent_len = Int32.zero; opened = true;
<LordBrain> mutex = Mutex.create () }, port)
<Banana> it's a record.
<Banana> like a struct in C.
<LordBrain> ah hmm
<Banana> if you have v = {x = 10; y=5} then you can access its fields with v.x or v.y
<LordBrain> oh i see
<Banana> you have to define the record before though.
<Banana> with :
<Banana> type point2D = { x : int; y : int}
kinners has quit ["leaving"]
Snark has joined #ocaml
<Snark> slt
* Snark likes to find good links in the topic when he joins a channel
bk_ has quit ["I'll be back"]
<Snark> no caml on www.cetus-links.org, or did I not search correctly?
<LordBrain> someone remind me.. what operator is string concatenation?
<mof> ^
<LordBrain> ok, thanks
<mof> IIRC, I'm a beginner too. :-)
<mof> (It seems to be correct however.)
<Snark> it is
Demitar has quit [Remote closed the connection]
Demitar has joined #ocaml
pattern has quit [Read error: 110 (Connection timed out)]
<mof> Why do I get the following when running ocaml interactively:
<mof> # Graphics.open_graph "640x480";;
<mof> Reference to undefined global `Graphics'
<Banana> yes.
<Banana> Graphics library is not linked by default.
<mof> Ah.
<Banana> it is not part of the standard library.
<Banana> ocamlmktop -o ocamlgraphics graphics.cma
<Banana> and use ocamlgraphics as you interractive toplevel instead of ocaml.
<mof> Oh, thanks.
wazze has joined #ocaml
Lemmi1 has joined #ocaml
karryall has joined #ocaml
Lemmih has quit [Read error: 110 (Connection timed out)]
<LordBrain> is there a difference between using "let a=3 and b=5 in" and using "let a=3 in let b=5 in" ?
yella has joined #ocaml
<karryall> LordBrain: evaluation order is unspecified in the first case
<LordBrain> ah i see, thanks
<mattam> also you can't use a in the definition of b in the first case
Lemmi1 is now known as Lemmih
<mattam> except with let rec a ...
<LordBrain> ok
<mof> Hm, why do I get the following when I try to open_graph "640x480" in the ocaml toplevel?
<mof> Exception: Graphics.Graphic_failure "Cannot open display 640x480".
<andrewb> You need a space preceding the geometry
<andrewb> see the examples in the manual
<mof> Oh! I missed that :-) Ty.
karryall has quit ["tcho"]
maihem has joined #ocaml
maihem has quit [Read error: 104 (Connection reset by peer)]
smimou has quit ["J'ai fini."]
<LordBrain> "This function uses the auxiliary function domain_of, which extracts the domain of a socket from its address." -- I'm looking at a book on ocaml with an example server, but i dont see the source to this domain_of function anywhere.. is that in a library somewhere?
<LordBrain> the page i'm looking at is here: http://caml.inria.fr/oreilly-book/html/book-ora187.html
maihem has joined #ocaml
<mattam> you should be able to write it with functions like gethostbyaddr
<LordBrain> hmm thanks
* LordBrain looks that up
mattam_ has joined #ocaml
<LordBrain> gah.i'm too much of a beginner to be messing around trying to learn sockets and ocaml at the same time to do this.
<LordBrain> Ok here is a question
<LordBrain> if i have a type such as this:
<LordBrain> type sockaddr = ADDR_UNIX of string | ADDR_INET of inet_addr * int
<LordBrain> and i have a variable of type sockaddr, called say socka...
<LordBrain> how do i peel off the structure to get the inet_addr?
<LordBrain> socka.inet_addr?
mattam has quit [Read error: 110 (Connection timed out)]
<gl> match socka with ADDR_INET(inet_address, n) -> blah(inet_address) ... | ADDR_UNIX str -> foo(str) ... | _ -> failwith "impossible"
<gl> use the pattern matching, luke.
<gl> socka.inet_addr is ok if socka is a type record, with a inet_addr field
<LordBrain> ah thankyou
<mof> Are tail-recursive functions generally slower than ordinary recursive functions?
<LordBrain> i am running into a snafoo in the interactive mode
<gl> no, they don't consume heap
<mof> So they should be faster?
<LordBrain> # let socka = Unix.ADDR_INET((Unix.inet_addr_of_string "10.0.0.2"),12345);;
<LordBrain> Reference to undefined global `Unix'
<LordBrain> how do i get it to know about Unix?
<gl> with big depth, yes, mof
<Smerdyakov> #load "unix.cma";;
<mof> LordBrain: ocamlmktop -o ocamlgraphics unix.cma :-)
<gl> LordBrain
<mof> That works as well?
<Smerdyakov> mof, sure does
<LordBrain> hmm it says unbound value load
<Smerdyakov> LordBrain, notice the # ?
<mof> Yah, I get that too. :/
<LordBrain> ooh
<mof> Oh.
<gl> <french>le toplevel est pas lie a Unix par defaut, faut compiler ton toplevel a la main</french>
<LordBrain> ah thankyou Smerdyakov
<Banana> didn't i say that earlier to someone ?
<gl> Banana to mof, with Graphics :)
<Banana> yeah right.
<mof> But you told me to use (reverse-i-search)`ocamlm': ocamlmktop -o ocamlgraphics graphics.cma
<mof> oops!
<Banana> who did learn as i see. good work :)
<mof> You told me to use ocamlmktop was what I meant. :-)
<mof> #load seems smoother.
<Banana> yes and no.
<mof> Why not?
<Banana> you have to remove the #load directives when you actually compile using ocamlc or ocamlopt.
<Banana> (or are they ignored ? i don't remember).
<mof> Heh, ok. It works fine for just testing and playing around in the interpreter though.
<Banana> that's true.
<LordBrain> does the # mean linker directive?
<Banana> it means interactive toplevel directive
<LordBrain> hmm
<LordBrain> linker directives would be cooler
<LordBrain> hehe
<Banana> there are other (#use "file.ml").
<LordBrain> ah
<LordBrain> that the same as (use File)?
<Banana> ?
<gl> bon pour les francais j'ai fait le chan #ocamlfr, histoire de pas polluer celui-ci avec du blabla latin incomprehensible
<gl> (cf. cette nuit :)
<Banana> ;)
<Banana> merci mon bon monsieur.
<Banana> sorry.
<Banana> LordBrain: #use "file.ml" sources "file.ml" (ala #include "file.h" in C).
<LordBrain> ah i see
mfurr has joined #ocaml
maihem has quit ["Client exiting"]
mfurr has quit ["Leaving"]
<LordBrain> How do i tell vim to use spaces for tabs?
<gl> "TA GUEULE !!!" :)
<LordBrain> oops wrong room
mattam_ is now known as mattam
Jaundice has joined #ocaml
<Snark> hmmmm...
<Snark> I have a defs.ml, a something_parser.mly ad a something_lexer.mll ; the two latest would need to "include" the first
<LordBrain> Here is a style question... I have a 2 line function which is only called from within another 2 line function and neednt be global, so i could include it in a let within the definition of the other function, but i think it might be more readable if i keep it separate. In your opinion(s), is it better to keep it separate or to embed it?
<det> God damn caml-list is active
<Banana> det: yeah you bet.
<Banana> stupid question about an "eval" function a la python.
<Banana> LordBrain: in term of performance, it's the same.
<Banana> (quite the same).
<LordBrain> well it seems like its a question of scope verses readability
<Banana> so nesting the function is cleaner.
<Riastradh> Use whichever one you prefer.
<Banana> but you can also hide it by a module signature so it's not a big problem to keep them separate.
<LordBrain> hmm readability is probably more important
det has quit ["Hey! Where'd my controlling terminal go?"]
<Snark> good night
Snark has left #ocaml []
det has joined #ocaml
malte has joined #ocaml
pattern has joined #ocaml
srv has quit [Read error: 104 (Connection reset by peer)]
srv has joined #ocaml
cjohnson has quit [Read error: 104 (Connection reset by peer)]
cjohnson has joined #ocaml
bk_ has joined #ocaml
LittleDan has joined #ocaml
<LittleDan> Why doesn't OCaml use equality types like SML?
<Riastradh> Equality types are a brusquely tacked-on-at-the-last-minute extension to the type system to half-assedly support operator overloading for equality comparison.
<LittleDan> but OCaml has runtime exceptions for type errors, isn't that worse?
<Riastradh> Run-time type errors?
<mattam> aren't type errors unspecified at runtime ?
<LittleDan> for being unable to check for equality, I think
<LittleDan> I'm probably mistaken
<LittleDan> as you could probably guess, I'm a beginner
<mattam> there is no type information at runtime, so type errors go uncatched until... not long :)
<mattam> what are equality types ?
<Riastradh> SML's hideousy for generic equality comparison.
<LittleDan> SML:
<LittleDan> fun f x y = (x = y)
<LittleDan> val f : ''a -> ''a -> bool
<LittleDan> Ocaml:
<LittleDan> let f x y = (x = y)
<LittleDan> val f : 'a -> 'a -> bool
<LittleDan> Does not have equality type variables - comparison allowed on all types but may raise Invalid_argument exception
<LittleDan> I prefer typeclasses for this sort of thing, but I can't find any strict functional language with typeclasses
<Riastradh> Implement 'em!
<LittleDan> You mean a language?
<Riastradh> No, I mean implement typeclasses in OCaml.
<LittleDan> You mean make something like Haskell's typeable?
<LittleDan> Or make explicit type constructors for everything, which can then be used to pattern match based on type?
<Riastradh> No, I mean implement typeclasses in OCaml.
<LittleDan> You mean modify the base system?
<Riastradh> Yes.
<LittleDan> But wouldn't that require completely redoing the type system>
<LittleDan> I think
<Riastradh> Why don't you try it and find out?
<mattam> :)
<LittleDan> Ocaml is implemented in C, right?
<Riastradh> The run-time system is implemented in C and the compilers are implemented in OCaml.
<LittleDan> I've tried to learn C so many times but I'm just terrible at low-level languages
<Riastradh> You'd be modifying OCaml code, not C.
<LittleDan> I'm trying to make my own language right now, which is why I'm learning OCaml
<LittleDan> but you need runtime type information for typeclasses, don't you?
<Riastradh> No. Type dispatch can be resolved at compile-time.
<LittleDan> You mean like in Java?
<Riastradh> ?
<LittleDan> Their generic functions
<LittleDan> functions for different types have different signatures
<Riastradh> I am unfamiliar witih Java's generic functions.
<Riastradh> With, even.
<LittleDan> they're really completely different functions
<LittleDan> pretty bad for generic type dispatch
<mattam> this is done at runtime in java
<LittleDan> really?
<LittleDan> How does it work, then?
<mattam> you mean specialization right ?
<mattam> like f(int) and f(double)
<LittleDan> yeah
<LittleDan> that's runtime?
<mattam> the method call is at runtime, and the decision may be dependant on the called values
<LittleDan> Why do that when you have static typing as inflexibly as Java has?
<LittleDan> why isn't it done at compiletime?
<mattam> wait a second, i may be mistaken
<Riastradh> Ask Java's designers.
<mattam> like if you have an object of A which has two subclasses B and C, and f(A), f(B) and f(C) are defined. I'm not sure
<LittleDan> that's different than f(int) and f(double), since int and double aren't classes, right?
<LittleDan> runtime class information is different than runtime type information (at least in Java)
<LittleDan> So how can type dispatch be resolved at compiletime, riastradh?
<LittleDan> unless you have a different function stored for each instance of the typeclass
<Riastradh> Uh, how do you expect to do it _without_ doing that?
<LittleDan> It's obvious how runtime typing systems work (since there are so many examples), but how would it work at compiletime? If it dispatches on the type, and the function can accept different types, how isn't that a runtime property?
<LittleDan> You can still have static typechecking even if there's runtime type information
<Riastradh> No, because all types are decidable at compile-time with OCaml's strict, static type system.
<LittleDan> no, the type information is only used internally
<Riastradh> ?
<LittleDan> to determine how to dispatch on the type
<Riastradh> ?
<LittleDan> maybe I have this whole conception of structured polymorphism wrong
Jaundice has quit ["Leaving"]
<Riastradh> Please form a complete sentence that explains the entirety of what you mean. 'To determine how to dispatch on the type' makes no sense to me.
reltuk has joined #ocaml
<LittleDan> I thought the function internally looked at the type of its argument and chose what to do based on that.
<reltuk> has there been any traffic on the news group in the last day? I don't think I subscribed, but I thought I did
<LittleDan> not much, just check google news
<LittleDan> or something similar
<Riastradh> No, LittleDan, because a) there's no run-time type information, and b) all types are decidable at compile-time, so there's no need to.
<reltuk> yeah, I didn't get anything in fa.list
<LittleDan> Riastradh: I know, but I'm wondering how structured polymorphism (which, I think, is like typeclasses) can be implemented without runtime type information
<LittleDan> You said it could
<LittleDan> I'm not talking about OCaml as it currently is
<LittleDan> because it doesn't have typeclasses
<Riastradh> All types are decidable at compile-time, so with that information, you perform the dispatch at compile-time.
<reltuk> even with typeclasses the type information is decidable at compile time, right?
<LittleDan> how do you do that when you have functions (in this theoretical OCaml hack) like
<LittleDan> (=) : Eq 'a => 'a -> 'a -> bool
<LittleDan> and this might be in a module where not all instances of Eq are knowable at compiletime
<LittleDan> reltuk: How? That's what I'm trying to ask
<reltuk> the module is distributed in source form
<reltuk> there's been research into distributing in binary form...just basically no one does it
<Riastradh> All you need to do is dump the type information as well as the code, reltuk.
<LittleDan> apt-get distributes OCaml modules in binary form
<LittleDan> that's type information after compiletime, isn't it?
<LittleDan> (oh, but modules have that, I forgot)
<Riastradh> No, because only the compiler uses it.
<reltuk> Riastradh: he's saying functions that had been compiled which use Eq wouldn't dispatch correctly
<reltuk> and he's right...it's like distributing STL in source form
<reltuk> let me see if I can't find that paper I read on distributing them in binary..
<LittleDan> So would something like that have a different function implemented for each instance of Eq?
<reltuk> a different compiled function, yes
<reltuk> it's the same in source form
<LittleDan> Doesn't that make excessively large binaries?
<reltuk> not really...it's only compiled for types that it's used with
<LittleDan> but what if it's in a module distributed in binary?
<LittleDan> Would it have to be in a bytecode?
<reltuk> it's the exact same size as if you had implemented the functionality seperately
<LittleDan> Is that how Haskell does it?
<reltuk> it could be in real-machine code or bytecode...don't see how it makes a difference
<LittleDan> byte-code might store some higher-level information about typeclasses
<reltuk> haskell distributes libraries in source form...
<reltuk> at least, standard libraries that come with the compiler
<LittleDan> if you did something like
<LittleDan> f : Eq 'a, 'b => 'a -> 'b -> unit
<LittleDan> then wouldn't the size of the executable increace exponentially by the number of types you use?
<reltuk> LittleDan: yes, but it's not more code than would be necessary to implement the functionality anyways...
<Riastradh> GHC dumps types and code to separate files.
<reltuk> if you need code in the program to compare two binary trees, you need it in...doesn't matter if it makes the code any bigger
<LittleDan> Oh, so if I wanted to implement typeclasses in OCaml, it could be as simple as a preprocessor? (what am I saying? that's not simple)
<LittleDan> but it's simpler
<reltuk> all I know is that the very smart people that implemented ghc said Haskell's type system was much much harder to get right than a basic Hinley-... (brain fart, what OCaml ahs)
<LittleDan> Miller
<mattam> i was mistaken, java simply does not dispatch on argument types at all: this http://authors.aspalliance.com/aylar/ViewPasteCode.aspx?PasteCodeID=2384 produces 'in f(A) num 0\nin f(A) num = 1'
<reltuk> yep, thanks
<LittleDan> so it's like an annoying implicit super all the time in Java?
<reltuk> java is annoying in general :-p
<LittleDan> At the high school I go to, they teach Java as a first programming language. I can't think of anything worse.
<reltuk> I can...at the college I go to, they do the same thing
<LittleDan> I mean I can't think of any language worse.
<reltuk> of course, the goal isn't to teach Java...but they use it to teach people the fundamentals of algorithms
<LittleDan> then why not use a functional language?
<reltuk> which is absolutely disgusting...they used to use scheme, which should have been much better for teaching algorithms in my opinion
<mattam> they do the same in my university, but the next year, we write a Java compiler in OCaml and are encouraged to criticize it to learn how to make good(c) languages.
<LittleDan> each student writes a full java compiler?
<mattam> that is done in binomials(?)
<reltuk> we never touch java again after first semester
<mattam> and only a subset of java (no packages, threads, interfaces, arrays (although i did arrays for fun :)))
<reltuk> and most people don't write their first compiler until junior or senior year
<LittleDan> you get to writing compilers as an undergrad?
<reltuk> actually, most people don't write a compiler at all
<reltuk> that class isn't a required undergrad class
<reltuk> LittleDan: you can always write whatever you want :-p
<LittleDan> I know, but the college has you take that class
<mattam> hey, you're 20 at this time, that's a good time to write a compiler
<reltuk> LittleDan: well, most colleges will have a person take a class on programming languages, theories and choices made in designing one, parsing, etc...
<reltuk> LittleDan: for the most part, these classes have you write interpreters for languages, not compilers...
<mattam> i'm not sure i was undergrad, is undergrad anything before a master ?
<reltuk> mattam: undergrad is when you're pursuing a BS
<mattam> BS ?
<reltuk> bachelor of science
<LittleDan> terrible acronym
<reltuk> lol