<krumms>
Hi all ... can anybody help me understand the unit operator: () ?
<krumms>
sometimes it seems to be used as a NOP
<psnively>
unit is a type; () is its only value.
<psnively>
It's essentially analogous to the void type in C/C++/Java/C#...
<krumms>
psnively: cheers. Why do you sometimes see it as a parameter to functions then? Stylistic thing?
<krumms>
e.g. let main () = ... ;;
<xavierbot>
Characters 0-1:
<xavierbot>
e.g. let main () = ... ;;
<xavierbot>
^
<xavierbot>
Unbound value e
<psnively>
No; any function must be applied to at least one argument. So if your function wants no arguments, you apply it to ().
<krumms>
Ah, I see
<krumms>
thanks very much, huge help :)
<psnively>
So that means "main takes one argument, which must be the of type unit."
<psnively>
Sure thing!
<krumms>
psnively: one last question - is it "correct" to use it as a NOP in something like the following:
<psnively>
Actually, it means something a bit weirder: main takes one argument, which must be the one value of type unit.
<krumms>
if !Sys.interactive then () else print_endline "Hello!" ;;
<xavierbot>
Characters 5-8:
<xavierbot>
Parse error: [binding] expected after [opt_rec] (in [str_item])
<xavierbot>
if !Sys.interactive then () else print_endline "Hello!" ;;
<xavierbot>
^^^
<krumms>
psnively: sure, understood
<psnively>
if/then is kind of an interesting case too: the expressions of the "then" and "else" cases must be of the same type.
<psnively>
Here, the code is saying: if we're interactive, print_endline "Hello!"
<psnively>
What is the type of that expression?
<psnively>
print_endline "Hello!";;
<xavierbot>
Characters 5-8:
<xavierbot>
print_endline "Hello!";;
<xavierbot>
^^^
<xavierbot>
Unbound constructor Sys
<psnively>
Sys.print_endline "Hello!";;
<xavierbot>
Characters 1-18:
<xavierbot>
Sys.print_endline "Hello!";;
<xavierbot>
^^^^^^^^^^^^^^^^^
<xavierbot>
Unbound value Sys.print_endline
<krumms>
xavierbot's not happy :)
<psnively>
OK, whatever. trust me, the type of print_endline "Hello!" is unit. :-)
<krumms>
I think it evaluates to unit
<krumms>
yeah :)
<psnively>
Yep.
<psnively>
So since "then" and "else" must match, what do you use in the other one when one is unit?
<krumms>
so if it were to return a string, then I'd have to pass back "" if I wanted a NOP ... bad example, i know
<psnively>
Of course, that code is confusing: you could rewrite it as if Sys.interactive then print_endline "Hello!"
<psnively>
But you're right: the types must match.
<krumms>
another expression that evaluates to the type unit
<krumms>
yeah
<psnively>
Incidentally, when "else" is omitted, it defaults to type unit.
<psnively>
Yep. And there's only one value of type unit: ()
<krumms>
! is the dereference operator, right? Isn't Sys.interactive a bool reference?
<psnively>
So when you need an expression of type unit that has no side-effects, that's it.
<krumms>
Sure, I see
<psnively>
Oh, right, sorry. I was thinking negation. Bad Paul. No biscuit.
<krumms>
psnively: don't worry, I'm struggling to get my head around stuff like that too :)
<krumms>
too much C/Java *sniffle*
<krumms>
but yeah, I'm trying to get this write. Writing little tutorials as I learn Ocaml.
<krumms>
get this *right
<krumms>
*shakes head*
<psnively>
Very good.
<psnively>
I'd still rewrite that as: if not !Sys.interactive then print_endline "Hello!";;
<xavierbot>
Characters 5-10:
<xavierbot>
Parse error: currified constructor
<xavierbot>
I'd still rewrite that as: if not !Sys.interactive then print_endline "Hello!";;
<xavierbot>
^^^^^
<krumms>
sure, I might do that
<krumms>
save me trying to explain unit just yet ...
<psnively>
Yeah, hmmm. I'm not sure which is clearer.
<psnively>
Exactly.
<psnively>
I dislike having "else" when there really is no "else" case.
<krumms>
Totally agree
<krumms>
I'm picking this stuff up as I go along :)
<psnively>
I certainly don't know a better way. :-)
<krumms>
You wouldn't happen to know _why_ Sys.interactive has a bool ref type rather than a bool, would you?
<psnively>
I would guess so that a process could essentially "detach" itself from the console after being forked.
<psnively>
Kind of go in and out of "server mode," if you will.
<krumms>
Not sure I follow you, but okay :)
<psnively>
Not surprising; I'm not sure I'm making any sense. :-)
<krumms>
lol either am I. I'm trying to make this tutorial accessible, but it's quite hard to talk in simple terms when the subject matter gets hairy so quickly.
<psnively>
I would just point out that all expressions in OCaml return values, and all values have types, so if/then/else is a bit finicky because the then and else branches have to be of the same type.
<psnively>
Then you can point out that, when it's missing, "else" has type "unit." You can either have already talked about unit, or you can defer talking about unit.
<krumms>
ocaml-tutorial.org only got me so far ... things like declaring the type signatures for lists of tuples were semi-alluded to in the tutorial. I guess it's hard knowing what's "too much" and what's going to be genuinely helpful.
<krumms>
I think I'm going to defer talking about unit until the next tutorial ... need to mess with it all a little I think :)
<psnively>
Yes. I think worked examples are best.
<psnively>
Unfortunately, unit comes up almost immediately, because if/then/else comes up almost immediately.
<psnively>
But honestly, I still see stuff in OCaml that makes me go "hruh?" Scooby-Do style roughly once a week. So don't listen to me.
<krumms>
lol ... how long have you been working with Ocaml?
<psnively>
Off and on, mostly off, for about, oh, four years now.
<psnively>
But I haven't really hunkered down and said: I'm gonna get fluent... until, oh, hmmm... six months ago or so.
<psnively>
When I first started on it, my home machine was a Macintosh IIfx and OCaml hadn't been ported to it. I found OCaml, actually, via the Ensemble project, which, at the time, was still in Ken Birman's group at Cornell. I had first encountered Birman's work on Horus, Ensemble's predecessor, while looking into distributed databases at Apple.
buluc1 has joined #ocaml
<psnively>
So this business of a reliable process group communication system intrigued me, and the observations that they made about correctness, etc. in OCaml that much more so.
<psnively>
I'd paid some attention to the ML family, from a distance, for many years. I found the syntax quite ugly. But now I felt like I really needed to understand what the benefits were.
<psnively>
Coming mostly from a Lisp/Smalltalk background academically, and, of course, a Pascal/C/assembly background professionally.
<krumms>
Ah, right. Sounds like you've been working on much more interesting stuff than I :)
<psnively>
I dunno. I have a formal CS background, yes, and I guess the same desire to understand the Big Picture™ that impelled me to study CS and Physics drives me to learn some pretty fringe stuff.
<krumms>
Yeah I found Ocaml's syntax ugly when I first stumbled across it all. It kinda grows on you though.
<psnively>
I agree. Now I don't see it as ugly at all, but I guess some people really prefer the revised syntax. As a Lisper, I like the fact that we have camlp4 and even have two "competing" syntaxes...
<psnively>
Lispers are always going on about macros, and here we are with a language that ships with two different surface syntaxes. :-)
<krumms>
haha :) Lisp (and Scheme) is a language I'd love to look into a little more one day
<psnively>
Scheme is an underappreciated gem, IMHO. Common Lisp is an amazing political feat.
<psnively>
All of which just underscores that Guy Steele is a genius of the first rank.
<krumms>
:) First I've heard of him, but yeah - at a glance, it looks like he's done more than his fair share for the CLISP and Scheme world
<psnively>
And before that, C. And after that, Java.
<psnively>
I think Guy has had his fingers in more language designs than any other human being.
<psnively>
He's the Steele in "Harbison and Steele C," a popular pre-ANSI dialect.
<psnively>
And he co-authored various design aspects of Java.
buluca has quit [Nick collision from services.]
buluc1 is now known as buluca
<krumms>
Wow ... yeah, he has been busy
<psnively>
But no doubt, he's most famous for shepherding the standardization of Common Lisp, and co-inventing Scheme.
<krumms>
I missed out on a formal CS education ... instead had to push myself through a watered down generic "IT" degree. It's all the universities here offered. I'm moving soon, so that may change. :)
<krumms>
All of the fun stuff has since kinda been self-taught. Which is probably why I still don't understand Haskell monads ... ;)
<psnively>
To my growing embarrassment bordering on shame, I flunked out of one of the best CS schools in America.
<psnively>
There are people with CS Ph.D.'s who don't understand monads.
<mbishop>
heh, I'm willing to bet most of them don't
<psnively>
Word.
<mbishop>
CS PhDs are given out in those little $.25 machines in front of Kmart now a days
<psnively>
Really? I'd heard the CS program at most schools was dying.
<psnively>
In any case, read anything by Steele you can, but better yet, listen to him.
<mbishop>
dying most likely, but that doesn't mean they still don't zoom past some Java book and hand them a degree
<krumms>
I'm in Australia. Here in Brisbane, most programmers seem to have "generic" IT degrees. I've seen Comp Sci degrees pop up here and there recently though.
<psnively>
I'm a Hoosier; IU is the school I flunked out of. But not before getting to hang out and talk with Dan Friedman, Douglas Hofstadter...
<psnively>
Ah, an Aussie! I know there are some excellent CS programs in Oz.
<krumms>
Yeah. Probably somewhere other than Brisbane :)
<mbishop>
Haha, is Douglas Hofstadter as weird as his books? :P
<krumms>
Sydney, Melbourne
<krumms>
I'm moving to Melbourne at the end of this month
<krumms>
But if I do another degree, it'll be a math degree.
<mbishop>
I don't even want a degree in CS, or even CE, I'd prefer history or something
<psnively>
Most of the really good stuff I've heard of is out of Adelaide, now that you mention int.
<mbishop>
I love programming and all, but I don't want to do it as my job all day heh
<Smerdyakov>
mbishop, CS PhDs from K-Mart? Not PhDs from programs with reputations, and everyone know the difference.
<krumms>
cheers
<mbishop>
True, you can typically tell the "good" schools
<Smerdyakov>
mbishop, you don't even need to look at schools. Publication record is what matters.
<mbishop>
That's true, too
<psnively>
Smerdyakov here is one of the best, at one of the best schools, not coincidentally.
<mbishop>
UCB, right?
<psnively>
Yes.
* mbishop
nods
<mbishop>
UCB is still using SICP in a course, aren't they? Sad that MIT isn't :(
<psnively>
Actually, I believe MIT is. It just isn't required, IIRC.
<mbishop>
Well, I think they still use SICP for some courses, but I was talking about 6.001
piggybox has quit [Nick collision from services.]
another has joined #ocaml
<psnively>
Yeah. OTOH, what matters is the concepts, not SICP or Scheme, necessarily.
pantsd has joined #ocaml
<mbishop>
true
<mbishop>
Not like I'll ever get into MIT or UCB anyway :P
<psnively>
Me neither, but that doesn't mean we shouldn't pay attention to academic standards of excellence. Not, mind you, that I think you're making any such argument. :-)
<psnively>
I wanted to go to MIT in the worst way, as a teen. I was pretty delusional.
visage has joined #ocaml
<Mr_Awesome>
anyone know of a way to have number-parameterized types in ocaml?
<psnively>
Yes. It's not for the faint of heart.
visage has quit []
<Mr_Awesome>
does it involve those dastardly peano numerals?
<Smerdyakov>
Hey, psnively; why aren't you authenticated to services?
<psnively>
Sorry?
<Smerdyakov>
/msg nickserv help
<psnively>
Ah, right. Need to do that.
<psnively>
Right now, however, dinnertime. Later!
psnively has quit []
another is now known as piggybox
pantsd has quit [Read error: 110 (Connection timed out)]
joshcryer has quit [Read error: 113 (No route to host)]
G has joined #ocaml
joshcryer has joined #ocaml
ygrek__ has quit [Excess Flood]
G_ has quit [Read error: 110 (Connection timed out)]
<krumms>
is there a name for ()? "the unit value"?
joshcryer has quit [Read error: 104 (Connection reset by peer)]
<Smerdyakov>
In the right crowd, everyone will know what you mean by "unit-introduction."
<krumms>
Smerdyakov - what about amongst newbs coming from C++/Java? :)
<Smerdyakov>
Obviously none of them will have any terminology in mind for ML.
<krumms>
'The parentheses <em>()</em> represent what is known as the "unit-introduction". It is the only possible value for the <em>unit</em> type, and has a similar use and meaning to what <em>void</em> has in C/C++. In this case'
<krumms>
^ is that a fair enough statement?
<Smerdyakov>
You generally don't want to use "unit-introduction," though. "The unit value" should also be OK.
<krumms>
sure, thanks
joshcryer has joined #ocaml
<krumms>
and what would one call the ";" and ";;" operators? Hmm. This is probably all in the manual, right?
slipstream has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
slipstream-- has quit [Read error: 110 (Connection timed out)]
noteventime has quit [Remote closed the connection]
noteventime has joined #ocaml
buluca has left #ocaml []
buluca has joined #ocaml
buluca has quit [Client Quit]
piggybox has joined #ocaml
robyonrails has joined #ocaml
clop2 has joined #ocaml
<clop2>
hi, im having trouble building ocaml, the "make world" command fails with Fatal error: exception Failure("input_value: bad object"); any idea how to debug?
<rwmjones>
that error indicates that a .cmo/.cmi (or similar) file is out of step with the current version of OCaml. I would try doing "make clean"
<clop2>
ah nice, that seems to have gotten me further. now it dies with File "camlp4/boot/Camlp4.ml", line 458, characters 17-18:
<clop2>
Illegal character (\000)
<rwmjones>
ouch ... what are you trying to build this on?
marc has quit [Read error: 110 (Connection timed out)]
screwt8 has quit [Read error: 104 (Connection reset by peer)]
<clop2>
a linux64 system. i think the sysadmins may have screwed it up royally though; i should probably wait until later to retry this
pango has quit [Remote closed the connection]
pango has joined #ocaml
love-pingoo has joined #ocaml
xavierbot has quit [Remote closed the connection]
xavierbot has joined #ocaml
ed-t8 has quit [Read error: 110 (Connection timed out)]
oxylin has joined #ocaml
rwmjones_ has joined #ocaml
oxylin has quit [Connection reset by peer]
pantsd has quit ["Leaving."]
smimou has joined #ocaml
robyonrails has quit ["me ne vo'"]
Lena has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
Lena has quit ["Leaving."]
leo037 has joined #ocaml
mnemonic has quit ["leaving"]
bluestorm_ has joined #ocaml
mnemonic has joined #ocaml
rwmjones_ has quit ["This computer has gone to sleep"]
screwt8 has joined #ocaml
pantsd has joined #ocaml
piggybox has quit [Connection timed out]
setog3 has joined #ocaml
<setog3>
hi
<setog3>
vim user here ?
zarvok has joined #ocaml
<setog3>
emacs user ?
<pango>
yup
pantsd has quit [Read error: 110 (Connection timed out)]
<setog3>
how to paste the line under the cursor to the interpreter with tuareg mode ?
<pango>
M-C-x (Alt-Ctrl-X on PC keyboards)
<setog3>
ok right
<setog3>
now I need to do the same in vim..
<Smerdyakov>
Don't use vim for functional programming.
<Smerdyakov>
Emacs is the standard for FP, and very little effort goes into support for anything else.
<setog3>
why ?
<setog3>
hmm... but I .. hmm ..
<pango>
setog3: tried omlet ?
<setog3>
pango: omlet is only the indentation and syntax highlight file ..
<setog3>
I don't need something difficult .. I only want to do cut and past the line to the interpreter, I think I must use a pipe ..
rwmjones_ has joined #ocaml
<Smerdyakov>
If you haven't been able to do it yet, wouldn't it be reasonable to conclude that it's difficult? :)
<setog3>
pango: I find evaluateSelection .. wich do what I want .. but I think I need to create a ocamltoplevel to use it with graphics package
rwmjones_ has quit ["This computer has gone to sleep"]
Mr_Awesome has joined #ocaml
clop2 has quit ["Leaving"]
Lena has joined #ocaml
<setog3>
hmm finaly this script do exaclty what I want
<zarvok>
does anyone happen to know, are strings basically character arrays on the inside? And if so, why doesn't the standard library have any nice string <-> char array functions
<Lena>
I don't see why you need a char array
<zarvok>
It would just make my life easier. In this case, I have a function that makes 'a arrays, and I would like to be able to get a string out where appropriate
<pango>
you could functorize your code...
<zarvok>
and if their internal representations are basically the same, it would be nice to be able to do it without scanning down the array
piggybox has joined #ocaml
<zarvok>
pango: yeah, it's a possibility, but it seems like overkill.
<zarvok>
in particular, I'd prefer the function which produces arrays to continue producing arrays
<zarvok>
and another module that uses it to be able to convert to a string
<zarvok>
I wonder, are the two actually represented similarly? To the degree that it would be easy to write an FFI function to convert without actually scanning down the structure?
<pango>
no
<zarvok>
ah
<zarvok>
how are strings represented?
<zarvok>
perhaps character arrays are boxed and strings aren't?
<pango>
they're both boxed
<pango>
arrays are arrays of words
<pango>
string are more compact than character arrays
<zarvok>
ah, I see
<zarvok>
thanks
bluestorm_ has quit [Read error: 113 (No route to host)]
bluestorm_ has joined #ocaml
descender has quit [Remote closed the connection]
<setog3>
hmm last question .. how to use ocaml command without exit if it's the end of file ?
<Smerdyakov>
zarvok, strings are exposed as char vectors in SML. ;)
rwmjones_ has joined #ocaml
<zarvok>
Smerdyakov: Yeah
<zarvok>
I'm writing ocaml this summer, but it's just making me yearn for SML
<Smerdyakov>
What are you writing?
<zarvok>
I'm porting Parsec
<zarvok>
the haskell parsing library
<Smerdyakov>
Ah, I see you on the OSP list.
<zarvok>
yeah
<zarvok>
I'm dissatisfied with camlp4 streams and the other available options
<zarvok>
though the port isn't the only part of the project
<Smerdyakov>
Does anyone know what class of grammars camlp4 supports?
<zarvok>
LL(something)
<zarvok>
where something is an area of argument
<Smerdyakov>
Good, so I won't feel bad implementing a parsing system that handles any context-free grammar. :)
<zarvok>
people disagree, I mean to say
<zarvok>
heh, yeah
TFKv2 has joined #ocaml
<Smerdyakov>
Using camlp4-in-Coq is very frustrating. It's easy to add rules that break each other, but wouldn't with a fully-general parsing engine.
<Smerdyakov>
I wonder what the application is today where parsing performance is most critical.
<zarvok>
I wouldn't know, but I'm told gerard huet's coq camlp4 syntax extensions are very cool
<zarvok>
err, well, I think it was him, but perhaps I misremember
<zarvok>
yeah, my bad, I meant Gonthier
<zarvok>
should have known better
tty56_ has joined #ocaml
tty56 has quit [Read error: 60 (Operation timed out)]
rwmjones_ has quit ["This computer has gone to sleep"]
TFK has quit [Read error: 110 (Connection timed out)]
david_koontz has joined #ocaml
david_koontz has quit [Read error: 104 (Connection reset by peer)]
rwmjones_ has joined #ocaml
Lena has left #ocaml []
david_koontz has joined #ocaml
rwmjones_ has quit ["This computer has gone to sleep"]