det has quit [Read error: 104 (Connection reset by peer)]
tsume_ is now known as tsume
det has joined #ocaml
smkl has quit [Read error: 60 (Operation timed out)]
cjohnson has joined #ocaml
smkl has joined #ocaml
smkl has quit [Read error: 110 (Connection timed out)]
cjohnson has quit ["feigning sleep"]
vezenchio has quit ["Computer Science is no more about computers than astronomy is about telescopes"]
smkl has joined #ocaml
Herrchen_ has joined #ocaml
Herrchen has quit [Read error: 60 (Operation timed out)]
CLxyz has quit [Connection timed out]
CLxyz has joined #ocaml
humasect has quit [Read error: 110 (Connection timed out)]
m3ga has joined #ocaml
<Zaius>
how were the functions drop and take defined? i think there was a mutually dependant definition, but i dont remember it
smkl has quit [Read error: 110 (Connection timed out)]
<mrvn>
drop? take?
<Zaius>
drop : 'a list -> int -> 'a list , drops the first n elements, while take returns them
<mrvn>
look at the ocaml source at list.ml
<Zaius>
its not in module list
<mrvn>
Then where is it from?
<Zaius>
must have been some tutorial, i dont remember. but the definition was beautiful
<mrvn>
let rec drop l = function 0 -> l | n -> drop (List.tl l) (n-1)
<mrvn>
take is ugly. You can build a reverse list and reverse it at the end, do it non recursive or hack with Obj.magic to append to a list.
<mrvn>
non tail-recursive I mean
<Zaius>
of course. the definition was short, so it must have been non-tail-recursive
<mrvn>
let rec take l = function 0 -> [] | n -> (List.hd l) :: (take (List.tl l) (n-1))
<Nutssh>
What does take do?
<mrvn>
07:17 < Zaius> drop : 'a list -> int -> 'a list , drops the first n elements,
<mrvn>
while take returns them
<Zaius>
thanks mrvn. i just cant remember what i needed them for... :/
<mrvn>
But doing List things non tail-recursive is ugly. Too often lists are too large.
<Nutssh>
Oh, I see.. How about let take l n = List.reverse (drop (List.reverse l) ((List.length l) -n))
<Nutssh>
mrvn, I saw that.
<Nutssh>
'take returns the first n list elements' take: 'a list -> int -> 'a list
<mrvn>
let take l n = let rec loop accu l = function 0 -> List.rev accu | n -> loop ((List.hd l)::accu) (List.tl l) (n-1)
<mrvn>
in loop [] l n
<mrvn>
let take = let rec loop accu l = function 0 -> List.rev accu | n -> loop ((List.hd l)::accu) (List.tl l) (n-1) in loop
<Nutssh>
Its too late for me.
<mrvn>
Better to first cut the list down and then reverse it.
solarwin1 is now known as solarwind
smkl has joined #ocaml
<Nutssh>
Reverse the list, slice off the prefix, reverse the result.
creichen has quit [Read error: 110 (Connection timed out)]
<Zaius>
reversing it beforehand is probably slower than mrvn's solution. and i must admit that i was mistaken - it does not make sense to write take and drop as mutually recursive functions
m3ga has quit ["Client exiting"]
mrvn_ has joined #ocaml
mrvn has quit [Read error: 60 (Operation timed out)]
withersoever has quit ["Leaving"]
alek2 has joined #ocaml
zzorn has joined #ocaml
Svrog has joined #ocaml
humasect has joined #ocaml
zzorn is now known as zzorn_away
alek2 has quit ["Leaving"]
vodka-goo has joined #ocaml
alek2 has joined #ocaml
Svrog has quit []
Svrog has joined #ocaml
alek2 has quit ["Leaving"]
alek2 has joined #ocaml
alek2 has quit [Client Quit]
m3ga has joined #ocaml
Herrchen_ has quit ["bye"]
Riastradh has quit [Remote closed the connection]
Riastradh has joined #ocaml
Riastradh has quit [Remote closed the connection]
Submarine has joined #ocaml
Riastradh has joined #ocaml
pango has quit [Remote closed the connection]
vincenz_ is now known as vincenz
smimou has joined #ocaml
pango has joined #ocaml
<vincenz>
Smerdyakov: you here?
<vincenz>
Riastradh: ?
<det>
vincenz: did you take them serious?
<vincenz>
?
<det>
vincenz: You are best off just asking a question in #sml and you will most likely get an answer within a day :)
<det>
vincenz: asking to ask is a failing strategy in most IRC channels
<vincenz>
I moved to haskell
<vincenz>
;)
<det>
What was your question, curiously?
<vincenz>
it was a general CS question about notation
<det>
oh
<vincenz>
F, a, a |- b
<vincenz>
-------------
<vincenz>
F, a |- b
<det>
yeah, Haskell is a good place for that :)
<vincenz>
the exact meaning of |- and ,
<vincenz>
but I got it ;)
smkl has quit [Read error: 60 (Operation timed out)]
kinners has joined #ocaml
smkl has joined #ocaml
Svrog has quit []
humasect has quit [Read error: 54 (Connection reset by peer)]
mrvn_ is now known as mrvn
humasect has joined #ocaml
<mrvn>
noshadow: on "update"
<mrvn>
ups
<grirgz>
plop
m3ga has quit ["Client exiting"]
pango is now known as pangoafk
kinners has quit ["leaving"]
tintin has joined #ocaml
__DL__ has joined #ocaml
pangoafk is now known as pango
Submarine has quit ["Leaving"]
kuribas has joined #ocaml
tintin has quit [Remote closed the connection]
_shawn has joined #ocaml
karryall has joined #ocaml
kuribas has quit ["ERC Version 5.0.1 $Revision: 1.726.2.3 $ (IRC client for Emacs)"]
shawn_ has quit [Read error: 110 (Connection timed out)]
kuribas has joined #ocaml
kuribas has quit [Client Quit]
kuribas has joined #ocaml
kuribas has quit [Remote closed the connection]
kuribas has joined #ocaml
cjohnson has joined #ocaml
Yorick has joined #ocaml
slashvar[lri] has joined #ocaml
<slashvar[lri]>
Yop
<karryall>
hej
grirgz_ has joined #ocaml
Submarine has joined #ocaml
grirgz has quit [Read error: 110 (Connection timed out)]
kuribas has quit ["ERC Version 5.0.1 $Revision: 1.726.2.3 $ (IRC client for Emacs)"]
<grirgz_>
what is exactly the differences between "method m () =" and "method m =" ?
grirgz_ is now known as grirgz
<Zaius>
additional parameter ... you call a) obj#m or b) obj#m (),
<karryall>
one has type unit -> unit and the other just unit
<Zaius>
since unit does not hold any information thats especially useful
<solarwind>
() is useful when you have optional or named parameters.
<Zaius>
*not*
<karryall>
Zaius: ever heard of side effects ?
<Zaius>
karryall: what do you mean?
<karryall>
I misunderstood that you were syaing
<karryall>
as solarwind says, it's useful in the presence of optional parameters
<karryall>
also it can make the code cleaner when you want to use the method as a callback
<karryall>
eg obj#m instead of (fun () -> obj#m)
<Zaius>
agreed, but that would be a convention i'd easily forget
<karryall>
in lablgtk there's the convention that if the method has side effects, then it must have at least one argument
<grirgz>
thanks :)
<mflux>
I wish there was more candy for writing fun () -> foo
<mflux>
\foo would be nice :-)
<mflux>
or maybe \() -> foo would be sufficient
<mflux>
lending some other language
<mflux>
well, \() -> foo isn't that far from (fun()->foo) anymore
<Zaius>
thtas really a nice convention, karryall. i think i will like it
Snark has joined #ocaml
xqw has quit ["Abandonando"]
CosmicRay has joined #ocaml
smkl has quit [Read error: 60 (Operation timed out)]
xol has joined #ocaml
cjohnson has quit [Read error: 60 (Operation timed out)]
vezenchio has joined #ocaml
Pupeno has left #ocaml []
tintin has joined #ocaml
smkl has joined #ocaml
<mauke>
echo hmm
<Snark>
hmm
<karryall>
HMM ?
<mauke>
sorry, wrong command in my client
<Snark>
mauke: no problem, we could execute it anyway ;-)
karryall has quit ["apluche"]
<grirgz>
how to declare a function prototype ?
<grirgz>
i have a class wich call a function, and the function create a new instance of this class
<grirgz>
i tryed "val f : unit -> class_c" but this raise a syntax error
<mauke>
where is that function defined?
<grirgz>
if i define the function before the class, error because the class is unbound, and if i define it after, error in the class because the function is unbound
smkl has quit [Read error: 60 (Operation timed out)]
<Yorick>
what if you parametrise things?
<Yorick>
(but maybe you can't declare then function then)
mrpingoo has joined #ocaml
mattam has joined #ocaml
<grirgz>
let f x = match x with 1 -> new c1 | 2 -> new c2
<grirgz>
class c1 = object method m = f 1 end
<grirgz>
class c2 = object method m = f 2 end
<grirgz>
that is the problem
<grirgz>
how to make this code work ?
zzorn_away is now known as zzorn
<mattam>
f x has non exhaustive pattern matching, is that your problem ?
<grirgz>
no, the problem is the mutually recursive types of function and class
<grirgz>
the function cannot be defined before de definition of classes and vice versa
<TheDracle>
Hm.
<TheDracle>
Grigrgz: Can you define the function in the constructor maybe?
vodka-goo has quit [Read error: 104 (Connection reset by peer)]
vodka-goo has joined #ocaml
<grirgz>
the problem is if i define the function in the first class constructor, the second class is not yet defined so i get an error
gim has quit [Read error: 110 (Connection timed out)]
<TheDracle>
grigz: So, they're circularly dependant?
gim has joined #ocaml
<TheDracle>
Like, c1 refers to c2, and vice versa?
mrpingoo has quit [Read error: 104 (Connection reset by peer)]
<grirgz>
TheDracle: yes
<mflux>
grirgz, you could first declare a prototype for those classes, and then define a reference to a function which returns an object of the said class
<mflux>
and then after declaring classes c1 and c2 modify the reference
<mflux>
not neat, but..
<grirgz>
a class prototype is "type c1 = < ..... >" ?
cognominal has quit [Read error: 60 (Operation timed out)]
<mattam>
class type c = method m : c end
<grirgz>
what is the difference between this two forms ?
monochrom has joined #ocaml
<mattam>
i didn't know type c = <...> worked :)
<grirgz>
all would be very simple if ocaml support the use of function declared but not definied yet
<grirgz>
like C
<Snark>
grirgz: doesn't it?
pango has quit ["Leaving"]
<grirgz>
Snark: show me an exemple of a function call before his definition
<Snark>
grirgz: doesn't it work in a class?
* Snark
isn't sure
smkl has joined #ocaml
<grirgz>
it work in a class, but classes cannot be imbriqued
pango has joined #ocaml
Snark has quit ["Leaving"]
humasect_ has joined #ocaml
humasect has quit [Connection timed out]
humasect_ is now known as humasect
<grirgz>
arggg nooo, another recursion problem :,(
cognominal has joined #ocaml
<grirgz>
ocaml sux very hard at this point
cjohnson has joined #ocaml
xol has quit [Read error: 110 (Connection timed out)]
cjohnson has quit [Read error: 104 (Connection reset by peer)]
<TheDracle>
Hm. Grirgz: Ocaml's type system is much more restrictive than C's.
<TheDracle>
It has it's benefits.
<TheDracle>
The fact that you're having so many recursive object references makes me think your design has problems to begin with.
Demitar has joined #ocaml
__DL__ has quit ["je vais dormir"]
<monochrom>
let rec f x = g x and g x = x+1;;
<monochrom>
That is your "declared but not defined yet" function g.
<monochrom>
Even better, "used but not even declared yet".
<monochrom>
Please learn the language before you criticize.
<TheDracle>
monochrom: How would you use that with objects though, just out of curiosity?
<TheDracle>
Could you say, "class bob = object(self) end and class joe = "?
<grirgz>
monochrom: ok, with two functions, it's easy, but when there is 10 functions, 10 classes and 10 modules..
<monochrom>
10 functions ==> 9 "and"s
cjohnson has joined #ocaml
<monochrom>
I don't see an "and" for "class", but there is class type (interface) and there is also virtual class, so there is no problem.
<grirgz>
TheDracle: i had designed my program before i began to code in ocaml
<TheDracle>
mono: Right, shouldn't he be able to make like, an mli file and just define prototypes for everything?
<monochrom>
Modules pose no problem.
<grirgz>
yes the and with class works
<TheDracle>
grirgz: it does?
<grirgz>
yes
<TheDracle>
Wait, so, instead of end, you say and?
<monochrom>
Yes, .h : C :: .mli : ocaml. Actually .mli is even better.
<grirgz>
but the and with class and function doesnt work :,(
<grirgz>
class a = object end and b = object end
<TheDracle>
How did you get it to work with a class?
<TheDracle>
Oh, maybe I need a semicolon after my method.
<monochrom>
You can't use a class/struct in C/C++ before declaring it anyway.
<mauke>
you can, actually. kind of.
<monochrom>
"before declaring".
<mauke>
struct undeclared *ptr; // compiles
<monochrom>
That is a "declaration but not definition" case.
<grirgz>
the probleme is not declaration but definition in ocaml
<monochrom>
Like I said, to do a similar thing in ocaml, use class type (interface) to boot yourself up.
<TheDracle>
.. You can't 'use' it. In C you can.
<TheDracle>
In C++ it will bitch about use of an incomplete type.
<TheDracle>
grirgz: How did you get 'and' to work with an object? Can you send me the specific syntax?
<TheDracle>
I can't get it to work.
<grirgz>
TheDracle: ok
<monochrom>
Aha there is "and" for class. Section 6.9.3. All problems solved. The whiner is the ignoramus.
<grirgz>
i am coding a file manager, so i have implemented a class to represent each file, with a child method for directory, this is why i have so much recursivity
<TheDracle>
lass bob = object(self) method test = print_string "Here" end and class joe = object(self) method test = print_string "There" end;;
<TheDracle>
Ahem, that's what I'm trying.
<TheDracle>
Cept' the c got cut off.
<monochrom>
omit the second "class". :D
<grirgz>
TheDracle: do not put the class keyword after the and
<TheDracle>
Ha.. Finally.
<monochrom>
class bob = ... and joe = ...
<TheDracle>
Hm, I thought I'd tried that before.
<TheDracle>
Apparently not.
<monochrom>
If you use CVS to track all your casual experiements, you may be able to see whether you tried it before.
<TheDracle>
Sweet. it works :p
<monochrom>
A journaling file system may also have a record.
<TheDracle>
Very interesting.
<TheDracle>
mono: I'm just typing it into the toplevel.
<monochrom>
God has the video taped. I'll ask Him. :D
<TheDracle>
Heh.
<monochrom>
Or I could calculate it from the known initial state of the universe using the laws of physics...
<TheDracle>
You'll have to wait for quantum computers.
<monochrom>
(BTW do you want the lottery number for next week? I'll calculate that along the way.)
Demitar has quit ["Terminated with extreme prejudice - dircproxy 1.0.5"]
Yorick has quit ["beauty sleep"]
Smerdyakov has quit [Read error: 110 (Connection timed out)]
Smerdy has joined #ocaml
Smerdy is now known as Smerdyakov
chimikal has joined #ocaml
kuribas has joined #ocaml
Smerdyakov has quit [Nick collision from services.]
Smerdyakov has joined #ocaml
smkl has quit [Read error: 60 (Operation timed out)]
Submarine has quit ["Leaving"]
CosmicRay has quit ["Client exiting"]
smkl has joined #ocaml
cjohnson has quit ["5/4 of all people have trouble with fractions"]
chimikal has quit [Read error: 110 (Connection timed out)]