<flux>
I was amazed how one of its first examples worked: #use "printf.ml";;
<flux>
but I'm not sure if that's giving the right idea about how to use use modules..
<flux>
it's good that 2.7 Scope has an example about rebinding.
<flux>
hmm, it calls the error referring to a non-existing value (Unbound value) a "runtime error"
<flux>
(2.11)
<flux>
although I'm unsure to what call if, if syntax errors are a class of their own, and those errors with syntax errors make "compiling errors" or some such
<flux>
it seems to give a good overview on things a newcomer to ocaml might do wrong :)
<adrien>
if-then-else, open as a way to _load_ modules, ... ?
<flux>
what about if-then-else?
<adrien>
if foo then do_this (); do_that ()
<flux>
where is that?
<adrien>
# if true then (); () else ();;
<adrien>
Error: Syntax error
<flux>
where are you picking that code from?
<adrien>
syntax error for the else because ocaml "ends" the "then" as early as it can
* adrien
has to afk for a few minutes
<flux>
in some pages the code isn't properly indented
Tobu has quit [Ping timeout: 272 seconds]
Tobu has joined #ocaml
eni has quit [Ping timeout: 260 seconds]
<flux>
heh, at least one python example has slipped in
<flux>
yeah, it seems the author has mixed #use with Open consistently, which leads me into thinking he must not be very familiar with OCaml :-o
<flux>
hmm, records are introduced after Arrays and Hashtbls..
<adrien>
or maybe he has developed his own style of ocaml ;p
<flux>
adrien, I wonder though how he would make use of the Str module with #use, perhaps he just has ocaml sources around :)
<flux>
then he talks about aggregate types, this is probably the first time I've heard sum types being called that. it's not a bad name for them, but probably quite rare?
<flux>
and the whole pdf doesn't really mention the module system at all
<flux>
but I suppose it's work in progress.
<flux>
so perhaps Hickey's Introduction to Objective Caml is still better
<pippijn>
mrvn: pity, I'm new to ocaml but none of that is new to me
<pippijn>
mrvn: at least the ocaml language one, I haven't seen the others, yet
Submarine has joined #ocaml
jamii has joined #ocaml
Submarine has quit [Read error: Connection reset by peer]
roha has quit [Ping timeout: 240 seconds]
rzys has quit [Ping timeout: 244 seconds]
ftrvxmtrx has quit [Read error: Connection reset by peer]
reynir has quit [Ping timeout: 246 seconds]
reynir has joined #ocaml
ftrvxmtrx has joined #ocaml
<flux>
pippijn, perhaps you aren't new enough :)
<pippijn>
I've used ocaml for 2 weeks or so
<flux>
oh :)
<pippijn>
(not 2 weeks ago, just 2 weeks and then I stopped because my semester started and it's super busy)
<flux>
maybe there should be a cheatsheet generator. you could pick which categories to have. I wouldn't have the oo stuff in 'level 1' cheatsheets, for example.
<pippijn>
(now I'm back doing java at work)
<reynir>
In the compiler class we wrote a compiler of a subset of java 1.1 in ocaml :)
<mrvn>
I like the local scope syntax: let rect = Sdlvideo.({ r_x = 0; r_y = 0; r_w = 512; r_h = 256; }) in
<pippijn>
but I find myself using "let open .. in" more often
<rly>
The OCaml compiler is much quicker than GHC, right?
<rly>
Is that because of proper engineering in the compiler or because the language is simpler or .... ?
<mrvn>
rly: it is far quicker to output a result
<mrvn>
because it doesn't optimize
<mrvn>
The type system is simpler too but that doesn't gain so much
<rly>
So, it's just tokenize, parse, basic compile.
<rly>
I recently tried some SML code and I was already like .... wow, this is fast.
<mrvn>
+type inference, and some simple optimisation
<Qrntz>
are there any pitfalls to creating a more heavily optimizing ocamlopt (except reduced compilation speed)? just wondering.
<rly>
Not the generated code, but the loading of code and when changing somec ode.
<mrvn>
if you want really fast then try go from google. The whole compiler builds in 10s.
<rly>
mrvn: and the same for changes?
<mrvn>
rly: 10s from pure source to finshed binary.
<mrvn>
Qrntz: you always have to be carefull that you don't optimize in bugs.
<rly>
mrvn: but Go doesn't have any fancy types.
<mrvn>
Qrntz: as recently discussed some major shortfalls of the compiler are that it doesn't inline closure arguments and it doesn't reduce polymorphic types to the actual types when inlineing. Those two could give a fair bit of speedup.
<rly>
AFAIK, it ignores everything that has happened in the past 20 years.
<Qrntz>
mrvn, interesting…
<mrvn>
Qrntz: go write patch and become famous. :)
ftrvxmtrx has joined #ocaml
<Qrntz>
mrvn, heh, wish I knew the internals that well.
<Qrntz>
I've been interested in how ocamlopt generates code since the very moment I started ocaml, though
<mrvn>
Qrntz: then be happy it is kept simple. Makes it much easier to understand.
<rly>
Is OCaml written in OCaml? If so, can it be bootstrapped? If so, how?
<Qrntz>
mrvn, indeed.
<mrvn>
rly: ocaml + c. And the source seems to be self contained.
<adrien>
rly: the ocaml compiler doesn't try to gain 1% of speed
<adrien>
if there is something with a notable gain, it can go in
<adrien>
but less than 5% and only in some specific benchmark at the cost of complexity in the compiler? that usually doesn't get in
<rly>
adrien: by 'the compiler' you mean the native code compiler which doesn't do fancy optimizations?
<adrien>
I mean "ocamlopt"
<adrien>
"ocamlc" does a bit less than "ocamlopt"
<rly>
Does it even optimize (map f . map g) l to (map (f.g) l)?
<mrvn>
Some optimization could be done for both byte and native code
<adrien>
(but mostly because it skips things not appropriate for bytecode)
<adrien>
rly: no
<mrvn>
rly: how could it?
<adrien>
rly: it's only possible if f is pure
<adrien>
and it can't know that
<mrvn>
it would also need internal knowledge of map or have to vectorize it
<rly>
adrien: if f and g are in code which it has access to, it could.
<mrvn>
rly: f and g aren't even inlined
<adrien>
but to be honest, I prefer a dumb compiler that really does what I is written, it predictable
<adrien>
rly: it doesn't know such things
<rly>
adrien: yes, I think a good case could be made for that.
<rly>
adrien: smart compilers are nice when you don't have to wait for them.
<mrvn>
adrien: I always wanted to write a C compiler like that.
<adrien>
if it knew that, it could eliminate some dead code in modules, which would be really the nicest benefit I think
<rly>
What I don't get it why OCaml code is so fast then.
<rly>
Are the others doing it so wrong then?
<mrvn>
rly: because 1) it is really hard to write code that doesn't stall the cpu pipeline and dumb code just fills the gaps better, 2) ocaml source code is efficient, 3) optimizing just works really hard to get those last 5% speed.
<adrien>
probably, the first thing is that it's simple; then it's quite pragmatic
<mrvn>
rly: Where you get problems is with small loops or heavy arithmetic code.
<mrvn>
rly: things where unrolling and reordering has huge gains.
<mrvn>
rly: also common subexpression elimination gains you a lot but people tend to do that manualy in ocaml.
<mrvn>
as in let x = 3 * y + z in foo x; bar x; baz x
<adrien>
that one depends
<adrien>
in some cases, it's a loss
<adrien>
and it'll depend on the machine quite a lot
avsm has joined #ocaml
<mrvn>
adrien: computing x 3 times is never faster
<rly>
Is there a way to get rid of the let a = 3;; let b = 4;; stuff and just write a=3; b=4 or something similar?
<mrvn>
rly: no. a=3 is a comparison
<adrien>
mrvn: in some cases, I've done that manually and that was slower
<adrien>
and XL was mentionning that too
<rly>
Does camlp integrate with the error messages?
<mrvn>
adrien: I would call that a compiler bug then
<rly>
So, let's say one writes a different surface syntax on top of OCaml, does it properly create error messages then for the new surface syntax?
<mrvn>
rly: since you mention camlp. With camlp you can do pretty much anything.
<mrvn>
rly: iirc someone wrote a shell grammar for camlp so you could compile your shell scripts as ocaml code.
<rly>
And naturally, it also depends on how fast camlp executes, because one wouldn't want to get lots of slower compiles again.
<rly>
mrvn: heh, I thought of that too once.
<rly>
mrvn: cool that someone did.
<adrien>
mrvn: might be different from what I saw but I quite clearly remember XL stating expression folding could be slower too
thizanne has quit [Remote host closed the connection]
<adrien>
mrvn: was the shell thing cash or something else? I'd be quite interested in that actually
<mrvn>
adrien: I found that years ago. no idea anymore
<adrien>
ok, I'll try to find it
eni has joined #ocaml
Juzor1 has left #ocaml []
avsm has quit [Quit: Leaving.]
bnwr has quit [Quit: Changing server]
Fabio has joined #ocaml
emmanuelux has joined #ocaml
bnwr has joined #ocaml
ftrvxmtrx has quit [Ping timeout: 246 seconds]
ygrek has joined #ocaml
Zedrikov has quit [Ping timeout: 260 seconds]
eni is now known as albacker
albacker has quit [Changing host]
albacker has joined #ocaml
smerz has joined #ocaml
avsm has joined #ocaml
jamii has joined #ocaml
ikaros has joined #ocaml
iago has joined #ocaml
avsm1 has joined #ocaml
avsm has quit [Read error: Connection reset by peer]
ftrvxmtrx has joined #ocaml
avsm1 has quit [Quit: Leaving.]
sanders___ has joined #ocaml
NougatRillettes has joined #ocaml
iago has quit [Quit: Leaving]
IbnFirnas has joined #ocaml
reynir has quit [Ping timeout: 244 seconds]
hefner has quit [Quit: now you have two problems.]
tufisi has quit [Read error: Connection reset by peer]
tufisi has joined #ocaml
Submarine has joined #ocaml
Submarine has quit [Changing host]
Submarine has joined #ocaml
roha has joined #ocaml
rzys has joined #ocaml
reynir has joined #ocaml
reynir has quit [Ping timeout: 260 seconds]
reynir has joined #ocaml
iZsh has quit [Quit: Coyote finally caught me]
avsm has joined #ocaml
letrec has quit [Ping timeout: 248 seconds]
Tobu has quit [Ping timeout: 260 seconds]
bitbckt has quit [Ping timeout: 245 seconds]
bitbckt has joined #ocaml
dgfitch has quit [Remote host closed the connection]
Tobu has joined #ocaml
Tobu has quit [Changing host]
Tobu has joined #ocaml
The_third_bug has joined #ocaml
ftrvxmtrx_ has joined #ocaml
The_third_bug has quit [Ping timeout: 265 seconds]
<adrien>
pippijn: it uses libev, it integrates with glib's loop and lablgtk, and it does some more
<pippijn>
oh
<pippijn>
it uses libev? really?
<adrien>
and if you have stuff that would typically be blocking (I/O), it'll help
<adrien>
yes
<adrien>
libev or select
<pippijn>
ok
<adrien>
chosen at compile-time
<pippijn>
lwt doesn't have a lot of examples, it seems
<Qrntz>
the biggest one is probably ocsigen :-)
<mrvn>
reynir: most of that art truely sucks and the search interface is totaly unusable.
<adrien>
the search interface is bad but you can end up "getting" it
<adrien>
and browsing by tags works quite well
Smerdyakov has joined #ocaml
Smerdyakov is now known as adamc
Submarine has quit [Quit: Leaving]
adamc has left #ocaml []
rzys has quit [Ping timeout: 260 seconds]
roha has quit [Ping timeout: 260 seconds]
sanders___ has quit [Ping timeout: 264 seconds]
reynir has quit [Quit: Reconnecting]
reynir has joined #ocaml
BiDOrD_ has joined #ocaml
<flux>
pippijn, don't use that, it's broken, should say on the front page :). I should put that in bold..
<pippijn>
ocaml-ev?
<flux>
that
<flux>
I still don't understand what's the problem
<pippijn>
ok
<pippijn>
oh
sanders___ has joined #ocaml
<pippijn>
ok, well, I'm trying lwt now
<pippijn>
I'm still confused as to how it's supposed to be used for sequential code
BiDOrD has quit [Ping timeout: 245 seconds]
<flux>
it is a bit confusing, yes. but if you're talking about system calls, basically you write it like: instead of let a = Unix.read blahblah it is Lwt_unix.read blahblah >>= fun a -> ..
<pippijn>
I want to open a socket and resolve a hostname, then connect to the resolved host and set the socket to non-blocking
<flux>
if you use Lwt functions for that, they are probably nonblocking automatically
<adrien>
if you have some chunk of code that will run while nothing else is running, do not try to use lwt there
<pippijn>
adrien: I don't know that.. I want to write a client library much more than a client
<pippijn>
I don't know if someone will use it to create many clients in one process
<pippijn>
so I think it should be non-blocking
<adrien>
I don't know Lwt_log but basically, use the thread stuffs when you actually have several things that are running at the same time and some operations might be blocking
<pippijn>
at least for resolving
<pippijn>
and connecting, of course
<flux>
does Lwt come with non-blocking resolver?
<adrien>
do you need interactivity while it's resolving?
<pippijn>
me, I don't need that, no
<adrien>
if it makes no sense to do something else while it's resolving, don't overengineer
<pippijn>
ok
<pippijn>
Lwt_log.log returns a thread
<flux>
you're supposed to sequence your code with the Lwt binding operator >>=
<pippijn>
ok
<flux>
(or use the syntax extensions to provide you with a bit more nicer syntax)
<pippijn>
that's ugly for the log code
<flux>
well, you can also push stuff to run on the main loop without that sequencing
<flux>
I don't remember the function, but its type is probably 'a Lwt.t -> unit
<albacker>
what kind of questions on functional and Ocaml programming would you think about to ask in an interview?
<zorun>
albacker: is that used in the real world?
<zorun>
:)
<zorun>
it mostly depends on your public, I guess
sgnb` has joined #ocaml
<zorun>
is it a lecture?
<albacker>
internship interview
<mrvn>
albacker: something about modules, functors, variant types and records, objects and tail recursion
<zorun>
oh, at Jane's Street?
<albacker>
zorun, everywhere
<albacker>
mrvn, what about functional programming in general?
datkin has quit [Ping timeout: 246 seconds]
<mrvn>
albacker: that too
sgnb` has quit [Remote host closed the connection]
tlockney_ has joined #ocaml
<mrvn>
for an internship you shouldn't need to know a lot. It is not like you wan't earn ocaml quickly if you have some basic knowledge in programming and functional languages.
sgnb` has joined #ocaml
<mrvn>
s/wan't/can't/
<mrvn>
s/earn/learn/
adrien_ has joined #ocaml
hcarty_ has joined #ocaml
<albacker>
:)
<albacker>
you are right
ygrek has quit [Quit: Leaving]
<albacker>
zorun, what about at jane's street, what kind of questions do they ask?
ikaros has quit [*.net *.split]
emmanuelux has quit [*.net *.split]
Snark has quit [*.net *.split]
sgnb has quit [*.net *.split]
hcarty has quit [*.net *.split]
yroeht has quit [*.net *.split]
tlockney has quit [*.net *.split]
adrien has quit [*.net *.split]
ikaros has joined #ocaml
yroeht has joined #ocaml
Snark has joined #ocaml
emmanuelux has joined #ocaml
<zorun>
albacker: I honestly don't know
<albacker>
ah, since you asked I thought you had an idea.
Snark has quit [Client Quit]
datkin has joined #ocaml
struktured has quit [Remote host closed the connection]
struktured has joined #ocaml
struktured has quit [Remote host closed the connection]
<mrvn>
anyone using sdl? I can't Sdlvideo.blit a surface without loosing the alpha channel.
<Anarchos>
Who does know a C/C++ parser targeting Ocaml as the abstract target language ?
<Anarchos>
I must admit i tried Elsa/Olmar but i am unable to compile it without some hacks, and the first test fails when i tried it
tufisi has quit [Ping timeout: 260 seconds]
<pippijn>
ok, I think I found a good way
<pippijn>
it will be like a fold over the infinite list of network packets
<rly>
zaltekk: foo n m f = sum (map f (enumFrom n m))
<rly>
zaltekk: that seems a lot better.
<rly>
Fill in obvious definitions for enumFrom if you like.
krktz has quit [Remote host closed the connection]
krktz has joined #ocaml
adrien_ is now known as adrien
Tobu has quit [Ping timeout: 272 seconds]
reynir has quit [Ping timeout: 244 seconds]
iZsh has joined #ocaml
reynir has joined #ocaml
Tobu has joined #ocaml
rzys has quit [Ping timeout: 260 seconds]
roha has quit [Ping timeout: 265 seconds]
Smerdyakov has joined #ocaml
deelazy has joined #ocaml
deelazy has quit [Client Quit]
deelazy has joined #ocaml
deelazy has quit [Client Quit]
deelazy has joined #ocaml
deelazy has quit [Client Quit]
Juzor has joined #ocaml
roha has joined #ocaml
rzys has joined #ocaml
datkin has quit [Read error: Connection reset by peer]
Anarchos has quit [Quit: noz mad ganeoc'h]
sanders___ has quit [Quit: Leaving]
<pippijn>
can I tell Unix.read to write into a string starting at a certain position?
<mrvn>
it already does that
<pippijn>
one that is not position 0
<mrvn>
read fd buff ofs len reads len characters from descriptor fd, storing them in string buff, starting at position ofs in string buff. Return the number of characters actually read.
Fabio has quit [Quit: Leaving]
<pippijn>
oh
<pippijn>
strange.. I get Invalid_argument if I have ofs <> 0
<pippijn>
oh I know
<adrien>
:-)
<pippijn>
mrvn: thanks
<albacker>
why would you use variant types ?
<albacker>
and i'm not talking about type = ... but about the `foo (type definition on the fly).. it's also the first time i see this.
jamii has quit [Ping timeout: 246 seconds]
<mrvn>
albacker: That's a hash variant type.
<albacker>
mrvn, why is that useful, can you give me an example?
<mrvn>
They allow sub and supertypes.
<adrien>
no need to define them, and some kind of inheritance for instance
<adrien>
lablgtk shows how they can help
<mrvn>
let f = function `Foo -> "Foo" | `Bar -> "Bar" | _ -> "<unknown>";;
<mrvn>
val f : [> `Bar | `Foo ] -> string = <fun>
<mrvn>
# f `Blub;;
<mrvn>
- : string = "<unknown>"
<adrien>
for instance, it uses `FOO in the OCaml interface when the GTK+ API uses "FOO" (the _string_, so with no type checking)
<adrien>
or does it use enums in the GTK+ API?
<adrien>
and, unlike non-polymorphic variants, you don't have to type Gtk.Bar.Baz.FOO (the full path) to use them
<adrien>
night
<mrvn>
One nice thing with hash variants is that they don't collidetype foo = [ `Foo ]
<mrvn>
type bar = [ `Bar | `Foo ]
<albacker>
so the advantage is that you don't need to define them?
<mrvn>
Makes it easier to define functions that use the same flags but different subsets.
larhat has joined #ocaml
<mrvn>
albacker: that too
<mrvn>
But the main thing is that you have types [< bar ] a subset of bar, [ bar ] exactly bar and [> bar ] a superset of bar.
Tobu_ has joined #ocaml
Tobu has quit [Ping timeout: 260 seconds]
larhat has quit [Read error: Connection reset by peer]