<pippijn>
I could just add yet another function to get the location
<pippijn>
adrien: maybe location * ast is not bad
<adrien>
as far as I see (or try to see), you only have the "Nothing" case that doesn't have a location; if you could change that, you could move location out of the tuples
<pippijn>
yes, correct
<adrien>
(maybe by giving an invalid location if you can't see a better way)
<pippijn>
is it generally recommended to add annotations like that?
<adrien>
annotations like what?
<pippijn>
"like that" as in "in that way"
iago has joined #ocaml
<pippijn>
using * types outside instead of putting the annotations into the AST definition
ftrvxmtrx has quit [Ping timeout: 276 seconds]
<pippijn>
for example, I will have a typeinfo attached to every node, later
<pippijn>
should I have typeinfo * ast or should I put the typeinfo into the ast nodes?
<adrien>
you don't really have the choice most of the time and it would be good if you could split the big type a bit more
<f[x]>
you can use polymorphic records to have different annotation on different stages
ftrvxmtrx has joined #ocaml
<f[x]>
like type 'a t = { extra : 'a; ast : ast; }
<pippijn>
hmm
<pippijn>
right
cdidd has quit [Ping timeout: 248 seconds]
eikke has joined #ocaml
antegallya has quit [Ping timeout: 248 seconds]
<pippijn>
f[x]: ast is recursive, so I need to make ast contain 'a t?
<f[x]>
probably
cdidd has joined #ocaml
antegallya has joined #ocaml
letrec has joined #ocaml
n25 has joined #ocaml
<pippijn>
f[x]: this is making all my code super ugly :
<pippijn>
f[x]: everything needs to take care of the extra stuff
<pippijn>
:(
<pippijn>
I'll keep the location inside and annotate with stuff ad-hoc, I think
<iZsh`>
is menhir supposed to support polymorphic variants ?
avsm has joined #ocaml
<iZsh`>
pippijn: I recently changed my ast (which looked like yours for the locations) to use a "traits" type, such that I can support location but also type annotation or any annotation
<pippijn>
iZsh`: traits?
<iZsh`>
a set of trait :P
<pippijn>
ah
<pippijn>
and trait is a polymorphic datatype?
<iZsh`>
type trait = Location of .. .| Ty of .. | … (or you could use polymorhic variants, but menhir didn't let me)
<pippijn>
right
<pippijn>
ok
<pippijn>
that's good
<pippijn>
I think I will do that
<iZsh`>
that way you can have traits_of_ast
<iZsh`>
and then a bunch of helper function to extract a given trait, replace it etc.
<pippijn>
keeping stuff outside is too noisy
<iZsh`>
also, your ast is very.. flat to my taste, why dont you use stuff like ast * binop * ast etc. ?
<pippijn>
yeah..
<pippijn>
because it's a parse tree
<iZsh`>
well it's an AST :)
<pippijn>
it's pretty concrete
<pippijn>
it has all the tokens in it
<pippijn>
I think I will transform it into an abstract tree, with binop and such
<pippijn>
and later transform it back
<iZsh`>
why dont you generate an AST directly?
<pippijn>
because the tool I get it from expects a parse tree as sexpr
<pippijn>
this ocaml program acts as a filter
<iZsh`>
well dunno who coded the frontend then, but it's not pretty :P
<iZsh`>
I've never seen anyone generating something so flat
<pippijn>
the frontend is very basic
<iZsh`>
I dont really understand what the tool gained by doing so
<pippijn>
I already have a proper parser and everything I need
<pippijn>
this time, I wanted to see what I can do with a parse tree instead of an AST
<iZsh`>
what do you gain from it?
<pippijn>
iZsh`: the advantage is that I can output the original source 1:1
<iZsh`>
I can too
<pippijn>
because I know the original location of every token
<iZsh`>
if your ast is properly defined you can output the original source
<pippijn>
you don't know where the binop was
<iZsh`>
oh you mean, like an exact location, with the space and all
<pippijn>
yes
<iZsh`>
why would it matter?
<pippijn>
I don't know :)
<iZsh`>
(actually binop could still have a trait, but mehhhh :P )
<pippijn>
I'm just doing this for fun
<iZsh`>
a real AST is easier to work with imho :)
<pippijn>
sure
<pippijn>
but I've done that more times than I can remember
endre_ has joined #ocaml
Tobu has quit [Remote host closed the connection]
Tobu has joined #ocaml
endre_ has left #ocaml []
avsm has quit [Quit: Leaving.]
iago has quit [Quit: Leaving]
iago has joined #ocaml
Tobu has quit [Ping timeout: 260 seconds]
Tobu has joined #ocaml
oriba has joined #ocaml
oriba_ has joined #ocaml
oriba has quit [Ping timeout: 248 seconds]
eikke has quit [Read error: Operation timed out]
oriba_ has quit [Quit: oriba_]
maufred_ has joined #ocaml
<Ptival>
I have three levels of work (a whole executable, a source file, and a particular function), and I need to process them while some information flows
<Ptival>
the problem is, there are some pieces of information that are global to the executable, and need to flow through everything
<Ptival>
but there are some other that are specific to a "file", or a "function"
maufred has quit [Ping timeout: 272 seconds]
<Ptival>
I tried to have a record for exe_info, a record for file_info that include an exe_info, and a record for fun_info that included a file_info
<Ptival>
but then when I need to access/update the exe_info while processing a function, I have to cross all these indirections...
int_ has quit [Ping timeout: 252 seconds]
<Ptival>
{my_fun_info with file_info = { my_fun_info.file_info with exe_info = { my_fun_info.file_info.exe_info with field = ... } } }
<Ptival>
is there something I _should_ use?
<Ptival>
the easiest solution right now seems to have exe_info, (exe_info * file_info), and (exe_info * file_info * func_info)
<pippijn>
You've been redirected to this login page because you have tried accessing a page that was not available to you as an anonymous user.
int_ has joined #ocaml
eikke has joined #ocaml
avsm has joined #ocaml
vivanov has joined #ocaml
<vivanov>
when using output channels, i need to flush frequently otherwise the channels will occupy all memory, right ?
<Drakken>
Ptival two questions: (a) is accessing really so bad? and (b) is there some reason you can't just write a constructor for updates?
<djcoin>
adrien: I saw jingoo is the port of jinja of ocaml, you are making an OCaml browser and so on. Those are great projects, how do you manage do work on those ?
<djcoin>
s/do/to
<Ptival>
Drakken: (a) I don't understand your question, (b) in my representation, I would actually need 3 updaters per field of the exe_info record (depending on from what level you try to update), etc.
<adrien>
djcoin: I don't do anything with jingoo: I saw it mentionned in the caml weekly news which in turn fetched it from planet.ocamlcore.org
<djcoin>
oh ok
<adrien>
I wanted to see more but ...
<djcoin>
adrien: and well, im still curious, do you program in OCaml for your living ?
<djcoin>
:)
<adrien>
no, although I wish; I'm a student who is taking some holidays :P
<djcoin>
adrien: :) nice ! Why did you choose ocaml ?
<djcoin>
may i ask ! :)
<pippijn>
where can you find ocaml jobs?
<pippijn>
I started ocaml yesterday
<pippijn>
so I don't want to start a job in it
<pippijn>
but I like it so far
<Drakken>
Ptival (a) I mean all you have to write is fun_info.file_info.exe_info.field. no withs or double references to fields.
<djcoin>
For myself, I started Ocaml a few days ago ; but its because I feel it may be the right way to go rather than Python, JavaScript /Node.js
<adrien>
djcoin: I started it because of studies
<pippijn>
I started it because of pattern matching
<Ptival>
Drakken: I need updating
<adrien>
I think what really motivated me was mldonkey: few developpers; great software; outperforms the competition by a huge margin
<pippijn>
first I tried scheme, but it was incredibly slow and died for nesting deeper than 244
<adrien>
and stable and fast
<pippijn>
(mz scheme)
<adrien>
since I had liked it and had also enjoyed the static typing, I started using it for my own stuff
<djcoin>
And well, I want to have time to develop in OCaml to use it in Web stuff or other thing; Node.JS is great, will be hard to compete with in the Web sphere, but well, javascript even if I do like it a lot, will not be a substainable solution anyway
<djcoin>
All right
<djcoin>
And what is your goal ? Make a browser in OCaml ?
<adrien>
my goal is that a tool I use all-day long and everyday doesn't suck like all browsers currently available and alive do :P
<pippijn>
adrien: how does a donkey outperform other donkeys?
<pippijn>
in what way?
<Drakken>
Ocaml is the best language in the world for large-scale software development.
<pippijn>
I don't quite understand its module system, yet
<pippijn>
I mean, I don't get it at all
<pippijn>
but I've read 5% of 1 tutorial, so that's ok
<adrien>
emule had been plagued by security issues, it used more memory, cpu and didn't have the same server-client modle (mldonkey runs headless and graphical clients connect to it)
<adrien>
and with far fewer developpers, mldonkey had more features, was more stable and was faster
<pippijn>
ah
<pippijn>
making a program in ocaml more stable than a program in C is almost default, I think
<adrien>
pippijn: I think that it takes some time before the module system starts appearing as useful
<adrien>
emule is worse: C++ :P
<adrien>
(iirc)
<pippijn>
C++ can be better than C
<pippijn>
but is generally not
<pippijn>
but not because of the language
<pippijn>
but rather because of the developers
<adrien>
I'm wondering if they weren't doing C-style C++
<flux>
wish donkey was more modular. I once tried to pinch its bittorrent parsing functions out of it, it was a pain in the behind.
<djcoin>
Drakken: im okay with that ! no Gc yet so good performance + type checking ; really awesome for large scale dev
maufred_ has quit [Ping timeout: 244 seconds]
<djcoin>
GC i mean
<djcoin>
s/no//
maufred has joined #ocaml
<djcoin>
I want hard to program in ocaml
<pippijn>
adrien: how well do you know ocaml?
<djcoin>
ahem; lets return to django/python
<pippijn>
do you know how it optimises the code?
<pippijn>
do you know roughly what machine code comes out of your ocaml code?
<adrien>
half-well; there's still a lot of things that I don't know; as for optimization: almost nothing but the generated code is not dumb either
<adrien>
and you have the -S switch to ocamlopt to look at the generated assembly ;-)
ankit9 has quit [Quit: Leaving]
<pippijn>
I can always objdump the executable
<pippijn>
I know what machine code my C++ compiler generates for the things I do
<pippijn>
and I know what C code is executed for things in perl
<Drakken>
If you really need runtime performance, Mlton is supposed to be good.
<adrien>
the main rule with ocaml is that it doesn't go to great lengths to optimize your code
<pippijn>
I like to know what things cost
<adrien>
so you get what you write
<pippijn>
so when I do AST transformations and untouched nodes are copied, they are copied
<pippijn>
so every mutating run through the AST will clone the entire tree
<adrien>
it will share when you write code that shows there is something to share
n25 has quit [Quit: Leaving]
<flux>
pippijn, hmm, of course when you copy roots of whole trees, you only copy the root, not the whole tree
<pippijn>
I actually clone the entire tree every time
<flux>
pippijn, well, at least 'loc' contents are shared, unless it's a plain integer ;)
<pippijn>
that's a record, yes
Tobu has joined #ocaml
<pippijn>
how should I do this?
<pippijn>
better to have mutable fields?
<flux>
I would prefer immutable structures for those
<flux>
because it appears you are walking through everything in any case
<pippijn>
yes
maufred_ has joined #ocaml
maufred has quit [Ping timeout: 276 seconds]
vivanov has quit [Quit: leaving]
Kakadu has quit [Quit: Page closed]
yroeht has quit [Ping timeout: 272 seconds]
smondet has joined #ocaml
yroeht has joined #ocaml
<pippijn>
flux: it take 7.3 seconds to load the s-expressions (sexprlib), turn them into ocaml objects, turn them back into s-expressions and print them
<pippijn>
flux: all that + doing 3 transformations that copy all the nodes takes 7.4 seconds
<iZsh`>
bytecode or native?
<pippijn>
native
<pippijn>
it's a large file
<flux>
pippijn, how many cpu seconds?
<flux>
7.3?
<pippijn>
./xform >| /dev/null 6.99s user 0.38s system 99% cpu 7.433 total
<iZsh`>
i used to look at ocaml's assembly a lot. i find frustrating there isn't a wiki about it :P
<thelema>
iZsh`: start one
<flux>
pippijn, perhaps you can make use of gprof to find out the easiest points to optimize
<iZsh`>
thelema: i'm the worst sysadmin ever :P
<pippijn>
I do almost nothing
<flux>
pippijn, I'm however guessing it's not the tree walking, but rather the s-expression manipulation..
<thelema>
iZsh`: so don't host it yourself.
<thelema>
iZsh`: maybe ask for some space in the inria wiki
<pippijn>
flux: loading takes 2.5 seconds
ikaros has quit [Quit: Ex-Chat]
<thelema>
err, not inria wiki, gallium wiki
<iZsh`>
thelema: what i meant is that it would take me forever because then i would start tuning the wiki template and stupid thing like that instead of adding content :P
<adrien>
I don't think that ocaml likes huge match statements
<adrien>
it's going to be a huge if ... then ... else if ... then ... else if ...
<pippijn>
I think especially the string matches will be bad
<iZsh`>
w
<adrien>
I can't say this is why your code is slow but it doesn't look terribly good to me; plus it's hard to reread
<pippijn>
maybe it's faster if I sort them by probability
<iZsh`>
cant you just profile the code?
<flux>
but, it was the transformation that was the fastest piece of all?
<adrien>
pippijn: it will definitely be
<iZsh`>
adrien: do you know that for a fact?did you look at the assembly?
<pippijn>
flux: yes, that's what I wanted to know, and that's nice
<pippijn>
the sexpr_of_pt should be a simple switch
<iZsh`>
cant remember how it looked like when i checked years ago, but i didnt keep a bad impression about the generated code for the pattern matching
<pippijn>
since the data type is limited
<pippijn>
pt_of_sexp is a lot of string compares
<flux>
pippijn, if you really want speed, perhaps it would be faster to directly generate the serialized sexp string output instead of first creating sexp and then creating the string..
<pippijn>
flux: yeah
<iZsh`>
IIRC it was doing if then… for small matches and turned it into table for large ones, but maybe i mis-remember
<pippijn>
flux: but I don't really want speed, so it's ok
<pippijn>
for now
<thelema>
pattern matching can take a while to compile, but is generally pretty good. that said, there's some tricks that I doubt the ocaml compiler uses for string matching that could be done here.
<pippijn>
I'm still learning, not optimisin
<flux>
another would be to use processes in a pipelining fashion. too bad threads won't help here..
<pippijn>
thelema: it could make a perfect hash :)
<iZsh`>
pippijn: if you really want speed you need to profile the code, otherwise you're just blindly optimizing stuff which might not even be the issue
<thelema>
s/is generally pretty good/produces good runtime code/
<pippijn>
iZsh`: sure
<flux>
I mean, to make use of the multiple CPUs you probably have
<pippijn>
I'm not really optimising
<iZsh`>
pippijn: you're still trying to understand where the time is going
<adrien>
iZsh`: matches over a variant with something like 15 values or less is done with a jump and otherwise it's the if then else if ... stuff if I read the assembly well a couple of months ago
<thelema>
pippijn: there's some trie variants that do really well
<pippijn>
adrien: it makes jump tables for *few* elements?
<iZsh`>
adrien: funny, I remember the opposite, but I checked like 10 years ago
<pippijn>
that doesn't make sense
<iZsh`>
exactly :)
<pippijn>
I'm pretty sure gcc generates jump tables for many elements (in a small range)
<adrien>
hmmm, I don't remember well; I only remember the limite of 15 or so since I was looking for something completely different
<thelema>
drat, I can't remember the name of the technique, but there was some lexer that generated code to match a set of strings by finding specific characters at specific offsets that could be tested for to minimize the number of character comparisons needed. It would build a series of nested if statements to implement this logic