<KrispyKringle>
OK, second question: how do I use modules sfrom the standard library in the interactive command-line parser?
KrispyKringle has quit ["leaving"]
mrsolo_ has quit [Read error: 110 (Connection timed out)]
mrsolo_ has joined #ocaml
shawn_ has joined #ocaml
cjohnson has quit ["The main attraction: distraction"]
_fab has joined #ocaml
cjohnson has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
shawn has quit [Read error: 110 (Connection timed out)]
fab__ has quit [Read error: 110 (Connection timed out)]
dan2 has quit []
evariste has quit []
dan2 has joined #ocaml
dan2 has quit []
smkl_ has joined #ocaml
mlh has joined #ocaml
mlh_ has joined #ocaml
dan2 has joined #ocaml
dan2 has quit [Client Quit]
dan2 has joined #ocaml
shawn has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
shawn_ has quit [Read error: 110 (Connection timed out)]
KrispyKringle has joined #ocaml
<KrispyKringle>
So the line "let len = Unix.read fd str 0 stats.st_size in" is giving me, " Invalid_argument("Unix.read")". Anyone able to tell me what's up with that? I'd really appreciate the help. :)
smkl_ has joined #ocaml
<dan2>
KrispyKringle: str is a string buffer right?
<KrispyKringle>
dan2: oh, know what? it may be a string rather than a string buffer (they aren't the same, are they?).
<KrispyKringle>
hmm, Unix.read seems to expect a string, though...not a string buffer, unless im mistaken.
<KrispyKringle>
This expression has type Buffer.t but is here used with type string
swarm has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
_JusSx_ has joined #ocaml
vezenchio has joined #ocaml
KrispyKringle has quit ["leaving"]
mrsolo_ has quit [Read error: 113 (No route to host)]
mrsolo_ has joined #ocaml
smkl_ has joined #ocaml
mrsolo_ has quit [Read error: 104 (Connection reset by peer)]
mrsolo_ has joined #ocaml
shawn_ has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
shawn has quit [Read error: 110 (Connection timed out)]
stef_ has quit [Read error: 60 (Operation timed out)]
swarm has quit []
budjet has joined #ocaml
_JusSx_ has left #ocaml []
budjet has quit [Remote closed the connection]
gim has quit ["brb"]
smkl_ has joined #ocaml
vezenchio has quit ["haibane · renmei"]
vezenchio has joined #ocaml
mlh_ has quit [Client Quit]
mlh has quit [Client Quit]
swarm has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
smkl_ has joined #ocaml
swarm has quit []
_JusSx_ has joined #ocaml
<_JusSx_>
ok hi guys
<vincenz>
kris\\\
<vincenz>
hmm he left
<_JusSx_>
one year ago i found a guy here his name was wuruz, what happened to him?
smkl_ has quit [Read error: 238 (Connection timed out)]
<_JusSx_>
cjohnson: hi
<_JusSx_>
Smerdyakov:
<_JusSx_>
Smerdyakov: you re still here
<_JusSx_>
i can remember you are really nice
mrvn has joined #ocaml
smkl_ has joined #ocaml
mrvn_ has quit [Read error: 110 (Connection timed out)]
Herrchen has joined #ocaml
xqw has joined #ocaml
xqw has quit [Read error: 104 (Connection reset by peer)]
xqw has joined #ocaml
budjet has joined #ocaml
smkl_ has quit [Read error: 238 (Connection timed out)]
KrispyKringle has joined #ocaml
budjet has quit [Remote closed the connection]
KrispyKringle has quit [Read error: 60 (Operation timed out)]
jtiner has joined #ocaml
KrispyKringle has joined #ocaml
Herrchen has quit ["bye"]
smkl_ has joined #ocaml
budjet has joined #ocaml
smkl_ has quit ["..."]
budjet has quit [Remote closed the connection]
_JusSx_ has quit ["leaving"]
skylan has quit [Read error: 54 (Connection reset by peer)]
skylan has joined #ocaml
lodewijk has joined #ocaml
vezenchio has quit ["haibane · renmei"]
<KrispyKringle>
So I'm doing something like this: http://rafb.net/paste/results/ZPMA8q29.html as a bit of experimentation, and I get "Fatal error: exception Invalid_argument("Unix.read")
<KrispyKringle>
" when I run this.
<KrispyKringle>
Any help on why that may be? The types are themselves correct, it would seem...
<KrispyKringle>
Basically, I'm trying to read in a file, it's size, and it's mtime, or, if it doesn't exist, return the error message instead.
<lodewijk>
KrispyKringle: str is too small. Unix.read will read into the string, so try let str = String.create stats.st_size in (etc)
<Smerdyakov>
No runtime exception will ever have anything to do with a "type error." That's all resolved at compile time.
<KrispyKringle>
lodewijk: ah, thanks.
<KrispyKringle>
Smerdyakov: yeah, i'm aware of that. someone suggested to me last night that i should be using a string buffer rather than a string, so i was just sort of confirming in my head that i had this right.
<KrispyKringle>
:)
<KrispyKringle>
lodewijk: yep, you nailed it. I had a couple of other questions, though, if I may: 1) is there a way to access the fields in the stats record without opening Unix? and 2) Is it better to be using the Unix file access routines, or should I use Filename to open them as input_channels and read from them that way?
<Smerdyakov>
variable.Unix.st_whatever
<KrispyKringle>
(I really appreciate the help, by the way. thanks. )
<KrispyKringle>
Smerdyakov: ah, thanks.
<Smerdyakov>
You should at least be closing the files.
<KrispyKringle>
true. but what's the primary difference between the Unix module's file routines and the alternatives?
<lodewijk>
KrispyKringle: the alternatives are portable
<lodewijk>
KrispyKringle: I don't know if there's any difference in speed or whatever. I expect there isn't.
<KrispyKringle>
ok.
<Smerdyakov>
KrispyKringle, are using Unix stuff just so that you can use fstat instead of stat, so you know you get the information for the same file you've opened?
<KrispyKringle>
well, the Unix module claims to be somewhat portable to macos and windows, but im not so concerned about portability here (just fooling around, really, though portability is laways nice).
<Smerdyakov>
If you didn't use stat, it would make the most sense to use the stuff in Pervasives.
<KrispyKringle>
Smerdyakov: you mean so i can use it on the same file descriptor? yes. But mainly since the Unix routines are quite easey to understand, since they are analagous to other languages.
<KrispyKringle>
OK.
<Smerdyakov>
The Pervasives file stuff is easier, I'd say.
<KrispyKringle>
ok. I'll check it out. Thanks.
<Smerdyakov>
(Pervasives is the module that is opened by default, in case you didn't know.)
<KrispyKringle>
right.
<KrispyKringle>
I sorta got that. I'm a first-class newbie at OCaml, though, so... ;)
<KrispyKringle>
I wasn't able to find the exceptions that would be raised, though, for like permission denied versus the file not existing (akin to EACCESS, etc) in Pervasives. Am I looking in the wrong place (I probably am)?
<Smerdyakov>
I don't think that the OCaml authors would choose to require that every implementation be on a system where such errors would make sense.
<KrispyKringle>
Right, so I assumed. So how would I detect such errors (or rather, how would I differentiate between such errors when an exception is raised)?
<Smerdyakov>
I don't know. Try the different cases in the repl and see what happens.
<Smerdyakov>
There's no guarantee that it would be possible to tell the difference.
<lodewijk>
differentiating between such errors is system dependent, so you're back to Unix if you want that. I think.
<KrispyKringle>
ok, well, I suppose I may as well just stick with Unix. I'm only going to be running this on systems where such errors *do* make sense, so I suppose that's the practical choice.
<KrispyKringle>
Thanks again, guys.
<lodewijk>
I also stick to Unix, fwiw :)
<KrispyKringle>
makes me feel a bit more self-assured. I can be confident I'm not barking up completely the wrong tree ;)
<lodewijk>
KrispyKringle: don't take my word for it though, I'm a relative newbie as well :)
<KrispyKringle>
heh
<KrispyKringle>
that's ok.
<KrispyKringle>
I'm just sorta dicking around. When I took intro to programming back in the day, I learned in OCaml, but I never really did anything serious with it, so I figured what the heck, you know? ;)
<KrispyKringle>
didn't remember a single thing when I picked it up a few days ago, though. c'est la vie.
<Smerdyakov>
KrispyKringle, where did you take that class?
<KrispyKringle>
Smerdyakov: University of Pennsylvania.
<KrispyKringle>
Probably one of the few places OCaml was still used, though they don't use it any longer.
<Smerdyakov>
I bet it wasn't all that "back in the day," then. :)
<KrispyKringle>
Few years ;)
<Smerdyakov>
It would have to be after Pierce had been there for a while. :)
<KrispyKringle>
Pierce says they're considering moving back to OCaml.
<KrispyKringle>
It's been java for maybe two years now, I think.
<KrispyKringle>
Smerdyakov: you go/went to Penn?
<Smerdyakov>
No, but I know the PL people there a bit.
<KrispyKringle>
Ah.
<Smerdyakov>
And I know something about the history of ML and American universities. :)
<KrispyKringle>
Yeah, I'd be surprised to hear of OCaml being used in many other places.
<Smerdyakov>
SML is more common everywhere but France.
<KrispyKringle>
The AP classes taught in high schools push for Java (formerly C++).
<KrispyKringle>
I sorta liked having OCaml when I took it, to the extent that it leveled the field between those of us who knew C++ and those who didn't.
<Smerdyakov>
Yeah, but what kinda loser expects to learn anything in a high school class, anyway? :D
<KrispyKringle>
OTOH, I thought it was a complete waste of time and couldn't figure out where I'd ever use it :P
<lodewijk>
I find it's pretty usable for Real World Stuff(tm)
<KrispyKringle>
Smerdyakov: I was at a seminar for high school CS teachers by the ACM (JETT workshop, it was called) last summer, and a bunch of teachers asked me what I thought about the AP course I took when I was in high school, having gone on to computer science in college.
<KrispyKringle>
I was like, "Yeah, uh, it wasn't...wasn't really useful."
<KrispyKringle>
They were appalled.
<KrispyKringle>
lodewijk: right, looking back on it, I didn't know what the hell I was talking about. OCaml is far more versatile than many other languages.
<Smerdyakov>
KrispyKringle, are you a high school CS teacher?
<KrispyKringle>
Smerdyakov: no, I'm still in school.
<Smerdyakov>
KrispyKringle, undergrad at Penn?
<KrispyKringle>
yep
<KrispyKringle>
I was just helping to teach some of the high school teachers java.
<KrispyKringle>
oi, I tell ya...
<Smerdyakov>
What year are you?
<KrispyKringle>
junior.
<KrispyKringle>
Where are you, Smerdyakov ?
<KrispyKringle>
student?
<Smerdyakov>
2nd-year PhD, Berkeley
<KrispyKringle>
ah.
<KrispyKringle>
yeah, so i'm taking a class with pierce next semester, actually, which will either be in haskell or ocaml.
<KrispyKringle>
he's apparently undecided.
<lodewijk>
good luck if it's haskell :)
<KrispyKringle>
lodewijk: i've been sorta studying them both concurrently, as a distraction from studying (and now break).
<Smerdyakov>
KrispyKringle, considering grad school?
<lodewijk>
I never could appreciate all the monads or what I consider the mess that comes from combining them
<KrispyKringle>
haskell is interesting, but monads are a bit of a pain. and i have to say i find ocaml a bit more flexible.
<KrispyKringle>
lodewijk: right. the devotion to purity seems to simply make things less usable.
<KrispyKringle>
Smerdyakov: considered it, yes.
<KrispyKringle>
Smerdyakov: i've got an internship this summer with microsoft, so it's sorta like, see how that goes, see if i want to actually join the real world or not ;)
<Smerdyakov>
KrispyKringle, in Redmond?
<KrispyKringle>
yep
<Smerdyakov>
KrispyKringle, I'll probably be there, too, at MS Research.
<KrispyKringle>
really? slick.
<KrispyKringle>
language research?
<Smerdyakov>
Nothing official, but people in my research group usually get jobs there about this time in their careers. I'll be applying next week.
<lodewijk>
and to get Haskell code to run even mildly efficiently you have to be a guru. check out the threads on mailing lists where they discuss the results of language shootouts
<KrispyKringle>
Smerdyakov: congrats. that's the place to be, for sure.
<KrispyKringle>
lodewijk: i've seen that. I'm skeptical about the varacity of the Great Language Shootout (or whatever it's called), but there's no doubt that ocaml is far faster.
<Smerdyakov>
KrispyKringle, yup
<Smerdyakov>
There's also no doubt that MLton is far awesomer than OCaml. :D
<KrispyKringle>
otoh, I'm worried I'll slip into a C-ish programming style using ocaml, while haskell wouldn't let me.
<KrispyKringle>
Smerdyakov: standard ml versus ocaml, you mean?
<Riastradh>
Haskell would let you just as easily as OCaml, possibly even moreso with GHC.
<Smerdyakov>
KrispyKringle, MLton in particular. Without MLton, things wouldn't be as clear.
<KrispyKringle>
Riastradh: ah, it may be the documentation i was reading, then. It was quite focussed on functional purity.
<KrispyKringle>
but like I said, I found monads to be klunky (nevermindi that it took me a while to figure out what the hell they were ;)
<KrispyKringle>
Smerdyakov: i don't know anything about it.
<Smerdyakov>
KrispyKringle, it's the best open source compiler ever!! :D
<KrispyKringle>
Smerdyakov: how different from ocaml is standard ml?
<Smerdyakov>
KrispyKringle, not much
<Riastradh>
Monads are, from a purely theoretical standpoint, purely functional. Monads, however, simply form a general way to express sequential computation, which is the basis of the imperative paradigm.
<lodewijk>
Riastradh: yes, but when you get right down to it, when a monad tutorial says "see how clear it is!" I more of then than not think "not really".
<KrispyKringle>
hehe
<Smerdyakov>
lodewijk, s/of then/often
<lodewijk>
yes
<lodewijk>
I type too fast and I'm trying to track down a memory leak in a long running ocaml program here :)
<KrispyKringle>
Right, but they seem to be necessitated by the theoretical definition of a pure function and the lazy evaluation. Neither of these seem to benefit the praactical user that much.
<Riastradh>
Lazy evaluation has nothing to do with it.
<Riastradh>
Purity does, of course: monads are essentially a way to express impurity purely.
<KrispyKringle>
Riastradh: i thought that the requirement for specifying computation arises from lazy evaluation?
<KrispyKringle>
specifying order of, that is.
<Riastradh>
What makes you think that?
<KrispyKringle>
Er, I thought that I read that. If I'm wrong, you can just say so. I won't be offended. ;)
<KrispyKringle>
This is the point where, in real life, I'd mumble something about higher order functions, pretend my phone is ringing, and leave the room :P
<lodewijk>
damn. the memory leak comes from a piece of my C code and AFAICS it obeys all the rules from the manual
<KrispyKringle>
that's the problem with C code.
<lodewijk>
KrispyKringle: yes, but I need it here :)
<KrispyKringle>
why so?
<KrispyKringle>
out of curiosity, what are you working on that requires C?
<Riastradh>
C should have died in 1972 after a couple of dorks at AT&T had had enough fun with their toy called Unix.
<lodewijk>
a routing daemon for the local wireless municipal network
<lodewijk>
it works brilliantly, but after a week it will have used up all swap space on the smallest and busiest systems
<KrispyKringle>
hahaha
<KrispyKringle>
ouch
<lodewijk>
so now I've deployed a braindead crontab entry that restarts the thing once a week during the night, but I'd like to fix the problem instead :)
<KrispyKringle>
makes sense. what's it do, if i may ask, that other routing daemons don't?
<lodewijk>
but why it requires C is because of a lot of low-level FreeBSD interaction
<KrispyKringle>
ah
<KrispyKringle>
yeah, figures.
<lodewijk>
KrispyKringle: well, it works, for one. we tried quagga ospf but it kept locking the wireless cards, the code is big and buggy and the algorithm can't handle cycles that well. we have a lot of cycles in the network.
<lodewijk>
ospfd was 45k lines of C. this is 1200 lines of ocaml and 800 lines of C (including various license agreements in comments)
<KrispyKringle>
ah
<KrispyKringle>
sounds like a big improvement.
<lodewijk>
it is, except for this leak :)
<KrispyKringle>
the leak is in the C?
<KrispyKringle>
i mean, obviously...?
<lodewijk>
yes. well, not really obviously because the snippet that leaks seems to adhere to the rules specified in the manual
<KrispyKringle>
hmm.
<KrispyKringle>
can you run it in a tool like valgrind?
<KrispyKringle>
valgrind > god
<lodewijk>
hmm. I'll try, but the thing is that the code doesn't do any C allocations, it's using just the ocaml-provided allocators
<lodewijk>
all the malloc()s and free()s are in code that doesn't leak :)
<KrispyKringle>
oh.
<KrispyKringle>
well, you could certainl run the whole thing under valgrind, though i wouldn't expect the ocaml parts to leak.
<KrispyKringle>
and it might get pretty slow pretty fast.
<KrispyKringle>
in either case, i'm starving, so im gonna run off to grab some food. thanks for the help.
<lodewijk>
pff, this is bizarre. the leak goes away if I violate rule 1 from section 18.5.1 :|