malc has quit [Read error: 60 (Operation timed out)]
gim_ has quit ["++"]
async has quit [Read error: 104 (Connection reset by peer)]
Iorek has quit []
ayrnieu has joined #ocaml
_JusSx_ has quit ["Read error: 2.71828182846 (Excessive e)"]
buggs is now known as buggs|afk
jdmarshall has joined #ocaml
jdmarshall has quit [Client Quit]
jdmarshall has joined #ocaml
jdmarshall has quit [Client Quit]
gim|570 is now known as gim
Herrchen has quit [Read error: 110 (Connection timed out)]
Herrchen has joined #ocaml
mattam_ has joined #ocaml
mattam has quit [Read error: 110 (Connection timed out)]
<Maddas>
tomasso: for basic things, you might try the "example" package
Kinners has joined #ocaml
wazze has joined #ocaml
gim_ has joined #ocaml
EgonOberStork has joined #ocaml
__buggs has joined #ocaml
buggs|afk has quit [Read error: 110 (Connection timed out)]
EgonOberStork has quit ["leaving"]
blueshoe has joined #ocaml
<blueshoe>
what is wrong with this? if Array.length Sys.argv = 1 then main Sys.argv.(1) else print_string ( "Usage:...\n" )
<blueshoe>
when i omit any arguments to my program i get: "Fatal error: exception Invalid_argument("Array.get")"
<blueshoe>
and when i have more than 0 arguments i get my usage message :(
<Kinners>
arrays are zero based
<blueshoe>
oh, right
<Kinners>
argv.(0) is the name of the invoked program
<blueshoe>
yeah
<blueshoe>
and argv.(1) is the first argument, which is what i'm checking for
<blueshoe>
i want the user to type one argument (in addition to the command name)
<Kinners>
check that the length is 2 then
<blueshoe>
ahh
<blueshoe>
yeah, that worked
<blueshoe>
the length starts from 1
<blueshoe>
that's what i was missing, blech
<blueshoe>
thanks, kinners
<blueshoe>
it's late
<blueshoe>
that "Array.get" exception must have been coming from the Sys.argv.(1)
<blueshoe>
i thought it was coming from the Array.length
<Kinners>
yeah, foo.(n) gets turned into Arrey.get foo n
<blueshoe>
now i've modified my code to have a "numargswanted" binding, which is subsequently incremented by one, to avoid this kind of mistake in the future
<blueshoe>
even when i'm half asleep
malc has joined #ocaml
_JusSx_ has joined #ocaml
blueshoe has quit [Read error: 54 (Connection reset by peer)]
malc has quit ["no reason"]
__buggs is now known as buggs
kruskal has joined #ocaml
<kruskal>
Does sb know if dynamic arrays will be integrated in ocaml standard lib in the future ?
blueshoe has joined #ocaml
<blueshoe>
here's another mystery (this one a bit more mysterious, i think)...
<blueshoe>
let rec cycle l = function 0 -> l | i -> cycle( List.tl(l)@[List.hd(l)], i - 1 )
<blueshoe>
"This expression has type 'a list * int but is here used with type 'a list"
<blueshoe>
that error at the invocation of cycle()
<blueshoe>
but the arguments to cycle() look like an 'a list * int to me... isn't that what "(list,int)" is?
<blueshoe>
or do i need sleep now more than ever?
<Maddas>
'a list is expected
<blueshoe>
it is?
<blueshoe>
oh, i must have misread that error, then
<blueshoe>
i thought it was saying 'a list * int was expected
<Maddas>
yes, I find them confusing too. I occasionally make sure with a print_int "foo"
<Maddas>
:-)
<blueshoe>
nice trick :)
<blueshoe>
sooo... why does it expect an 'a list?
<Maddas>
I'm not sure what let foo a = function ... does
<blueshoe>
"cycle l = function" looks like it wants two arguments, a list and an int
<blueshoe>
oh, that's the same as saying: "let foo a b = match b with"
<Maddas>
don't you find it clearer to write let rec cycle = function (l, 0) -> l | (l, i) -> ...
<Maddas>
add a question mark to that
<Maddas>
works here that way
<Maddas>
I'm not sure what you want, but this compiles: let rec cycle = function (l, 0) -> l | (l, i) -> cycle (List.tl(l) @ [List.hd(l)], i-1);;
<blueshoe>
hmmm
<blueshoe>
yeah, that looks like a good way of doing it too
<blueshoe>
i still want to figure out why mine doesn't work, though
<Maddas>
let foo a = function ... doesn't expect a tuple
<Kinners>
blueshoe: you return l in the first match, and use l later on in list operations which expect an 'a list
<Maddas>
hm, that's probably the real reason :-)
<blueshoe>
but why does it expect an 'a list?
<Kinners>
blueshoe: List.tl l
<Maddas>
Because you use 'l' as a list
<blueshoe>
the 'a list should be just the first part of the tuple
<blueshoe>
yes, l is a list
<Maddas>
why should it expect a tuple?
<blueshoe>
but it's just the first part of the tuple
<Maddas>
why should it expect a tuple? as I said, let foo a = function ... does not ask for a tuple
<blueshoe>
because i have cycle take a tuple as an argument, no?
<Maddas>
no
<blueshoe>
:(
<Maddas>
at least I don't think so :/
<blueshoe>
i'm sure you're right
<blueshoe>
but i don't understand why
<Maddas>
let foo a = function 0 -> print_endline "foo" | n -> print_endline "bar"
<Maddas>
that function has the signature 'a -> int -> unit
<Maddas>
not 'a * int -> unit
<blueshoe>
ahh
<Maddas>
:-)
<blueshoe>
yeah, i guess i was getting currying confused with tuples
<blueshoe>
now it's all coming back to me
<Maddas>
You don't really need a tuple for cycle, you could as well have two arguments
<blueshoe>
i looked as "let foo a = function" as foo having a single tuple argument, but it's not
<Maddas>
yes, it just expects two arguments
<blueshoe>
i tried invoking cycle with two arguments, but that fails
Kinners has left #ocaml []
<Maddas>
something else with your cycle was borked (check the difference with the one I pasted)
<Maddas>
hm
<Maddas>
it works here
<Maddas>
I simply remove the cycle (... , ...) construct with cycle (...) (...)
<Maddas>
err, replace, not remove
<Maddas>
let rec cycle l = function 0 -> l | i -> cycle( List.tl(l)@[List.hd(l)]) (i - 1 );;
<blueshoe>
This expression has type int list * 'a but is here used with type 'b list
<Maddas>
really?
<blueshoe>
oops, that was another erro
<blueshoe>
r
<blueshoe>
nevermind!
<blueshoe>
it did work
<Maddas>
:-)
<blueshoe>
i had tried it earlier, but thought it didn't work because it gave me another error, but that other error was for another line
<blueshoe>
wasn't paying close enough attention
<blueshoe>
oh yeah... now we're in business
<blueshoe>
the other error was from later invocations of cycle()
<Maddas>
:-)
mattam_ is now known as mattam
<blueshoe>
so... now i have to think about your style
<blueshoe>
i think it does seem clearer
<Maddas>
my style?
<blueshoe>
yeah
<Maddas>
oh, I see
<blueshoe>
the (l,0)
<blueshoe>
etc
<Maddas>
well, this should be somewhat ok
<blueshoe>
i actually just ran in to an ocaml style guide today
<Maddas>
the clearer, but more verbose two-argument version would probably be let rec cycle l n = match n with ...
<blueshoe>
well, that seems the same as what i have
<blueshoe>
"let rec cycle l = function" is idiomatic, afaik
<Maddas>
whatever floats your boat
<Maddas>
I personally only use the function notation for one-argument subs :)
<blueshoe>
but (l,0), etc shows both arguments, so you don't have to look back up to the top of the function to see what the hell l is
<Maddas>
one-argument functions, not subs
<blueshoe>
right
<blueshoe>
i usually do too
<Maddas>
blueshoe: yes, but then that takes a tuple -- use whatever you want
<blueshoe>
this was an exercise, though
<blueshoe>
yeah, it doesn't matter to me if it's a tuple or a curried function
<blueshoe>
but clarity is important
<blueshoe>
anyway, thank you, maddas
<Maddas>
I think one would not usually use tuples unless for some specific reason, but I don't know too much about O'Caml
<Maddas>
no problem
<blueshoe>
i think avoiding tuples makes sense
<blueshoe>
that way you could have delayed evaluation, right?
* Maddas
shrugs
<Maddas>
No idea :-)
<Maddas>
I think it's rather inconvenient to handle large tuples, though
<Maddas>
and you don't get partial application
<Maddas>
err
<Maddas>
you don't get currying :)
<blueshoe>
right, partial application, that's what i mean
<blueshoe>
t
<blueshoe>
why would handling large tuples be harder than handling large numbers of arguments?
<Maddas>
let foo a b c d e f = ...
<Maddas>
you already got all your values in a variable
<blueshoe>
ah
<Maddas>
let foo = function (a,b,c,d,e,f) -> ... seems a bit ugly to me
<blueshoe>
i guess it could be useful if you want to spell out all the different possible combinations
<Maddas>
and also calling foo looks uglier, IMO
<blueshoe>
but if your variables are more independent, then i guess using them as args instead of tuples makes more sense
<blueshoe>
i don't know if it's about smartness so much as education, though
<Maddas>
probably
<blueshoe>
lots of programmers don't have the formal background to really get it
<blueshoe>
like lambda calculus
<Maddas>
I never studied lambda calculus either :-)
<blueshoe>
of course, that can be taught... but it's a lot more than most programmers are willing to undertake when they want to learn some new language
<Maddas>
I'd say that the main thing that keeps people away is that it isn't like C
<Maddas>
The syntax, that is
<blueshoe>
i think you study lambda calculus just by studying ocaml :)
<Maddas>
:)
<blueshoe>
i don't know... ocaml's syntax is a complaint i hear from a lot of people, but i think that can be overcome relatively easily
<blueshoe>
what's a lot harder, imo, is the functional paradigm, thinking recursively rather than iteratively, etc
<Maddas>
I don't think it's bad, it's just very different and awkward at first
<Maddas>
That too, of course
<blueshoe>
i dunno.. i found the syntax pretty easy, after the first day or so
<Maddas>
I don't know if it's harder or just different, though.
<blueshoe>
once i got over the quirky differences, like with semicolons in the top level
<Maddas>
Maybe less natural
<blueshoe>
yeah, just different
<blueshoe>
different enough to scare some of the meek programmers away
<Maddas>
blueshoe: That's what I meant most with awkward, knowing when I can leave away the semicolons is probably what took longest to figure out
<Maddas>
but it's mostly that you would look at some simple code (before learning O'Caml) and not understand a bit
<blueshoe>
they don't realise that the bitter pill holds a lot of power
<blueshoe>
well, you can't really leave the semicolons out in the toplevel
<blueshoe>
and they're still used in lists
<Maddas>
You can
<blueshoe>
not in the toplevel
<Maddas>
let a = foo
<Maddas>
let b = bar;;
<Maddas>
oh, hm
<Maddas>
works here :-)
<blueshoe>
you did need the ;; at the end, though
<blueshoe>
that's what i mean
<Maddas>
Yeah
<blueshoe>
it looks inconsistent for someone used to a c-like syntax
<Maddas>
Yeah
<blueshoe>
esp when they're also used with lists
<blueshoe>
so you have to learn the exceptions and quirks
<blueshoe>
but, imo, those are minor
<Maddas>
the major thing is certainly the functional/imperative switch
<blueshoe>
right
<blueshoe>
that really makes you think differently
<Maddas>
I'm quite convinced though that the syntax alone and the fact that it isn't widely used scares away quite many, too :)
<blueshoe>
whereas syntax is just memorizing some relatively straightforward rules
<blueshoe>
yeah, people are scared by syntax... unjustly, though
<Maddas>
of course
two-face has left #ocaml []
<blueshoe>
i think, though, that many of those people who do struggle through the syntax can get discouraged by how hard it is to make the switch to the functional paradigm
<Maddas>
and the "if it were so good, why doesn't everybody use it" thing
<Maddas>
s/were/is/
<Maddas>
blueshoe: and that most documentation is in French ;)
<blueshoe>
well, i think most programmers realise that languages start small
<blueshoe>
many are looking for the hot new language
<Maddas>
heh, I feel quite the opposite
<blueshoe>
but they also, maybe without realising it, look for something not too different from what they know, so the learning curve isn't too steep
<Maddas>
many are sitting on their bums claiming that their language is the best and everything else is crap :)
<blueshoe>
yeah, that's true too
<Maddas>
and anything sufficiently different has to be crap anyway because it's different :)
<blueshoe>
heh
<blueshoe>
ooops, i almost forgot that the power in this building is going to go off in less than 30 mins
<blueshoe>
i should go and prepare
<Maddas>
Heh, ttyl then
<blueshoe>
cool chatting w/you, though
<blueshoe>
yeah, see you
<blueshoe>
and thanks again for your help!
<Maddas>
no problem
blueshoe has quit ["..."]
<Hadaka>
I never found ocaml's syntax overly hard to grasp - after the first few days, that is
<Hadaka>
ocaml was the first language with currying I stumbled upon - and that took a moment to grasp
srv has joined #ocaml
<Smerdyakov>
I think anyone who finds _syntax_ hard to grasp should give up on programming.
tomasso_ has joined #ocaml
tomasso has quit [Read error: 110 (Connection timed out)]
zenkov has joined #ocaml
rox has left #ocaml []
zenkov has left #ocaml []
yella has joined #ocaml
det has quit [Read error: 110 (Connection timed out)]
det has joined #ocaml
Demitar has joined #ocaml
gim has quit [sterling.freenode.net irc.freenode.net]
vect has quit [sterling.freenode.net irc.freenode.net]
gim has joined #ocaml
vect has joined #ocaml
madroach has joined #ocaml
<madroach>
Hello, I just searched for an interface to a gui library and fount lablgtk and mlgtk. Are there others and which should I use ?
<madroach>
smkl: I looked at this. But which is usable for me ? I know caml since august and like to try GUI programming.
simon- has quit [Read error: 60 (Operation timed out)]
<smkl>
i use lablgtk
<madroach>
What's the advatage of lablgtk in comparison with mlgtk, which is much smaller ?
<smkl>
i don't know, i havent tried mlgtk
<smkl>
lablgtk is probably more mature, and more high-level
<karryall>
mlgtk is completety unmaintained AFAIK
<karryall>
and it's for GTK 1.2 whereas lablgtk support GTK 2
<smkl>
do you know if lablgtk2 is completely backwards compatible?
<karryall>
smkl: not sure, but probably not
Iorek has joined #ocaml
owll has joined #ocaml
owll has quit [Client Quit]
madroach_ has joined #ocaml
malc has joined #ocaml
_JusSx_ has quit [Read error: 60 (Operation timed out)]
madroach has quit [Read error: 110 (Connection timed out)]
_JusSx_ has joined #ocaml
kruskal has left #ocaml []
karryall has quit ["reboot"]
madroach_ has quit ["leaving"]
malc has quit ["no reason"]
_JusSx_ has quit ["[BX] Who ate my nuggets?!"]
emu has quit [Read error: 60 (Operation timed out)]
Iorek has quit []
clog has joined #ocaml
buggs has quit [Remote closed the connection]
emu has joined #ocaml
<Etaoin>
is it possible to do something to an out_channel to send an EOF to the other side without actually closing the channel?
<Smerdyakov>
I doubt it. The underlying interfaces generally don't have any concept of what it means to "send an EOF."
<Riastradh>
Why would you want to do that?
<Etaoin>
I am talking to gnuplot through a pipe
<Etaoin>
oh well. I'll work around it
blueshoe has joined #ocaml
Swynndla_wk has joined #ocaml
blueshoe has quit [Read error: 104 (Connection reset by peer)]
mimosa has joined #ocaml
<Swynndla_wk>
Hey, I'm new to ocaml, and I'm having problems summing up the contents of an array, but I can't find out how to do it in the manual ... would someone be able to help? (is this the right place to ask?)
<mimosa>
I would do smth like
<mimosa>
let s = ref 0 in
<mimosa>
Array.iter (fun x -> s := !s + x) arr
blueshoe has joined #ocaml
<blueshoe>
does anyone know when the next icfp contest is going to take place?
<blueshoe>
i can only find the 2003 web page
<Swynndla_wk>
mimosa, can I put what I've tried? .. only if you don't laugh at my code though!
<Swynndla_wk>
only 5 lines
<mimosa>
no pb
<Swynndla_wk>
let v = [| 1; 2; 3 |];;
<Swynndla_wk>
let mysum=0;;
<Swynndla_wk>
for i = 0 to Array.length v -1 do
<Swynndla_wk>
let mysum=mysum+v.(i);;
<Swynndla_wk>
done;;
<Swynndla_wk>
but it doesn't work
<mimosa>
the problem is the let mysum=mysum+v.(i);;
<Swynndla_wk>
(as you can see I've got a lot to learn)
<mimosa>
:)
<Swynndla_wk>
oic
<mimosa>
when you declare let mysum=0;; ,
<mimosa>
you cannot change the value of mysum
<mimosa>
that's why you should declare let mysum=ref 0;;
<mimosa>
ref (roughly) indicates that the value of mysum can be changed
<mimosa>
then to change its value
<Swynndla_wk>
ahhhhhhhhhhhhh
<blueshoe>
or you can rewrite the function recursively
<mimosa>
you should use the syntax mysum := 324
<mimosa>
and to access to its value it's !mysum
<Swynndla_wk>
oic
<Swynndla_wk>
the only way I could figure it out was to create an array with one element and update that (as I could change the value)
<Swynndla_wk>
lol
<Swynndla_wk>
mimosa, I have to test it in a bit ... not right now as I'm in the middle of something (at work) ... but thanks so much for your help!
<mimosa>
the pleasure was for me :)
<Swynndla_wk>
:)
<Swynndla_wk>
blueshoe, I'm getting used to the idea of recursion .. slowly :)
<blueshoe>
yeah, it's tough
<blueshoe>
but once you learn it it's pretty cool
<Swynndla_wk>
:))
<blueshoe>
in fact, i had trouble starting to think iteratively again after immersing myself in recursion for a while
<Swynndla_wk>
lol
<blueshoe>
"how do you do for loops again"? heh
<Swynndla_wk>
studpid question ... what's the advantage of recusion over iterations?
<blueshoe>
not that i mastered recursion, or anything... i still have a long way to go... but it definitely makes more sense than when i first strated
<blueshoe>
i'll let more experienced people answer that... but from what i hear any iteration can be written recursively, but not vice versa
<blueshoe>
also, with recursion you don't need variables that change value, so you can write in a functional style
<blueshoe>
while with iteration you need modifiable state
<blueshoe>
right?
<Swynndla_wk>
ok
<Swynndla_wk>
so code it shorter
<blueshoe>
don't quote me on that... i'm still an ocaml/fp beginner
<Swynndla_wk>
is it faster?
<Swynndla_wk>
lol
<Swynndla_wk>
oh ... what's fp?
<blueshoe>
fucntional programming
<Swynndla_wk>
ahhhhhhh
<Swynndla_wk>
yea .... this is my 1st fp language
<blueshoe>
mine too
<Swynndla_wk>
:)
<blueshoe>
though now i'm reading an ml book
<blueshoe>
they're basically the same, though
<blueshoe>
so it's not a stretch
<blueshoe>
and i did read a tiny bit of the sicp, which teaches scheme
<Swynndla_wk>
oic
<blueshoe>
i've heard of ml referred to as a "statically typed lisp"
<Swynndla_wk>
what's the diff between ml and fp?
<blueshoe>
don't konw how true that is, since i don't really know lisp, except for the little bit of scheme from sicp
<blueshoe>
ml is a language
<Swynndla_wk>
ahhhh
<blueshoe>
functional programming is a pradigm
<Swynndla_wk>
ml is a fp language?
<blueshoe>
imperative programming (c, c++, java, perl, python, vb, etc) being the most popular paradigm
<blueshoe>
yes
<Swynndla_wk>
gotcha
<blueshoe>
those java programmers don't know what they're missing :)
<Swynndla_wk>
I know pascal, fortran, perl, and I was going to learn c but someone told me not to bother and to learn ocaml instead
<Swynndla_wk>
why?
<blueshoe>
i think c is definitely worth knowing
<blueshoe>
just because there are soooooo many programs written in it
<Swynndla_wk>
ahhhh
<Swynndla_wk>
yes
<blueshoe>
and so many books refer to c
<mattam>
C is not much different from Pascal
<blueshoe>
yeah, it's cloes
<blueshoe>
close
<Swynndla_wk>
ok
<blueshoe>
but just different enough that when i hear about pascal i don't fully know what they're talking about (my last pascal class was probably 20yrs ago)
* Smerdyakov
looks at blueshoe's hostname.
* blueshoe
gasps
<Smerdyakov>
There is a surprisingly large number of Berkeley people here.
<Swynndla_wk>
<blueshoe> those java programmers don't know what they're missing :) <-- what do you mean? ... I don't understand
<mattam>
all the niceness of fp is absent of Java.
<Swynndla_wk>
oic
<blueshoe>
smerdyakov, was what i said earlier about the advantages of recursion vs iteration accurate?
<Swynndla_wk>
so Java is one of the imperative languages?
<mattam>
yep
<Smerdyakov>
blueshoe, sounded accurate enough to me.
<blueshoe>
cool
<Smerdyakov>
blueshoe, what's your affiliation with Berkeley?
<mattam>
it is very close to C++, which is C + object system
<Swynndla_wk>
so ... recursion is tidier? ...but is it faster?
<blueshoe>
smerdyakov, i work there
<Swynndla_wk>
mattam, oic
<Smerdyakov>
blueshoe, what's your job title?
<blueshoe>
sys admin
<Smerdyakov>
Ah. I'm a soon-to-be-2nd-semester CS PhD student.
<Smerdyakov>
(At Berkeley, since I didn't say it explicitly yet. :)
<blueshoe>
ahh
<blueshoe>
wow
<Smerdyakov>
And async (who is often here) is a CS undergrad.
<blueshoe>
is there a strong ocaml presence at berekeley?
<blueshoe>
are there any ocaml classes here?
<blueshoe>
i just started working here a few months ago, so i don't really know much of what's going on on campus
<Smerdyakov>
I just started a few months ago, too, but here's my summary:
<Smerdyakov>
I don't think a single undergrad class mentions OCaml.
<blueshoe>
what about ml?
<Smerdyakov>
Grad classes taught by Open Source Quality group people often do, but that's not a big fraction of the classes.
<Smerdyakov>
A large portion of OSQ students are also big ML fans.
<Smerdyakov>
A number of projects use OCaml.
<blueshoe>
hmm... haven't heard of OSQ
<Smerdyakov>
Including the one I work on.
<blueshoe>
willcheckthem out
<blueshoe>
which one do you work on?
<Smerdyakov>
Extensible program safety verification architecture. No official project web page or anything yet.
<Smerdyakov>
mattam, this seems to take a higher level view. What we're doing is more concerned with basic yet universal properties like only accessing valid memory addresses.
<mattam>
yeah, i see. Does Java bytecode has registers ?
<Smerdyakov>
I think so.
<Smerdyakov>
Though I'm not sure.
<Smerdyakov>
You are forced to use stacks to store a lot of stuff.
<Smerdyakov>
Maybe it _is_ entirely stack based.
<mattam>
hey, that should be easier with stacks only i think :)
<Smerdyakov>
Yes. Proving memory safety ofwith x86 machine code produced by optimizing compilers is not a trivial task. :)
<blueshoe>
especially if the code was written by microsoft :)
<blueshoe>
actually, i've heard microsoft research is interested in ocaml
<mattam>
i'm curious, aren't there NP-hard problems when trying to prove such thing as accessing only valid memory addresses ?
<blueshoe>
...apart from f#
<Smerdyakov>
mattam, worse than that. It's undecidable.
<mattam>
ha
<Smerdyakov>
mattam, but if you know which compiler made the code, it can become very easy.
<Smerdyakov>
mattam, this system allows plug-ins for different compilers that generate proofs based on information on how the compiler produces code.
<mattam>
it sort of adds hypothesis given a particular compiler impl ?
<Smerdyakov>
No. That wouldn't be sound, from the code consumer's point of view.
<Smerdyakov>
It uses particular proof strategies.
<mattam>
ok
<Smerdyakov>
As opposed to flopping about like a fish on a provably impossible problem. :)
<mattam>
hehe
<blueshoe>
strategies like what?
<Smerdyakov>
Like ignoring all details of register values except their types
<blueshoe>
ahh.. that makes sense
<Smerdyakov>
And using a few simple lemmas about typed values
<blueshoe>
except what if the value is a pointer?
<Smerdyakov>
Never seen pointer types? :)
<blueshoe>
well, you'd still want to know what it points to, no?
<Smerdyakov>
Why?
<Smerdyakov>
OCaml's type checker doesn't need that info, and it's type safe.
<blueshoe>
to see if it points to a valid memory address... isn't that the whole point (pardon the pun)
<blueshoe>
?
<blueshoe>
yes, type safety i can understand
<Smerdyakov>
You just define the meaning of "having pointer type" to require that the pointer is valid.
<blueshoe>
but you're not going for just type safety but guarantees that you won't access invalid memory addresses, no?
<Smerdyakov>
That's part of type safety.
<blueshoe>
ahh, i see
<blueshoe>
interesting
<Swynndla_wk>
Riastradh, ahhh ic
<Swynndla_wk>
mimosa, sry I was busy ...
<blueshoe>
so, your system can ignore the content of these pointer variables, but they're not completely ignored, as something has to guarantee that they point to valid addresses
<Swynndla_wk>
mimosa, I tried let mysum=ref 0;; but it still din't work
<Smerdyakov>
Like I said, everything but their types can be ignored.
<blueshoe>
by your system
<mimosa>
Swynndla_wk: show the whole code please
<Swynndla_wk>
ok sure ...
<Smerdyakov>
By one class of plug-ins for it.
<Swynndla_wk>
let v = [| 1; 2; 3 |];;
<Swynndla_wk>
let mysum=ref 0;;;
<Swynndla_wk>
for i = 0 to Array.length v -1 do
<Swynndla_wk>
let mysum=mysum+v.(i);;
<Swynndla_wk>
done;;
<blueshoe>
but it can't be ignored by whatever it is that makes sure that the pointer type contains only valid memory addresses
<mattam>
Swynndla_wk: x := something
<mimosa>
yes
<mattam>
Swynndla_wk: x := !x + 1
<Riastradh>
Swynndla_wk, no, that's not how you write it. let doesn't assign anything. let _binds_. Only at the top level can let without a corresponding 'in <body>' be used, too.
<Swynndla_wk>
oic
<mimosa>
mysum := !mysum + v.(i)
<mimosa>
and no ;;
<Swynndla_wk>
oic ...
<Riastradh>
And still that's a needlessly imperative loop.
<blueshoe>
interesting that berkeley isn't particularly enthusiastic about ocaml... you'd think they'd be more on the cutting edge
<Riastradh>
The functional idiom of doing this is using Array.fold_left.
<blueshoe>
i wonder if there are any US universities that give it more attention
<Swynndla_wk>
yea .. I'm still learning to break my thinking from imperitive
<mimosa>
Riastradh: well purely functionnal approach would be more natural on lists
<Smerdyakov>
blueshoe, it matters at particular steps, but the information kept over time can be restricted to types.
<Swynndla_wk>
but ... it still doesn't work ... can I show you what i've got?
<Riastradh>
mimosa, it's irrelevant what structure it is.
<mimosa>
of course
<Riastradh>
Fold is the fundamental iterator over any collection.
<Swynndla_wk>
thx ....
<Smerdyakov>
blueshoe, my undergrad school CMU is enthusiastic about Standard ML.
<mimosa>
but you cannot do pattern-matching on arrays
<blueshoe>
smerdyakov, yes, i see that... it is a good approach
<mimosa>
x :: s
<mimosa>
Riastradh: ok sorry
<Riastradh>
mimosa, irrelevant. You don't _need_ to do pattern matching. Fold does all the destructuring for you.
<mimosa>
I wasn't thinking of fold
<Smerdyakov>
blueshoe, and we're working on getting some more ML exposure here. :)
<blueshoe>
smerdyakov, must have been fun to go there :)
<mimosa>
Riastradh: but anyway folding functions are not good for beginners
<mimosa>
I think
<Smerdyakov>
blueshoe, there should be a few new professors hired to work in programming languages. Hopefully some ML fans. :)
<blueshoe>
well, if you ever start an ml/ocaml user's group here let me know :)
<mimosa>
because you don't really understand how they do work
<Riastradh>
mimosa, perhaps not, but they're better than the imperative loop that Swynndla_wk has written.
<Smerdyakov>
blueshoe, I don't know what the use of that would be.
<mimosa>
of course
<Smerdyakov>
blueshoe, this channel, mailing lists, etc., work well enough.
<blueshoe>
me neither, but it sounds fun
<mimosa>
that's a beginning
<Riastradh>
And they can be trivially described in terms of those imperative loops, too.
<Smerdyakov>
blueshoe, what's your formal education to date?
<Swynndla_wk>
mimosa, sry ... work getting in the way!
<Smerdyakov>
blueshoe, I'm taking a grad class on what look like fun programming languages subjects this spring. If you're qualified, you might want to take it for fun. I assume you can take a class a semester for free.
<Swynndla_wk>
let v = [| 1; 2; 3 |];;
<Swynndla_wk>
let mysum=ref 0;;;
<Swynndla_wk>
for i = 0 to Array.length v -1 do
<Swynndla_wk>
mysum := !mysum + v.(i)
<Swynndla_wk>
done;;
<blueshoe>
smerdyakov, i studied art in college... i'm virtually completely self-taught as far as computers go... but i've been using them since '80
<Smerdyakov>
blueshoe, ah. Maybe that wouldn't work, then.
<Swynndla_wk>
it says "This expression has type int but is here used with type 'a ref" ... refering to "mysum" in mysum := ...
<blueshoe>
smerdyakov, yeah, i can take classes here... don't know what the requirements are... i would take one if it focused exclusively on ml/ocaml... but otherwise, i think i'd rather take a philosophy course... dunno yet... anyway, i don't really have time for anything but work these days
<Smerdyakov>
blueshoe, I expect a focus on functional languages. In the last instance of the course from this professor, the recommended background readings were books on Common Lisp and Standard ML.
<blueshoe>
cool
<blueshoe>
that sounds like fun
<Smerdyakov>
The prof. was on the Common Lisp standard committee.
<Smerdyakov>
It's CS264.
<Smerdyakov>
Formally, it requires an undergrad compilers course.
<blueshoe>
i want to learn lisp/scheme at some time... right now i want to focus on ml/ocaml, though... just so i can feel half-way proficient in one language before diving in to another
<blueshoe>
yeah, it does interest me... but i just can't devote that much time to it... i'm pretty much doomed to learning it piecemeal
<Swynndla_wk>
and the FAQ's .. but those eg's deal with caml light mainly :/
<Smerdyakov>
I worked with a research scientists at CMU who did a CS degree over 10 years, taking one or two courses every semester.
<blueshoe>
wow
<Riastradh>
A research scientists?
<blueshoe>
that would be cool
<Smerdyakov>
Riastradh, actually, just one.
<blueshoe>
you have to have a lot of dedication, though... my interests tend to swing violently from one topic to another... for a few months i might be obsessed with ocaml and programming, the next three months i might get totally sick of computers and want nothing to do with them, and just read fiction, or then philosophy, or art, or music, etc...
<Riastradh>
And you were complaining about that Russian guy misusing articles a few days ago!
<blueshoe>
hard to stay focused on just one subject when there's so much interesting stuff out there
<Smerdyakov>
blueshoe, you mean there are periods when you don't want to read fiction? :)
<blueshoe>
yes, hard to believe, huh? :)
<blueshoe>
i've read some of one of the books for that cs264 class
<blueshoe>
eseentials of programming languages... cool book
<blueshoe>
and one of the other books is by ullman... i'm reading his elements of ml programming now
<blueshoe>
ullman's one of the best programming language teachers i've read
<Swynndla_wk>
"x := !x + 1" ... does the "!x" mean the existing value of x?
<blueshoe>
he does a lot of stuff i don't see in most other books, like he shows you what the compiler will do when you get stuff wrong
<blueshoe>
and explains why
<blueshoe>
i find that kind of approach gives you a much better understanding of why things work the way they work
<Riastradh>
Swynndla_wk, it nabs the value inside the reference that x refers to. References are mutable cells. := assigns the value that a reference contains; ! retrieves the current value in the reference.
<blueshoe>
he teaches at stanford... would be cool to take a class with him
<Swynndla_wk>
Riastradh, ahhh ic
<Riastradh>
Variables in OCaml are not mutable, which is why you use references instead.
<Riastradh>
Er, without the 'instead' bit.
<Swynndla_wk>
you're going to hate this, but it starts to make sense to me when I think of Excel as an analogy :)
<blueshoe>
ocaml was based on excel
<Swynndla_wk>
really?
<blueshoe>
no
<blueshoe>
hehe
<Swynndla_wk>
you're teasing me!
<blueshoe>
guilty
<Swynndla_wk>
:P
<blueshoe>
though, actually, you're not the first person to suggest a connection
<Swynndla_wk>
huh!
<Smerdyakov>
blueshoe, there are plenty of professors at Berkeley who can provide sufficient "coolness factor." :)
<blueshoe>
i don't remember where, but i've heard some analogies with functional programming and spreadsheets
<Riastradh>
Yes, you could imagine variables as different names for things, such as references and numbers, and references as cells in a spreadsheet.
<blueshoe>
smerdyakov, i didn't mean "cool" in that way... not as meaning that it would make me feel cool or i'd go hear him because i thought he was cool... i just meant that since he was one of the best programming language teachers i've read i think i could learn a lot from taking a class with him in particular, and i would really like that... "cool" in that sense
<Riastradh>
But mutability is an imperative concept. Most of a functional program should avoid mutation.
<blueshoe>
there might be professors at berekeley who are just as "cool" (ie. have as good or better a reputation or have achieved as much or more, or be as or more brilliant, etc)... but can they teach as well? will i learn as much from them as from him?
<Swynndla_wk>
mutation lol ... that's going to be my 1st program .. to write a genetic algorithm!
<blueshoe>
all i know is that when i read his explanations in elements of ml programming they are some of the clearest that i've read, and that's rare, from my experience