<vixey>
jonafan: you now what ocaml is strict and has side effects
<vixey>
jonafan: How are you interpreting the scheme code?
<flux>
btw, laziness and side effects don't mix either, it can be a nightmare to debug code where a + b causes some other code to be executed (versus !!a + !!b)
<jonafan>
i am using ocamllex and ocamlyacc to translate to my ocaml variant type
<vixey>
I don't know what that variant type is
<vixey>
are you going to put all your code online?
<asmanur>
hm... it's not possible to read a printf-format from a non-litteral string ?
<jonafan>
let expr = Int of int | None | If of expr * expr * expr | Fun of string list * expr | Application of expr * expr list | etc ...
<vixey>
yeah jonafan
<vixey>
You could probably use HOAS and get a faster interpreter than rewriting directly
<jonafan>
i think it's actually kind of wrong because i also have like Plus of expr * expr as an expression, but scheme doesn't do it like that
<jonafan>
HOAS?
<vixey>
instead of Fun of string * expr, you can have Fun of (expr -> expr)
<vixey>
if you are interested in it this is a good example
mishok13 has quit [Read error: 131 (Connection reset by peer)]
<jonafan>
the example i'm learning from actually compiles ml
<vixey>
are you writing a compiler
<jonafan>
well, it doesn't ACTUALLY compile, it just kind of has it's own instruction lists that it converts to
<jonafan>
like bytecode i guess
<vixey>
on the pl zoo?
<jonafan>
yeah
<vixey>
I've seen that
<vixey>
that is definitely called compiling
<jonafan>
do you think that sort of thing is a good idea here?
<vixey>
I think you should check the HOAS thing I linked
<vixey>
it's so neat
<jonafan>
my tests seem to indicate that doing that is much less efficient if you're going to run inside ocaml
<jonafan>
however, i also adapted that to output assembly code, which was cool
<jonafan>
(very inefficient assembly code)
<Jeff_123>
Whats a good source for learning to write compilers? I've always wanted to know how, and I know some MIPS assembly.
vbmithr has joined #ocaml
<vixey>
I don't know any assembly
<jonafan>
it's constantly popping stuff on the stack, only to immediately pop them off and use them
<jonafan>
er pushing stuff on the stack
<vixey>
Jeff_123: I like this book Compiling with continations by Appel, and Marc Feeleys thing about compiling scheme in 90 mins is worth looking at
vbmithr_ has quit [Read error: 104 (Connection reset by peer)]
<vixey>
jonafan: is that the sort of thing a peephole optimizer fixes?
<jonafan>
i have no idea
<Jeff_123>
thinks vixey, I'll look into it
<jonafan>
i scanned of the wikipedia article
<jonafan>
i don't think it would help much here
<Jeff_123>
Oh sweet it's written in an ML language
<jonafan>
well, maybe
ChristopheT has joined #ocaml
ChristopheT has left #ocaml []
bluestorm has joined #ocaml
Axioplase_ is now known as Axioplase
marmotine has quit ["mv marmotine Laurie"]
redocdam has joined #ocaml
munga has quit [Read error: 110 (Connection timed out)]
_andre has joined #ocaml
<_andre>
i have this function that returns an array of keys from a hash
<_andre>
let keys h = let keys = Hashtbl.fold (fun k _ ks -> k :: ks) h [] in Array.of_list keys
<_andre>
can anyone think of a way to do that without creating the intermediate list?
<_andre>
(and keeping the function polymorphic :)
Linktim has joined #ocaml
<flux>
I see a way, but it's full of evil and I would never do it :). constructing an array of the proper length default-initialized by using Obj.magic, and then replacing the elements one by one with Hashtbl.iter
<_andre>
let me know it so i.. uhm.. won't use it :P
<flux>
call/cc could fit in here, although I doubt it would be any better performing soltuion
<flux>
so you have a performance problem related to doing that?
<_andre>
nah, it's just curiosity
<bluestorm>
_andre: you could use a 'a option array, and then map it to an 'a array after filling
<flux>
would that work with unboxed types?
<bluestorm>
hm ?
<flux>
or did you mean plain Array.map
<bluestorm>
yes
<_andre>
but that would still require walking over the data twice, no?
<flux>
nevertheles, it could still be faster
<bluestorm>
that would require manual unboxing and handling the error case
<bluestorm>
(wich won't happen)
<bluestorm>
hm
<bluestorm>
another solution would be have an 'a array ref
<bluestorm>
then you iter, and on the first element you change it to a array of the correct length
<bluestorm>
this should be quite fast and is typesafe
<bluestorm>
haha mfp
<mfp>
could remove the ugly thing to get a random key by using Obj.magic (also ugh)
<bluestorm>
that one is evil
<flux>
whoa
<flux>
:)
<mfp>
plus
<mfp>
it's not guaranteed to be faster than lists
<flux>
but it's nicer than the using Obj.magic
<mfp>
esp. if the array is allocated in the major heap
<mfp>
because of caml_modify
Kopophex has joined #ocaml
<flux>
the thing is that that solution still walks over the region twice: once to initialize, second time to fill in
<mfp>
it's probably faster up to 256 words or so (IIRC the limit for blocks in the minor heap)
<mfp>
yeah
<flux>
I wonder how Array.init does it
<mfp>
I don't see any way to avoid the double assignment here
<flux>
but one can't really compose a function with Hashtbl and Array.init
<flux>
(without continuations or threads)
<mfp>
probably inits to 0 (like Obj.magic 0, or in C)
<flux>
I suppose it must. but it will likely be fast, although Array.make would not likely be much (or any) slower
<bluestorm>
flux: hm
<flux>
walking a list can still be quite slow compared to walking an awway
<flux>
array :)
<bluestorm>
it's not a two-walk way as the first walk is promptly interrupted
<flux>
bluestorm, I meant the destination
<bluestorm>
ah
<bluestorm>
Array.init is two-walk too
<mfp>
it *must* be, you cannot run OCaml code with an uninitialized block around
<flux>
apparently Array.init uses a similarish approach
<flux>
as in: let init l f = if l = 0 then [||] else let res = create l (f 0) in for i = 1 to pred l do unsafe_set res i (f i) done; res
<flux>
so doing that youself should not be slower in any case
<flux>
(except you're unlikely to use unsafe_set without much self-confidence)
<mfp>
I sometimes wish the runtime didn't use a list for the remembered set
marmotine has joined #ocaml
<mfp>
(well, a resizable array to be precise)
<flux>
the remembered set?
<mfp>
the references to values in the minor heap from blocks in the major heap
TypedLambda has joined #ocaml
<mfp>
hmm I wonder if things like Array.copy would benefit from some manual loop unrolling
<mfp>
flux: the problem being that updating the same reference repeatedly results in the pointer being added many times to the remembered set
<mfp>
so you have to realloc the buffer, etc.
<mfp>
if it used a card marking sys for instance, that'd be no problem, and caml_modify could be faster
<mfp>
traversing the remembered set would be: faster if there have been many updates to the same reference, slower if the updates are spread throughout the major heap (?)
OChameau has quit ["Leaving"]
ofaurax has joined #ocaml
LordMetroid has joined #ocaml
asmanur has quit [Remote closed the connection]
netx has joined #ocaml
philip has joined #ocaml
sporkmonger_ has joined #ocaml
sporkmonger has quit [Read error: 104 (Connection reset by peer)]
filp has joined #ocaml
mishok13 has joined #ocaml
netx has quit ["This computer has gone to sleep"]
netx has joined #ocaml
tomh has joined #ocaml
Axioplase is now known as Axioplase_
Snark has quit ["Ex-Chat"]
Associat0r has joined #ocaml
Snrrrub_ has joined #ocaml
Snrrrub_ has quit [Read error: 104 (Connection reset by peer)]