<hcube>
it would be nice to access project's svn repo
Associat0r has quit [Quit: Associat0r]
<ygrek>
there is email on the site
eye-scuzzy has joined #ocaml
hto has joined #ocaml
juster has joined #ocaml
diml has quit [Ping timeout: 260 seconds]
<juster>
has anyone had experience getting a segfault when calling a ocamlyacc parser from within another ocamlyacc parser?
cthuluh has quit [Ping timeout: 260 seconds]
cthuluh has joined #ocaml
Tie has joined #ocaml
<Tie>
Hello all
<Tie>
let rec factorial n = match n with | 0 -> 1 | _ -> let rec mult x y = match x with | 0 -> 0 | _ -> y + mult (x-1) y in
<Tie>
for i = 1 to 3 do Printf.printf "%d" i done;
<Tie>
mult n (fact (n-1));;
<Tie>
could anyone help me on this piece of programme?
<Tie>
it is odd that the loop is called only 1 time when i run a "factorial 5" for instance
<adrien>
I have a few questions: why is "factorial" declared with "rec"? and why do you have a "+" in the definition of "mult"?
<adrien>
(| _ -> y + mult (x-1) y
<adrien>
)
diml has joined #ocaml
<Tie>
i just want to declare a function inside a function,
<ygrek>
juster, PR#5109?
<Tie>
and i declare mult with +
<Tie>
what i want to test is ';' inside a clause of "match"
<adrien>
Tie: well, for factorial, you definitely don't need to declare a function inside another one
<adrien>
there's a number of other cases when you need to do that however
<Tie>
sure, adrien
<Tie>
my point is not to do a factorial, i want to understand how to code caml
oriba has joined #ocaml
<Tie>
i do not understand why "for i = 1 to 3 do Printf.printf "%d" i done;" is called only 1 time
<thelema>
juster: no, but you can get segfaults from infinite recursion sometimes
boscop has quit [Ping timeout: 240 seconds]
<adrien>
Tie: ok, was saying that because it makes it hard to understand exactly what you are doing
<thelema>
Tie: 1) move mult outside factorial or remove one of its parameters
<thelema>
Tie: the loop gets called once because your recursion goes to a fact routine, not the factorial function you're defining
boscop has joined #ocaml
<juster>
thelema: maybe that's it, thanks
<adrien>
and the "fact" routine is a previous version that was defined earlier in the toplevel
<Tie>
adrien, you are right
<Tie>
it is "fact" called inside, instead of "factorial"
<Tie>
thanks all
brendan has quit [Read error: Operation timed out]
sepp2k has joined #ocaml
cyanure has quit [Remote host closed the connection]
Tie has quit [Quit: Page closed]
brendan has joined #ocaml
drunK has joined #ocaml
Tie has joined #ocaml
<Tie>
hello all
<Tie>
let rec factorial n =
<Tie>
match n with
<Tie>
| 0 -> 1
<Tie>
| 1 ->
<Tie>
let a = 5 in
<Tie>
Printf.printf "%d pass by 1\n" a;
<Tie>
1
<Tie>
| _ ->
<Tie>
n * factorial (n-1)
<Tie>
i have a question about the scope of variable
<thelema>
a is not accessible outside the 1 -> match clause
<Tie>
that is true, thelema
<Tie>
if i just want to define 'a' as a part of the 1 -> match clause, instead of the whole 1-> match clause
<orbitz>
Tie: you should use a pastebin
<Tie>
do you know what i should do?
<thelema>
you want a to be part of x instead of x?
<Tie>
i want a be valid just inside "Printf.printf "%d pass by 1\n" a"
<Tie>
not anywhere else, for instance i is not valid in '1' which follows that printf...
<Tie>
sorry i => a
<thelema>
use () to limit the scope of the in -- (let a = 5 in ... );
<thelema>
but rarely is this a problem
<orbitz>
Kind of an odd requirement
<thelema>
another solution is to break the new scope into its own function -- let print_status a = Printf.printf ... a
<thelema>
orbitz: agreed, this is rarely done because having variables in scope is usually not a problem
<orbitz>
Agreed
<Tie>
( ) works
<thelema>
although proper functional decomposition does limit the scope of variables to decrease bugs
<Tie>
thanks thelema, that is exactly what i want
<Tie>
I am not very familiar with too many layers "let ... in let ... in let ... in ..."
<Tie>
i perfer do it parallely (...); (...); ...
<thelema>
doing many lets is okay and not a problem
<thelema>
in fact almost all my code is lets
<thelema>
let get_vmsize () = let pid = Unix.getpid () in let fn = sprintf "/proc/%d/stat" pid in let stat_data = File.with_file_in fn (IO.read_all) in let fields = String.nsplit stat_data " " in
<orbitz>
Jeeze, 6/10 runs of my app end with : Fatal error: exception Unix.Unix_error(11, "select", "((read (7 9)) (write ()) (except ()) (timeout -1))")
<Tie>
what if i would to change the value of a inside let?
<orbitz>
it' sthe exact same eror too, 7 and 9 in there
<Tie>
(let a = 5 in a=6; print ...) does not seem to work
<thelema>
Tie: then either use a ref or structure your code so you don't have to
<orbitz>
thelema: any idea how i can track down what "11" means here?
<thelema>
let a = 6 in let a = 6 in print a
<thelema>
orbitz: yes, it's the order or the error variant in unix
<thelema>
orbitz: 11 is EINTR: function interrupted by signal
npouillard has quit [Ping timeout: 240 seconds]
<orbitz>
Hrmm
<orbitz>
What signal could I be gettin??
<orbitz>
This is in Lwt
<orbitz>
I wonder if I'm calling something outside Lwt that is causing a signal to be sent..
<orbitz>
Would doing a printf in Lwt be quite bad?
<Tie>
thelema, i would be happy to use ref
<orbitz>
Tie: IMO 'ref' is usually unnecessary except in very specifi cases and one should try to avoid it if possible
<Tie>
so which is good?
<Tie>
let?
<orbitz>
let and ref are two compeltely different things
<Tie>
I have already defined a type twointeger = int * int
<Tie>
so how can i declare a variable of twointeger with "ref"?
<orbitz>
Tie: it is difficult to understand what you are after without understanding your problem within a large scope
<orbitz>
Tie: let foo = ref (1, 2) in
<Tie>
so it recognize automatically the type of foo?
<thelema>
Tie: yes, even without the declaration "type twointeger"
<orbitz>
Tie: foo will proabbly have the type int * int not twointeger unless there is other evidence to infer the type specifically to twointeger
<Tie>
so i could not make its type twointeger explicitly with ref?
<thelema>
you could - let foo : twointeger ref = ref (1,2)
<thelema>
or you could do: type twoint_ref = ref (int * int)
<thelema>
but there's no need to do this, as ocaml tuples are structurally typed, so they don't need names
<orbitz>
Tie: you'd have to explicilty tell the compiler it is a twointeger unelss ther eis some way to infer it. But the reality is: who cares?
<orbitz>
there is some value to it when it comes to debugging but beyond that a twointeger and a int * int are teh same thing as far as any peice of your code are concerned
joewilliams_away is now known as joewilliams
<Tie>
great, i think i understand better, thanks all
<mrvn>
orbitz: Unix has a function to pretty print an error too
<orbitz>
mrvn: RIght I was asking incase someone knew of a quick list I could look at since i seem to be getting the same error all thet ime
<mrvn>
then just count down the error variant.
<orbitz>
The only difference that immediatly comes to mind that I made in this code is I added a Printf.printf for some debugging information, so I removed that and turned it into an Lwt_io.printf, I have to make some changes to other code before I'll know for sure
<orbitz>
mrvn: is it 0 indexed or 1?
<mrvn>
orbitz: 0
<orbitz>
Thanks
<mrvn>
why waste a perfectly good number. :)
<orbitz>
Any idea of if mixing standard I/O with Lwt would cause this?
<mrvn>
never used lwt.
<thelema>
orbitz: I doubt it
<mfp>
orbitz: do you know what is calling Unix.select?
<orbitz>
Lwt is
<orbitz>
or at least, none of my code is callign Unix.select
<orbitz>
so I presume it's Lwt
<mfp>
recent Lwt uses libev which calls epoll internally AFAIK
<mfp>
orbitz: which platform?
<orbitz>
I'm on Lwt 2.1.1
<orbitz>
Linux
npouillard has joined #ocaml
<orbitz>
Note, I've been running 2.1.1 for months and it's only in some recent change to my code that I've started running into this issue
<orbitz>
so I am confident it's something I'm doing
<mfp>
hmm 2.1.1 has got a known bug involving cancellable threads
cyanure has joined #ocaml
npouillard has quit [Client Quit]
<mfp>
can you try Lwt 2.2.1? the interfaces are mostly unchanged, apart from Lwt_io.close being unit Lwt.t instead of unit
<orbitz>
mfp: Sure I'll try it later this week, i need to install GODI I think, the only reason I"m at 2.1.1 is because i couldn't get react instaleld by hand
<mfp>
2.2.1 builds OK against the pkgs from the experimental repository
<orbitz>
No I haven't, i tend to avoid the repositories for programming languages, perhaps this is a bad move for ocaml but I hav a script tha tinstalls all my deps for latest ocaml + getting core + ocamlfind
npouillard has joined #ocaml
<adrien>
well, I use godi for that. But the debian ocaml repos are definitely good
<Tie>
hello all, is there a shortcut to go to the exact line + column of a program?
Snark has quit [Ping timeout: 272 seconds]
<orbitz>
Tie: that would clearly depend on the editor you are using...
<Tie>
sorry... i though i was chatting on emacs channel
Snark has joined #ocaml
<Tie>
let ns1 = [1;2;3;4;5] in
<Tie>
let rec sum2 ns1 ns2 =
<Tie>
match ns1 ns2 with
<Tie>
| [], [] -> 0
<orbitz>
syntax error
<Tie>
where ?
<orbitz>
match ns1 ns2
<flux>
well not really, but not what you mean
<Tie>
I see... should be match ns1, ns2
<Tie>
thank you
<orbitz>
What does sum2 do?
<oriba>
you need a comma between the two items in the match
<orbitz>
is there a neat litlte trick to perofrming the following transformation: [1; 2; 3; 4; 6; 10; 11; 12] -> [(1, 4); (6, 6); (10, 12)] ?
<orbitz>
Right now I'm impleemnting some mutually recursive functions that jump back and forth depending on if i've hit a run or not
<orbitz>
i feel like there should be osem enat trick to do it more succinctl
<oriba>
that is the algorithm?
<orbitz>
yes, I'm tryign to squeeze a list into a list of ranges
<oriba>
I don't see what is has to do
<oriba>
why 1,4 6,6 10,12?
<orbitz>
because the difference bewteen the elemtsn goign form 1 to 4 is 1, they are ocnsecutiv integers
<oriba>
??
<oriba>
how is the operation called?
<orbitz>
I don't know?
<oriba>
haha
<orbitz>
why does it need a name?
<oriba>
so that I can understand what it makes
<orbitz>
You could call it compression
<oriba>
the range from the list is (1,12)
<orbitz>
I can't reconstruct that list from (1, 12) though
<orbitz>
i can from the list I gave though
<oriba>
?
<orbitz>
with [(1, 4); (6, 6); (10; 12)] i can reconstruc tthe original list
<oriba>
ah now I see what it makes
<orbitz>
I can't do that with (1, 12)
<oriba>
maybe somehwo possible to use fold here
<oriba>
or write your own function
<orbitz>
i am writing my own, i was just thinking there must be some clever FP trick
charlesno has joined #ocaml
<charlesno>
could anyone walk me through installing tuareg mode on ubuntu
<charlesno>
nvm gotta go
charlesno has quit [Client Quit]
<orbitz>
good talk
<oriba>
tail-rec function I think
<oriba>
walk over the list
<oriba>
and look if the next element is first element+1
cthuluh has quit [Quit: "Our life is frittered away by detail... Simplify, simplify" -- Thoreau]
smerz has quit [Quit: Ex-Chat]
<orbitz>
Yeah that's what I'm doing
<oriba>
where is the problem?
<orbitz>
Nowhere, my question is if htere is a clever FP trick to do it succinctly, not that I am unable to do it
<oriba>
you can give intermediate values as param again
<orbitz>
I was htinking perhaps could zip the list against it's tail at which point I have access to the differences
<oriba>
aha
<oriba>
you use pattern matching for the list I assume
<oriba>
right?
lpereira has quit [Ping timeout: 246 seconds]
cthuluh has joined #ocaml
<orbitz>
Yes
<oriba>
and how do you split the list with the match?
<orbitz>
x::xs
<orbitz>
is that what you are asking?
<adrien>
trying to add React support directly to lablgtk's build system and I can't use ocamlfind autoconf macros for now(*), and I'm trying to copy how it's using gtkgl/lablgl since it's another external ocaml library and ... I just don't understand it
mnabil has joined #ocaml
<adrien>
it definitely needs to know where to find lablgl but I see no support for that: no way to define it externally
<adrien>
unless it's with a "pure" environment variable
<adrien>
ayone knows how it does it
<adrien>
?
vk0 has quit [Ping timeout: 240 seconds]
vk0 has joined #ocaml
<oriba>
orbitz, why not first::second:.tail ? Then you have two elements seperated and can look, if first = second+1
<thelema>
oriba: probably better to keep first in an extra parameter, similar to removing consecutive duplicates
<oriba>
no problem with extra aram, but for the match first elem nevertheless is seperated
<oriba>
so you have it there with the match
<adrien>
so, another question: does anyone have working lablgl support in lablgtk with godi?
Associat0r has joined #ocaml
mnabil has quit [Ping timeout: 265 seconds]
joewilliams is now known as joewilliams_away
Snark has quit [Quit: Ex-Chat]
cyanure has quit [Ping timeout: 250 seconds]
Edward has joined #ocaml
cthuluh has quit [Ping timeout: 272 seconds]
lopex has joined #ocaml
cthuluh has joined #ocaml
lopex has quit [Client Quit]
lopex has joined #ocaml
lopex has quit [Ping timeout: 265 seconds]
lopex has joined #ocaml
zirhc has joined #ocaml
hcube has quit [Ping timeout: 246 seconds]
seafood has joined #ocaml
alexyk has joined #ocaml
ulfdoz has quit [Read error: Operation timed out]
<alexyk>
is ocaml's include Module a textual one, or the module must be precompiled? I'm trying to define a type g differently in G1 and G2, then have a G_common with same definitions for applying to either, and then, in main, include G1; include G_common -- but G_common cannot be compiled without g defined?
alexyk has quit [Read error: Connection reset by peer]
alexyk has joined #ocaml
<thelema>
alexyk: ocaml does no textual includes - include Foo is a logical one
<thelema>
and yes, the module must be precompiled. Functors will do what you want - include G_common(struct type g = ...)
<alexyk>
ah ok. So if I extend a record with more fields, functor will be equivalent of having a set of common functions working on the common subset of fields, right?
<thelema>
you can't extend a record with more fields...
<alexyk>
thelema: I'll redefine the record
<alexyk>
I need to have a set of functions working on the common subset of fields
<thelema>
ah, okay... then yes, although I don't think functors can get around the limitation you're thinking of
<thelema>
because the parameter in the functor must have a module type
<thelema>
if it's abstract, you can't access fields
<thelema>
and if it's concrete, you can't extend
<alexyk>
thelema: so I'll have a module defining the record?
seafood has quit [Ping timeout: 276 seconds]
alexyk has quit [Read error: Connection reset by peer]
lopex has quit [Ping timeout: 250 seconds]
lopex has joined #ocaml
alexyk has joined #ocaml
<alexyk>
thelema: I'm back in case I missed the asnwer :)
<alexyk>
I guess I'd really need ibjects?
hcube has joined #ocaml
<alexyk>
How much overhead is an object vs a record?
<thelema>
alexyk: if your program did nothing but access object methods vs. accessing record fields, there could be between 5x and 100x speed benefit to using records. in actual code, you likely won't notice the difference unless you put objects in your inner loop
hcube has quit [Ping timeout: 240 seconds]
<thelema>
records get compiled down to accessing a pointer at a constant offset
<thelema>
which blindingly fast
alexyk has quit [Quit: alexyk]
alexyk has joined #ocaml
<thelema>
alexyk: why do you quit so often?
<alexyk>
thelema: I carry my laptop downstairs to make some coffee :)
<alexyk>
it's easier to do it with a closed laptop
<thelema>
alexyk: maybe turn off suspend on close?
<alexyk>
thelema: possibly... so I'm in a silly position. I refactored my code to have a definition, sgraph, with a separate number of fields, and then specialized versions are made by including a specific definition of sgraph, then all common files working on shared fields, then specific fuctions.
<alexyk>
Now that include strategy fails, functors don't help, I can only add all fields before hand and keep updating old code...
<alexyk>
one record type is used in inner loop, one is not and can be replaced by an object
<alexyk>
but it includes the user_stats record which is used for millions of users
<thelema>
get it working and profile, then optimize
<alexyk>
thelema: and I can't use a list or array, since fields are of different type; I guess tuple will fail for the same reason as record... since extractor functions will have to depend on the input size
<thelema>
exactly
<alexyk>
I think this is a real problem for static typing right here. Clojure does it without noticing.
<alexyk>
and Scala with OO also makes it easy
<thelema>
ocaml's OO isn't slow, it's just slow compared to records.
<alexyk>
at least I see why O was added to Caml... despite whatever OO-haters say, it is needed here
<thelema>
you're right, it'd be nice to have extensible records.
<thelema>
but we've got objects, and they work for this.
alexyk has quit [Read error: Connection reset by peer]
alexyk has joined #ocaml
<alexyk>
this is just poor wifi
alexyk has quit [Read error: Connection reset by peer]
coucou747 has quit [Ping timeout: 240 seconds]
alexyk has joined #ocaml
alexyk has quit [Read error: Connection reset by peer]
Tie has quit [Ping timeout: 245 seconds]
alexyk has joined #ocaml
alexyk has quit [Quit: alexyk]
edwin has quit [Remote host closed the connection]
alexyk has joined #ocaml
drunK has quit [Remote host closed the connection]
ptrf has quit [Quit: leaving]
alexyk has quit [Read error: Connection reset by peer]
oriba has quit [Quit: Verlassend]
tony__ has joined #ocaml
alexyk has joined #ocaml
kig has quit [Ping timeout: 246 seconds]
kig has joined #ocaml
alexyk has quit [Read error: Connection reset by peer]
mnabil has joined #ocaml
<adrien>
gildor: have you heard about anyone wanting to make lablgtk2 use oasis?
tony__ has quit [Quit: Leaving]
alexyk has joined #ocaml
ygrek has quit [Ping timeout: 240 seconds]
Yoric has quit [Quit: Yoric]
Edward has quit []
alexyk has quit [Read error: Connection reset by peer]
khia0 has joined #ocaml
khia0 has left #ocaml []
ikaros has quit [Quit: Leave the magic to Houdini]
kaustuv has joined #ocaml
cammcad has joined #ocaml
<cammcad>
Hi all, I'm new to Ocaml. Any recommendations for the best threading library?