<mattam>
and what is the average age of BS pursuers ?
<reltuk>
LittleDan: at my college, the required language theory class has you build an interpreter for an ocaml-like language
<LittleDan>
undergrad
<reltuk>
mattam: 18 - 22
<mattam>
so 20 is the average :)
<reltuk>
LittleDan: then the next course in the series has you build a compiler for some language...not really sure abou tthe language, but I think it's c-based
<LittleDan>
For making an interpreter, do you think passing around the AST itself would be an efficient way to implement thunks (with strictness in some situations)?
<reltuk>
LittleDan: thunks are hard to do efficiently...
<mattam>
simple, not efficient
<reltuk>
that way would work...it's how my interpreter does it
<reltuk>
but it's not efficient
<LittleDan>
what language did you implement?
<reltuk>
it's like a lazy ocaml...but without a lot of the features of ocaml like references
<reltuk>
i wouldn't call it a language so much as a "prove to us you can implement an interpreter" test bed
<LittleDan>
I'm trying to make a language where the variable model is based on pattern matching symbols.
wazze has quit ["--- reality is that which, when you stop believing in it, doesn't go away ---"]
<reltuk>
how so?
<LittleDan>
example
<LittleDan>
a = 5
<LittleDan>
when the "" function recieves the variable symbol a, it returns 5
<LittleDan>
"" is the root function
<LittleDan>
(actually I think it was
<LittleDan>
a is 5
<LittleDan>
for the actual syntax)
gim has quit ["/me has quit"]
<reltuk>
ahhh...ok
<reltuk>
this is an interpreter?
<LittleDan>
but you can do tons more stuff based on that
<LittleDan>
yes
<LittleDan>
I've barely started
<reltuk>
normally the variable model in an interpreter is based on a relational map from name to value
<LittleDan>
yeah, that's probably how it will be in implementation
<LittleDan>
but then you can do other things
<LittleDan>
like infix operators without special syntactic consideration
<LittleDan>
(a) + (b) is !!builtin-plus!! a b
<LittleDan>
putting things in parens evaluates them strictly
<reltuk>
sounds funky
<LittleDan>
[a] + [b] is [!!builtin-plus!! a b] -- lazy version
<LittleDan>
square brackets makes a promise-like thing
<LittleDan>
you get used to the parens because they have actual meaning
<LittleDan>
some-namespace a is 5
<LittleDan>
some-namepsace b is 10
<LittleDan>
x is some-namespace
<LittleDan>
assert ((x b) = 10)
<LittleDan>
do you get what that does?
<mattam>
b is equal to 10 in x
<reltuk>
how do you do function application?
<reltuk>
and what does [x b] = 10 do?
<LittleDan>
= forces it because it is defined with (a) = (b) is --something
<Riastradh>
LittleDan, what makes this language 'better' than others, and for which kinds of tasks?
<LittleDan>
f (a) (b) = a + b
<LittleDan>
assert ((f 1 2) = 3)
<LittleDan>
riastradh: it's just an experiment
tautologico has joined #ocaml
<reltuk>
looks confusing
<LittleDan>
there are a bunch of other abstractions you can do with it
<LittleDan>
oops, I messed up that last thing
<LittleDan>
f (a) (b) is a + b
<LittleDan>
but still probably confusing
<reltuk>
is f a function?
<LittleDan>
yes, sort of. Functions are all patterns.
<LittleDan>
it is the same amout a function as some-namespace was
<reltuk>
and how do you distinguish = from equality test?
<LittleDan>
it's always equality test
<LittleDan>
I messed up
<reltuk>
(x b) is 10
<LittleDan>
no
<LittleDan>
then b is a pattern matcher, which is like
<LittleDan>
f (x type <number>) is x + 1
<LittleDan>
b would be like type
<reltuk>
hmm...
<LittleDan>
but type is a keyword in other contexts
<reltuk>
f (a) (b) is a + b...
<reltuk>
now how do you apply f?
<LittleDan>
f 1 2
<LittleDan>
if the function wanted to, it could interpret 1 and 2 as variable symbols, but it because of how the pattern is written, it evaluates them
<LittleDan>
but you probably wouldn't do
<LittleDan>
f 1 2 is 3
<LittleDan>
because that dispatches on the name. You'd do
<LittleDan>
f (= 1) (= 2) is 3
<reltuk>
hmmm
<LittleDan>
this probably all seems complicated because I'm describing it so fast. Imagine if someone described OCaml to you like this after knowing only Cobol
<LittleDan>
(not that ocaml is like cobol)
<reltuk>
*shrug*, not that complicated...just foreign...but I don't see what you gain from it
<LittleDan>
you can do a lot of things more simply
<LittleDan>
like keyword arguments
<LittleDan>
and with simpler syntax
<reltuk>
example?
<LittleDan>
say to (target) (message) is --something
<LittleDan>
say (message) is --something to stdout
<LittleDan>
I just want to try out implementing it
<reltuk>
ahhh, I see what you mean
<LittleDan>
with implementing or with advantages?
<reltuk>
advantages...
<reltuk>
I mean, at first glance, the ability to have arbitrary "syntax" regarding a function call could be pretty cool
<reltuk>
it seems like it would make describing a system composed of these calls more natural
<LittleDan>
yeah
<reltuk>
if the calls themselves were in close-to-natural-language form
<LittleDan>
The only problem is that infix operators would be very inefficient. It has to first make sure that the first argument isn't a function with the operator applied to it
<LittleDan>
and that makes up much of the natural language-ness
<LittleDan>
Flow control is done via blocks like smalltalk
<LittleDan>
it isn't at all builtin; it's implemented completely with patterns
<LittleDan>
do actually makes an anonymous function
<LittleDan>
I'm not exactly sure of the rules for evaluating it
<reltuk>
yeah, but the gist of it is there
<LittleDan>
You almost don't need macros, but an argument-less #define equivalent is useful
<LittleDan>
example:
<LittleDan>
macro return is call/cc as return do
<LittleDan>
--as makes an anonymous function with arguments
<LittleDan>
oops, I mean
<LittleDan>
macro function is call/cc as (return) do
<LittleDan>
return-usage-example (x) is function
<LittleDan>
if (x = 5)
<LittleDan>
do return 3
<LittleDan>
else do
<LittleDan>
print "no"
<LittleDan>
print "no"
<reltuk>
gotta jet, good luck with that stuff :)
<reltuk>
although I'll probably see you around before you're done
<LittleDan>
thanks
reltuk has quit [Remote closed the connection]
LittleDan has left #ocaml []
tautologico has quit [Read error: 54 (Connection reset by peer)]
reltuk has joined #ocaml
kinners has joined #ocaml
kinners has quit ["leaving"]
cjohnson has quit [Read error: 60 (Operation timed out)]
hf has quit [Read error: 60 (Operation timed out)]
hf has joined #ocaml
__DL__ has joined #ocaml
__DL__ has quit [Client Quit]
bk_ has quit ["I'll be back"]
reltuk has left #ocaml []
LordBrain has quit [Remote closed the connection]
bk_ has joined #ocaml
mijdrol has quit [Read error: 110 (Connection timed out)]
mijdrol has joined #ocaml
buggs|afk has joined #ocaml
mijdrol has quit [kornbluth.freenode.net irc.freenode.net]
teratorn has quit [kornbluth.freenode.net irc.freenode.net]
mijdrol has joined #ocaml
teratorn has joined #ocaml
gim has joined #ocaml
buggs^z has quit [Read error: 110 (Connection timed out)]
<yella>
is it possible to write a 'member' function examining e.g. types F1(S1(L2("la"))) ?
<yella>
i would like to apply something like: member S1 (F1(S1(L2("la")))) which returns true or whatever when S1 is present
<yella>
though this seems not possible in this way
<Demitar>
Sounds like simply a recursive function to me.
<Demitar>
What is your type_
<Demitar>
s/_/?/
<yella>
well it was an example. i took
<yella>
type last = L1 of int|L2 of string
<yella>
type second = S1 of last|S2 of string
<yella>
type first = F1 of second|F2 of last
<yella>
it seems not possible to match only for one constructor without argument
<Demitar>
let rec first_has_S1 a = let rec second_has_S1 b = match b with S1 _ -> true | S2 _ -> false in match a with F1 x -> second_has_S1 x | F2 -> false
<Demitar>
How about that one? :) You don't really need a second recursive function in this case but if you want to do a more complicated check you might.
<Demitar>
Make that s/F2/F2 _/
<yella>
let me analyse it :)
buggs|afk is now known as buggs
<Demitar>
What it really does is that it first descends from type first, since last cannot have value S1 I optimize it and break out.
<Demitar>
Then it does the same for type second, if you had a more complicated type tree you might want to exhaust the entire tree before evaluating to false.
<yella>
yeh it's working.
<Demitar>
And if you hit the type you want you simply return true of course.
<yella>
though i tried to do a more polymorphic variant
<yella>
'a_has_'b would be nice :)
<Demitar>
Since you're investigating types you can't really do it in a polymorphic way since it's *type* polymorphism.
<yella>
hm
<Demitar>
However camlp4 might have some extensions to build the functions you want automagically.
<Demitar>
But you want someone elses word for that though. :)
<yella>
thus if you have much more complex types you have to program every 'possibility' out? that's bad news :)
<Demitar>
Why do you want this by the way?
<Demitar>
You generally descend the tree and do some *action* based on what you find, not check if it contains a specific type value.
<yella>
well, i want to compare two types for their similarity
<Demitar>
Tree types are generally value holders, not the values themselves.
<yella>
they still represent some value I suppose
<Demitar>
So, you want something like "80% the same"?
<yella>
yep
<yella>
could also be fuzzy. 'very similar' ..it's not that i insist on percentage :)
<Demitar>
Well unless you have a very specific reason you want them as types it sounds like the data you want to hold is more values.
<Demitar>
What specific application are you writing?
<yella>
i want to compare two abstract syntax trees for their similarity
<yella>
similar to a 'clone detection' process, if that says something to you
<Demitar>
Not as much as it should.
<yella>
:)
<Demitar>
But it sounds like you want to have the tree in value form since you then can compare everything using a generic tree algorithm.
<Demitar>
Or ask someone if camlp4 can do this.
<yella>
and for this application also the constructor type is essential. or even more essential than the value itself
<Demitar>
Actually I would suggest that if noone knowledgeable around here wakes up you might want to ask on the mailing list, presenting your problem and what you have tried so far.
<yella>
i thought to reconstruct it into a list and then apply some generic List function over it
<Demitar>
Sounds like a good plan actually.
<Demitar>
Or...
<Demitar>
Would it make sense to you to descend both trees at the same time?
<Demitar>
If your types are non-recursive that might be the best plan actually.
<Demitar>
Or maybe not... :) Do whatever is sane. :)
<yella>
they are recursive of course :)
<yella>
the type representation i mean
<Demitar>
How about accumulating one list for each type and comparing them?
<yella>
yes, sounds reasonable...
bk_ has quit ["I'll be back"]
<yella>
i have the feeling that the best way to compare datastructures is to have them in a binary tree
<yella>
but heh..feeling is not enough
<Demitar>
It is probably the best way, but only if you only have one type in the tree. ;-)
<malte>
is there a way to use threads in ocaml?
<Demitar>
Yep, check the manual. Don't forget to compile with -threads though.
<malte>
cool, thanks
<yella>
demitar: well. stringify everything and put them in a binary tree. but I'm sure there is a better way
<Demitar>
yella, sure, but none I'm likely to come up with right now. ;-)
<yella>
k. I try if the 'one list for each type' applicable and useful...
<yella>
is
avn has quit [Read error: 104 (Connection reset by peer)]
<malte>
make inconsistent assumptions over interface Nativeint
<malte>
^-- what does this mean?
<Demitar>
Looks like you've upgraded ocaml but not recompiled lablgtk.
* Demitar
heads out for a few days.
<malte>
ok, i'll try and recompile lablgtk then
bk_ has joined #ocaml
maihem has joined #ocaml
LordBrain has joined #ocaml
<LordBrain>
does ocaml let you make functions and tell it that they are infix operators?
<yella>
something like this:
<yella>
let ( +* ) a b = a + 2*b;;
<yella>
# 10 +* 30;;
<yella>
- : int = 70
<lucifer>
but not with new functions i presume?
<lucifer>
let ( foo* ) a b = a+2*b;; say
<malte>
it can only consist of special characters iirc
<yella>
i think & / - + etc are allowed
<lucifer>
messy..
<malte>
yah, that's what i meant :)
<malte>
it makes for obfuscated code if nothing else
<yella>
val ( <:- ) : int -> int -> int = <fun>
<yella>
hehe
<yella>
the smiley operator
<malte>
:)
<LordBrain>
any combination of those symbols? what about &:-& can that be an operator?
<yella>
of course
<lucifer>
try it?
<lucifer>
it doesnt like starting with : it seems
<LordBrain>
hmm cool
<LordBrain>
heh, what about postfix?
<LordBrain>
:P
<yella>
works aswell but you need the brackets around the operator
<yella>
( ++ ) 1 2
<lucifer>
thats prefix
<yella>
err :)
<lucifer>
i dont think ocaml knows any postfix operators
<lucifer>
postfix is kinda weird in functional languages anyway
<malte>
how fast is ocaml's bytecode compared to, say, mono?
<lucifer>
their C use that is
<LordBrain>
let ( *: ) f g x = f (g x) ;; (* function composition *)
<LordBrain>
pretty cool
<LordBrain>
hmm *: already means something huh?
<LordBrain>
oh no it doesnt
<LordBrain>
hmm
<LordBrain>
nifty
<LordBrain>
Do you guys think ocaml would be a good first language for someone?
Shammah has joined #ocaml
<LordBrain>
anyone use vim?
<yella>
i do..
<LordBrain>
have any ocaml scripts?
<yella>
scripts?
<LordBrain>
for vim
<LordBrain>
i'm thinking it would be nice if control-k grepped the headers for the word on the cursor, and opened it in a new window at the right spot.
<yella>
nope, no such scripts
<LordBrain>
hmm there is ocamldoc tho, i never tried that
<LordBrain>
is ocamldoc like perldoc?
<LordBrain>
oh no.. it looks like its for generating documentation for my software
bk_ has quit ["I'll be back"]
bk_ has joined #ocaml
vegai has quit ["ytimessä on roimaa alkuvoimaa"]
gl has quit [Read error: 60 (Operation timed out)]
bk_ has quit ["I'll be back"]
wazze has joined #ocaml
Shammah has quit ["ChatZilla 0.9.35 [Mozilla rv:1.5/20030925]"]
Dybbuk has joined #ocaml
<Dybbuk>
Howdy folks!
<Riastradh>
Hi.
gl has joined #ocaml
mattam_ has joined #ocaml
drWorm has quit [Read error: 113 (No route to host)]
reltuk has joined #ocaml
reltuk has quit [Client Quit]
buggs has quit [Read error: 104 (Connection reset by peer)]
mattam has quit [Read error: 110 (Connection timed out)]
buggs has joined #ocaml
<Dybbuk>
Grrr. My code is only passing its tests /sometimes/. Why did Barbie make math so hard?
cjohnson has joined #ocaml
<malte>
uhm. is there no way to use the Thread module in the interpreter?
<malte>
i mean: how does one use the Thread module in the interpreter? :)
mattam_ is now known as mattam
<Dybbuk>
malte: You might need to use 'ocamlmktop' to compile a new toplevel with the threading code linked in?
<malte>
i was hoping i could do a #load "somefile"
<malte>
but i dont seem to find the appropriate file :/
<Smerdyakov>
I can do: #load "vmthreads/threads.cma";;
<Smerdyakov>
But I get a runtime error.
<malte>
:)
<Banana>
you need to use the special flag -thread, no ?
<Banana>
ocamlmktop -o mytop -thread unix.cma threads.cma should do the trick.
<malte>
with ocamlmktop?
<Banana>
yes.
<malte>
oh! thanks :)
<Banana>
you're welcome.
<Banana>
hello, world, by the way.
<malte>
hello :) hm, i still seem to get "Unbound value Thread.create" with the new toplevel
<Banana>
yeah i see... that's strange...
<yella>
how would you compare two complex, recursive datatypes for their similarity?
<Banana>
in a way that is not to expensive ?
<yella>
well..this would be an extra. i'm already happy if it works
<yella>
actually the problem I see is to compare the constructors itself and not only their values...
<Banana>
what kind of data type more precisely ?
<yella>
an abstract syntax tree..
<Banana>
you want to compare to abstract syntax tree ?
<yella>
well of course not complete trees. parts of them
<Banana>
and si if one is subtree of another or things like that ?
<yella>
well yes. check for their similarity. similar procedure to 'clone detection', if you know what that is..
<Banana>
well can't you use a hash function ?
<Banana>
(it's a bit rough i know).
bk_ has joined #ocaml
<Banana>
you compute the hash of a subtree and you see if it matchs with hash of other trees of the same size.
<yella>
no since I'm not expecting to meet an _exact_ same subtree
<Banana>
of course...
bk_ has quit [Client Quit]
<yella>
a hashing functions which contains proximity in near-miss values would be nice though :)
bk_ has joined #ocaml
<Banana>
:)
<Banana>
does this exists ?
<yella>
only in my mind heh. but for these kind of usage it would be useful..
<Banana>
well i just found a paper about clone detection using AST.
<yella>
actually Hashtbl.hash does not even care about what constructors you are using ..
<yella>
Hashtbl.hash (F1(S1(L1(10))));;
<yella>
- : int = 10
<yella>
Hashtbl.hash (F1(S1(L1(11))));;
<yella>
- : int = 11
<Banana>
They say that indeed hash is to be used when you look for equivalence and not similarities...
<Banana>
for similarities they use an euristic
<yella>
hm what paper is this? Baxter,Yahin 'clone detection using ast' ?
<Banana>
yep.
<Banana>
first one googlising...
<yella>
yep :)
<yella>
they don't really describe the functions they are using in their algos..
<Banana>
like always they give a general formula and say "it works well in our implementation".
<Banana>
(and they don't say the implementation has been tweaked to death).
mfurr has joined #ocaml
<yella>
If CompareSequences(i,j,k) > SimilarityThreshold Then { ..
<yella>
tsss.. heh
<LordBrain>
is there a module to do infinite precision floats?
<LordBrain>
er well infinite precision numbers
<Banana>
in the standard distribution you have the num library
cjohnson has quit ["Drawn beyond the lines of reason"]
<LordBrain>
hmm
<LordBrain>
i dont see a num.mli in my /usr/lib/ocaml/3.07
<Banana>
got debian ?
<LordBrain>
yeah
<Banana>
;)
<Banana>
num library has been removed due to licencing problem.
<Banana>
(basically the licence of the num library as been lost during the takeover of Compaq by HP)
<LordBrain>
oh shucks
<LordBrain>
that sucks
<mfurr>
there is the numerix library that implements Big_nums though which is now in debian
<Banana>
you might want to look at JC Filliatre Creal library
<mfurr>
also, I'm getting ready to upload creal
<mfurr>
:)
<Banana>
yes and numerix too.
<Banana>
the core team is reemplementing bignum but I don't know if it made its way through CVS yet or not.
<mfurr>
its my understanding is that the debian numerix package is based on that implemention in cvs
<LordBrain>
ok
<LordBrain>
hmmm
<LordBrain>
anyone here use libnumerix-ocaml package on debian?
<LordBrain>
i installed it.. but it doesnt seem to have made the num.cma file anywhere
mijdrol has quit [Remote closed the connection]
<Banana>
try libnums-ocaml
<Banana>
and libnums-ocaml-dev
<LordBrain>
it installed libnums-ocaml
<LordBrain>
oh getting the dev package
<LordBrain>
aha that did it
<Banana>
libnums-ocaml is the cvs version of the num library.
<Banana>
which is free.
<LordBrain>
hmm, i'm getting "Reference to undefined global `Num'"
<LordBrain>
it lets me open it.. but when i try to use it i get an error
<mfurr>
how are you linking?
<LordBrain>
well i was just saying use Num;; in the top level interpretter
<LordBrain>
hmm i tried so much stuff now i forgot if i did a #load
<LordBrain>
er not use.. open
<Banana>
ocamlmktop -o mytop nums.cma
<Banana>
it work just fine.
<Banana>
works.
<LordBrain>
ah i got it now
<LordBrain>
i never used ocamlmktop
<LordBrain>
in fact, i am sort of gleaning a lot, like what the extensions mean and stuff
<LordBrain>
all the tutorials and docs i read are on the language, not on the tools so much....
<Banana>
the manual is still the best for that.
<Banana>
there is a tool section with the basics on ocamldebug, ocamlmktop,...
<LordBrain>
ah ok
<LordBrain>
i looked at the manual some, but not that section i guess
async has joined #ocaml
andrewb has quit [Ping timeout: 14400 seconds]
LittleDan has joined #ocaml
<LittleDan>
Why is the convention for the main section of a program in ocaml to do
<LittleDan>
let _ = (*code*)
<LittleDan>
and not
<LittleDan>
begin (*code*) end
<LittleDan>
?
<mfurr>
my guess would be because "let _ = (*code*)" is only valid in the global scope, not inside a f'n
<LittleDan>
I don't understand why that matters
<mfurr>
consider: let f x = f begin 4 end
<Dybbuk>
Um...
<mfurr>
where does the f'n end?
<malte>
is "let _ = " really necessary? cant one just do a main () in the end of the file?
<Dybbuk>
What's the modulo operator in OCaml? I thought it was mod?
<mfurr>
it is mod
<Dybbuk>
Ok, then why is "(-9 * 120) mod 23" returning -22?
<LittleDan>
malte: Sometimes you don't want to put main in a function
<mfurr>
Dybbuk: what were you expecting it to return?
<malte>
LittleDan, hm, what do you mean?
<Dybbuk>
mfurr: 1
<Dybbuk>
Hmmm...
<Dybbuk>
I am not sure what's going on. Lisp does this: (mod (* -9 120) 23) => 1
<LittleDan>
malte: I mean sometimes you want to do something like
<LittleDan>
let _ =
<LittleDan>
do_something ()
<LittleDan>
do_something_else ()
<LittleDan>
malte: without making it into a function
<malte>
ah. why? :)
<LittleDan>
Every piece of OCaml code I've seen does that, and it makes things shorter
<malte>
ok.. i've seen: let _ = main () sometimes
<malte>
but that seems unnecessary perhaps
<LittleDan>
it's because the convention is to put the main section after let _ =
<LittleDan>
so it's more readible
<mfurr>
Dybbuk: I'm not sure what the correct behavior is... I"ve always though of a mod b => Ex st bx-a = 0
<Dybbuk>
mfurr: I don't understand your notation there. What's "Ex" and "st"?
<mfurr>
Exists x such that
<Dybbuk>
mfurr: Hmm...even perl thinks it's 1. And you know it's a bad day when Perl and Lisp agree on something. :)
<mfurr>
lol
<Dybbuk>
perl -e 'print ((-9 * 120) % 23) . "\n"'
<LittleDan>
1
<Dybbuk>
Yeah.
<LittleDan>
but for some reason it didn't make a newline
<Dybbuk>
I thought modulo was this: a mod b => Ex st (a / b) * a + x = b
<mfurr>
I actually mean on mine: a mod b = c => Ex bx + a = c
<Dybbuk>
Hmmm...
<mfurr>
the perlop manpage explains its hackish ways
<LittleDan>
I thought it was (prothon) a mod b => b*((a/b)-(a//b))
gim has quit []
<LittleDan>
in ocaml there are tons of annoying type conversions for that
<mfurr>
whats '//'?
<LittleDan>
floor division
<Dybbuk>
Hmmm.
* mfurr
wishes IRC understood LaTeX
<Dybbuk>
So how can I get 'mod' to do what I expect? :)
<LittleDan>
mfurr: That's on the client end, not the protocall
<LittleDan>
*protocol
<mfurr>
fair enough
<LittleDan>
What do you want mod to do in this case?
<mfurr>
Dybbuk: you could wrap it to check for negative operands
<Dybbuk>
LittleDan: I want it to return the same thing Lisp, Perl, and the world of mathematics expect it to return. :)
<LittleDan>
Since Lisp and Perl disagree, I'm not sure that's possible
<LittleDan>
The world of mathematics expects it to be the remainder of a/b, I think
Alain_ has joined #ocaml
<Dybbuk>
No, Lisp and Perl agree. Both say it's 1.
<LittleDan>
I thought you said Lisp said it was -1
<Dybbuk>
And -9 is /supposed/ to be the multiplicative inverse of 120 mod 23, which only works if (-9 * 120) mod 23 is 1.
<Dybbuk>
LittleDan: No, it said 1.
* Dybbuk
is trying to compute multiplicative inverses.