smerz has quit [Remote host closed the connection]
agordonfreeman is now known as alexgordon
lopex has quit []
mfp has quit [Ping timeout: 246 seconds]
arubin has joined #ocaml
wtetzner has quit [Remote host closed the connection]
mfp has joined #ocaml
Associat0r has quit [Quit: Associat0r]
Transformer has joined #ocaml
Transformer has quit [Excess Flood]
boscop has joined #ocaml
wtetzner has joined #ocaml
raphscallion has quit [Quit: raphscallion]
eye-scuzzy has joined #ocaml
ymasory has quit [Quit: Leaving]
philtor has quit [Ping timeout: 240 seconds]
Amorphous has quit [Ping timeout: 240 seconds]
Amorphous has joined #ocaml
ulfdoz has joined #ocaml
arubin has quit [Quit: arubin]
hto_ has joined #ocaml
hto has quit [Ping timeout: 240 seconds]
mneedham has joined #ocaml
eelte has quit [Ping timeout: 240 seconds]
Associat0r has joined #ocaml
ygrek has joined #ocaml
myu2 has quit [Remote host closed the connection]
mneedham has quit [Ping timeout: 260 seconds]
mneedham has joined #ocaml
joelr has joined #ocaml
ygrek has quit [Ping timeout: 246 seconds]
Yoric has joined #ocaml
zubeen has quit []
Skolem has joined #ocaml
<Skolem>
I'm having trouble figuring out the syntax for 'open'. I expect this one-line program (open Int64 print_endline "K") to print "K" when I run it with "ocaml test.ml", but instead I get ``File "test.ml", line 1, characters 11-24: Error: Syntax error'' What am I doing wrong?
<adrien>
(I can't explain the rules properly early in the morning however)
<flux>
but I can!
<flux>
skolem, a file consists of parts of code, which are separated with ;;
<flux>
skolem, each part is either an expression or a list of statements
<flux>
(make it parts=blocks and it sounds better)
<flux>
we should have an infobot here. xavierbot could do.
<flux>
(xavierbot with persistency)
impy has quit [Ping timeout: 250 seconds]
ocp has joined #ocaml
Associat0r has quit [Quit: Associat0r]
coucou747 has joined #ocaml
eikke has joined #ocaml
ikaros has quit [Quit: Leave the magic to Houdini]
caligula has quit [Ping timeout: 240 seconds]
caligula has joined #ocaml
gildor has quit [Quit: leaving]
explodus has quit [Ping timeout: 276 seconds]
coucou747 has quit [Ping timeout: 260 seconds]
explodus has joined #ocaml
thomasga has joined #ocaml
jamii has joined #ocaml
raphscallion has joined #ocaml
larhat has joined #ocaml
hto has joined #ocaml
andreas1 has quit [Ping timeout: 250 seconds]
kaustuv_afk is now known as kaustuv
Snark has joined #ocaml
mfp has quit [Ping timeout: 240 seconds]
eelte has joined #ocaml
raphscallion has quit [Remote host closed the connection]
raphscallion has joined #ocaml
mfp has joined #ocaml
avsm has joined #ocaml
edwin has joined #ocaml
gildor has joined #ocaml
jamii has quit [Ping timeout: 276 seconds]
eelte has quit [Read error: Operation timed out]
jamii has joined #ocaml
andreas has joined #ocaml
Yoric has quit [Quit: Yoric]
f[x] has quit [Ping timeout: 252 seconds]
f[x] has joined #ocaml
zorun has quit [Ping timeout: 240 seconds]
avysk has joined #ocaml
ulfdoz_ has joined #ocaml
ulfdoz has quit [Ping timeout: 248 seconds]
ulfdoz_ is now known as ulfdoz
ygrek has joined #ocaml
lopex has joined #ocaml
_andre has joined #ocaml
roconnor has joined #ocaml
<roconnor>
Question about value recursion in ocaml...
<roconnor>
I'm trying to write a function to convert lists into doubly linked lists:
<roconnor>
type 'a dlist = Dnil | Dnode of 'a dlist *'a *'a dlist;;
<roconnor>
let listToDList l = let rec go l h = match l with [] -> Dnil | (x::xs) -> let rec r = Dnode (h,x,go xs r) in r in go l Dnil;;
<roconnor>
However I get an error at "let rec r = Dnode (h,x,go xs r) in r" saying
avsm has quit [Quit: Leaving.]
<roconnor>
Error: This kind of expression is not allowed as right-hand side of `let rec'
<roconnor>
Is it possible to write a function to convert lists into doubly linked lists?
<rixed>
roconnor: "let rec r = Dnode (h,x,go xs r)" in what order is this supposed to be evaluated? all parameters to go are supposed to be evaluated before the call to go, yet you need the result of go to build r :-/
<roconnor>
ah of course ...
<ocp>
roconnor: either you use lazy somewhere, or you have to create a mutable record somewhere
* roconnor
tries to figure out how to use lazy around r
<roconnor>
let rec r = Dnode (force h,x,go xs (lazy r)) in r still is an error :(
<roconnor>
in
<roconnor>
let listToDList l = let rec go l h = match l with [] -> Dnil | (x::xs) -> let rec r = Dnode (force h,x,go xs (lazy r)) in r in go l (lazy Dnil);;
<rixed>
ocaml
<rixed>
^ was destined to another term :)
<rixed>
roconnor: with "type 'a dlist = Dnil | Dnode of 'a dlist *'a *'a dlist Lazy.t;;", ...
<rixed>
...this parse allright: "let listToDList l = let rec go l h = match l with [] -> Dnil | (x::xs) -> let rec r = Dnode (h,x,lazy (go xs r)) in r in go l Dnil;;"
<rixed>
note that you will have to force the third value of a Dnode.
<rixed>
roconnor: I don't think this is suitable as a doubly linked list, though...
ygrek has quit [Ping timeout: 246 seconds]
sku has joined #ocaml
<roconnor>
rixed: hmm. I'm not sure I like the Lazy in the data types.
raphscallion has quit [Ping timeout: 276 seconds]
jderque has joined #ocaml
jamii has quit [Ping timeout: 260 seconds]
Modius has quit [Ping timeout: 276 seconds]
jamii has joined #ocaml
ikaros has joined #ocaml
jamii has quit [Ping timeout: 276 seconds]
Modius has joined #ocaml
edwin has quit [Ping timeout: 250 seconds]
hto has quit [Ping timeout: 250 seconds]
jamii has joined #ocaml
<iris1>
Dear experts, I've run into a puzzling problem with ocaml. I would be grateful if you could provide any insight into it. I am trying to get a backtrace for a program that exits via an uncaught exception at the bottom of a chain of function calls. I discovered the Printexc module (via Stack Overflow) and crafted a test program using the record_backtrace and print_backtrace functions in there. However, I find that this only gives me the func
<iris1>
raising the exception (and the catching it), but not the intermediate ones. I would like to be able to see all the intermediate function calls in the stack trace (as is the case in most other programming languages I know). What am I doing wrong? Here is the paste of exactly what I am doing: http://pastebin.com/7cJUcuNh (this is ocaml 3.11.2 on OS X Snow Leopard 10.6.6). Thank you!
<flux>
iris1, one possibility: are your functions in tail call positions?
<flux>
iris1, that results in tail call optimization being invoked, and such functions disappear from the back trace
<iris1>
yes they are
eye-scuzzy has quit [Quit: leaving]
fraggle_laptop has joined #ocaml
<rproust>
iris1: manual solution: catch exception, print backtrace and reraise exception (so that calling function receives it too)
edwin has joined #ocaml
<iris1>
flux, rproust, thank you very much! I modified my test program to remove the TC optimization from the intermediate function and it did indeed show up in the stack trace
<iris1>
this will do the job for me; in my program most of the functions cannot be TC optimized away, so the stack trace should be informative enough
<iris1>
I don't suppose there is any way for the stack trace to show the arguments that functions received ??
el-out_y has joined #ocaml
ymasory has joined #ocaml
<rproust>
iris1: manual solution (I don't know of any automatic solution) in all your functions catch exceptions and pretty print function name + arguments. Then reraise exception to obtain a backtrace
<rproust>
this is tedious and hard to maintain
hto has joined #ocaml
Yoric has joined #ocaml
<iris1>
rproust: I agree. In your opinion, would it be possible to write a higher-order function to take care of this? e.g., (print_arguments_on_exceptions f) would do the same as f but would also catch & rethrow exceptions while pretty-printing the arguments. This would require the print_arguments_on_exceptions to determine the argument list of f, to dispatch on types, etc. Is it possible / easy to do this kind of reflection in ocaml?
<flux>
not really. you would at least need to have different versions for different arities.
<flux>
for printing, you could use for example ExtLib/Batteries Std.dump
<rproust>
you can have with_pretty_print_arg1: ('a -> 'b) -> ('a -> string) -> 'a -> 'b
<rproust>
and as flux metionned you need another version for arity two, three, etc.
<rproust>
alternatively you can use dump or Show
<rproust>
with Show, it would be possible to have with
<rproust>
with_pp_exc_1 : ('a -> 'b) -> 'a -> 'b
<rproust>
and another for different arities
<rproust>
ho… you would need the function name/line number as an extra argument… the higher order function can't guess that…
<rproust>
all this could be automated via camlp4 I guess.
<iris1>
what is Show?
<rproust>
it's a typeclass in deriving
<iris1>
looks like a module name, but it does not show up on google (or at least my google skillz are not up to this challenge)
<iris1>
Thanks! It's nice to see this in ocaml. I thought type classes were some Haskell-only nicety :-)
<rproust>
well it's not excatly type classes
<rproust>
it's sortof similar
<iris1>
flux, rproust: Thank you for the advice about print_arguments_on_exceptions! Splitting it up by arity may be fine. Perhaps I'll try to do this one day.
f[x] has quit [Read error: Connection timed out]
f[x] has joined #ocaml
fraggle_laptop has quit [Ping timeout: 240 seconds]
Yoric has quit [Quit: Yoric]
Oejet has joined #ocaml
Yoric has joined #ocaml
myu2 has joined #ocaml
Yoric has quit [Client Quit]
sku has quit [Ping timeout: 246 seconds]
myu2 has quit [Remote host closed the connection]
jamii has quit [Ping timeout: 240 seconds]
<el-out_y>
hi
<el-out_y>
do someone know how to link a code with ocamlsdl?
dnolen has joined #ocaml
robinnn has joined #ocaml
jamii has joined #ocaml
<robinnn>
hi
<robinnn>
i need tutoriel for ocamlsdl
eikke has quit [Ping timeout: 240 seconds]
<adrien>
iirc it's very close to the C api so the C tutorials are a good reference
<_habnabit>
pdhborges, hm? That's basically my original implementation
<_habnabit>
pdhborges, except I used List.fold_left
f[x] has joined #ocaml
ymasory has joined #ocaml
andreas has quit [Ping timeout: 276 seconds]
jderque_ has joined #ocaml
pdhborges has quit [Quit: Leaving.]
Tobu_ has quit [Read error: Connection reset by peer]
Tobu has joined #ocaml
andreas has joined #ocaml
jderque has quit [Quit: Leaving.]
jderque_ is now known as jderque
roconnor has joined #ocaml
<roconnor>
I think I got it to work
<roconnor>
type 'a dlist = Dnil | Dnode of 'a dlist *'a *'a dlist;;
<roconnor>
let listToDlist l = let rec go l = match l with [] -> None | (x::xs) -> Some (x,match go xs with None -> Dnil | Some (y,ys) -> let rec r = Dnode (r, y, ys) in r) in match go l with None -> Dnil | Some (y,ys) -> Dnode (Dnil, y, ys);;
<roconnor>
heh, not very elegant, but a good first start maybe
_habnabit has left #ocaml []
<roconnor>
oops, it is broken :(
Associat0r has joined #ocaml
* roconnor
goes back to the drawing board
<adrien>
that looks like a looong function, would be better to split it