vezenchio has quit [Read error: 110 (Connection timed out)]
<vincenz>
Pity that there is no operator with higher precedence than function application
CosmicRay has quit ["Leaving"]
CosmicRay has joined #ocaml
j_n has quit [Read error: 113 (No route to host)]
j_n has joined #ocaml
zeeble has joined #ocaml
<Nutssh>
?
Sonarman_ has joined #ocaml
Sonarman has quit [Read error: 110 (Connection timed out)]
m3ga has joined #ocaml
cjohnson has quit [""We live like penguins in the desert...""]
tintin has quit [Read error: 110 (Connection timed out)]
vivek has joined #ocaml
m3ga has quit ["Client exiting"]
vivek is now known as tintin
__DL__ has joined #ocaml
ulfdoz has joined #ocaml
<ulfdoz>
good morning.
Sonarman_ has quit ["leaving"]
CosmicRay has quit ["Client exiting"]
Snark has joined #ocaml
araujo has joined #ocaml
<araujo>
is ocaml worth learning?
<zeeble>
heh
<zeeble>
its worth taking a look at. you can prolly decide whether you want to learn it.
<araujo>
:-)
<araujo>
zeeble, is it true that it can generate code as fast as in the C language?
<araujo>
zeeble, i know CL, and haskell ... but i am looking for something faster, can ocaml help me with that?
<zeeble>
not as fast as C
<zeeble>
:p
<araujo>
I also would like to know if for someone who already knows other functional programming languages, Ocaml is worth learning or it is just the same.
<zeeble>
i know lisp(though dont like it), sml, haskell, scheme
<araujo>
zeeble, but the Ocaml impĺementation is the faster among the functional languages right?
<zeeble>
Not that i know a lot, but i like ocaml a lot more than the others.
<zeeble>
araujo: it is pretty fast depending what you are doing. just grab the basics and use it for a spell. see if you like it.
<araujo>
Ok, i will definetly give it a try...
<araujo>
zeeble, it is a (purely?) functional language?
Submarine has joined #ocaml
slashvar[lri] has quit [Read error: 60 (Operation timed out)]
Banana has joined #ocaml
tintin has quit [Remote closed the connection]
tintin has joined #ocaml
<mflux_>
araujo, no, it has side effects
<mflux_>
and some imperative features you may use
<mflux_>
but you can write pure functional programs with it just fine
<araujo>
mflux_, cool
<araujo>
That's nice, i sometimes want to use some imperative features
__DL__ has quit [Read error: 104 (Connection reset by peer)]
araujo has quit ["Programs must be written for people to read, and only incidentally for machines to execute"]
__DL__ has joined #ocaml
smimou has joined #ocaml
nlv11757_ has joined #ocaml
Herrchen has joined #ocaml
vodka-goo has joined #ocaml
pango has quit [Remote closed the connection]
tintin has quit [Connection timed out]
haakonn_ is now known as haakonn
<haakonn>
in ocamllex, i want to parse line comments. they start with '%', and last until the end of the line. my rule, '%' _* '\n', seem to take the entire rest of the file as the line comment, which is quite unintentional. what am i doing wrong?
<Submarine>
[^ '\n'] '\n' ?
<Snark>
Submarine: with a * in the middle
<Submarine>
yes
<haakonn>
hm, so everything that's not a newline, and then a newline, i see
<Snark>
"%[^\\n]*\\n"
<haakonn>
works, thanks
Submarine has quit [Read error: 104 (Connection reset by peer)]
pango has joined #ocaml
zeeble has quit ["later"]
Submarine has joined #ocaml
_JusSx_ has joined #ocaml
Submarine has quit ["Leaving"]
Herrchen has quit ["bye"]
CosmicRay has joined #ocaml
CosmicRay has left #ocaml []
vezenchio has joined #ocaml
<nlv11757_>
how does compare work on user defined datatypes?
<nlv11757_>
you have to define an kind of instance
<nlv11757_>
?
<Snark>
eh?
<nlv11757_>
the function compare
<nlv11757_>
if i define a datatype.....
<Snark>
oh
<nlv11757_>
i cant just use compare i guess....if so, what is it behaviour on these user defined datatypes?
<Snark>
nlv11757_: you know you can define a specific compare function and give it to sort?
<nlv11757_>
thats the alternative for not having classes right?
<nlv11757_>
see the thing is, in someone's code...i see a 'equals' function being used....it is defined by just calling compare however......so why does this work then?
<nlv11757_>
if he doesn't provide a specific compare for that datatype
<Snark>
nlv11757_: I'm confused
<mellum>
"<" works on everything.
<Snark>
in module List, there is: val sort : ('a -> 'a -> int) -> 'a list -> 'a list
<mellum>
Well, nearly.
<Snark>
mellum: for some definition of "works"...
<nlv11757_>
ok i'll try to make it clear; There is a user defined datatype. A guy does
<nlv11757_>
equals s1 s2
<nlv11757_>
equals is defined in terms of compare
<nlv11757_>
i want to know what exactly makes s1 equal to s2
<nlv11757_>
so i must know how this compare works on user defined datatypes
<nlv11757_>
im sorry if im being unclear, i dont do ocaml often
<Snark>
nlv11757_: look at the documentation of the Pervasives module
<nlv11757_>
k
<Snark>
it is explained there I think
<mellum>
Defining "equals" in terms of compare seems... weird. Why not use =?
<Snark>
I can't give you the link right now since it's local to my filesystem :-/
<nlv11757_>
"..e1 = e2 tests for structural equality.."
<nlv11757_>
i happened to be looking at exactly that module documentation :D
<nlv11757_>
so it just looks if the contructornames are equal and structural equality i guess
<mellum>
nlv11757_: that doesn't seem complicated enough. I'd do (compare (compare x1 x2) 0) = 0
<nlv11757_>
heheh
<nlv11757_>
hey dont blame me :D im just trying to understand what this guy does
<nlv11757_>
as long as its structural equality, i know enough
<nlv11757_>
so the ocaml compiler generates eqs for user defined types then?
<nlv11757_>
cause ocaml doesnt have overloading through classes afaik
<mellum>
nlv11757_: no. There's one comparison function that is capable of handling everythong at run tome
<mellum>
time, even
<nlv11757_>
ah ok, when every structure is probably broken down to pieces this compare understands
<nlv11757_>
every user defined type can be broken down to those pieces
Submarine has joined #ocaml
<Snark>
eh
<Snark>
I think I found a bug in ocaml
tintin has joined #ocaml
<nlv11757_>
:D
<nlv11757_>
tell us
tintin has quit [Remote closed the connection]
<Snark>
arg
<Snark>
:-/
<Snark>
my little minimal test-case doesn't show the issue
<Snark>
well, let's discuss what I saw on the bigger project
<Snark>
I added an optional argument to a method class
<nlv11757_>
ok
<Snark>
and got type errors all around
<Snark>
the reason is that I was giving an object with a method foo that had an optional arguments, to objects who didn't make use of it
tintin has joined #ocaml
<nlv11757_>
so it wasnt that optional afterall
<Snark>
it is optional
<Snark>
the proof is that when I didn't let ocaml infer the type, but gave it explicitly, it just worked
<nlv11757_>
ow ok
<mflux_>
I think the problem is that the prototype inferred in the functions may differ from your prototype
<mflux_>
and I think it isn't a bug, it's a 'feature' ;)
<nlv11757_>
well, afaik if the optional argument thing is realized through types, then type inference can become very difficult
<Snark>
mflux_: the prototype is different
<mflux_>
but maybe you can create the test case
<Snark>
but the difference is an optional argument!
<Snark>
I'm trying to
<mflux_>
yes, but optional arguments are still arguments
<Snark>
yes
<Snark>
but they are optional
<mflux_>
they aren't optional in the prototype
<mflux_>
if you have a class with methods that have optional arguments and another which has the same methods except the optional argument, the first isn't compatible with the latter
<Snark>
the other way around they are
<Snark>
and I'm using that
<Snark>
a prototype is used to say "I need at least this"
<Snark>
if I give something that can do better, it still does the "at least this" and should be accepted
<mflux_>
I don't think that's how it works in ocaml
<Snark>
bbl
<mflux_>
hm, it does infact work that way with functions ;)
<mflux_>
so I imagine it should work with methods too
<Snark>
indeed
<mflux_>
so you mean that: class foo = object method bar () = 42 end class bar = object method bar ?(foo:int) () = 44 end (new bar :> foo) fails to compile?
<mflux_>
(which it does)
<mflux_>
whops
<mflux_>
make that: class foo = object method bar () = 42 end class bar = object method bar ?(foo:int option) () = 44 end (new bar :> foo) fails to compile?
<mflux_>
and you don't need the unit-parameter for the class, I think it needlessly complicates things; but you can do class foo = fun () -> object .. if you want
<mflux_>
which can be more useful
<mflux_>
(with non-unit parameters of course)
<mflux_>
if you need to initialize the code with some other defaults than just exactly the ones that come from the parameter list
<mflux_>
maybe I was exaggataring about complicating things in this case though ;)
cjohnson has joined #ocaml
<Snark>
mflux_: the ;; isn't superfluous in ocaml's toplevel I think
<mflux_>
for example I have a protocol client implementation in ocaml
<mflux_>
the protocol has optional fields
<mflux_>
it feels natural to implement that as an optional argument
<mflux_>
because if the protocol gets a new field, I don't need to modify the client code for yet another foo:None-parameter
<nlv11757_>
are you pleading for or against OO with this argument mflux?
<mflux_>
neither, I'm talking about optional arguments
<mflux_>
you could argue I should use lists in that case, but I want to convert the arguments into strings in the function I call, without giving the task of converting the value for the protocol to the user of the class
<mflux_>
nor I wish to have an intermediate 'language' for represeting lists of arguments
TeXitoi has quit [Read error: 104 (Connection reset by peer)]
TeXitoi has joined #ocaml
<mflux_>
a constructor for each parameter type that is..
<mflux_>
also using optional argument provides a convenient method for providing default values
<Snark>
yes
<Snark>
Smerdyakov: you didn't tell me why I shouldn't use objects...
<mflux_>
and optional arguments work just great in ocaml, I wonder if there's a language that does them so great :)
<Smerdyakov>
Maybe you should be using that kind of thing instead, mflux_.
<Smerdyakov>
Snark, well, are you using dynamic dispatch and inheritance critically in your program?
<Snark>
Smerdyakov: I'm using dynamic dispatch
<Smerdyakov>
Snark, so you have a class type implemented by multiple classes, and you call objects of either class at the same point in the code?
<Snark>
in fact, part of my code uses modules, and part objects
<Snark>
depends what is more convenient
<Snark>
I have several implementations of the same base class, and a worker class that uses them using the methods of the base class...
<Snark>
ie: I use objects for what they are good at
<nlv11757_>
garbage collection?
<nlv11757_>
lol
<Smerdyakov>
OK. I bet records would work precisely as well here, though.
<Snark>
how so?
<Smerdyakov>
If you don't use the 'self' type, it's easy to compile all uses of objects into uses of records.
<Snark>
a record won't cut it
<mflux_>
well, atleast with objects one doesn't accidentally call another object's method on another object's self
<Smerdyakov>
For your example:
<mflux_>
also extending record bring further syntactic grief
<Snark>
I don't know all implementations
<Snark>
my current code scaled well
<Smerdyakov>
type with_option_type = { text : ?option:string -> unit -> string }
<Smerdyakov>
mflux_, even using 'with' expressions?
<vincenz>
bleh
<vincenz>
Smerdyakov: you're basically doing the compiler's job and making objects into records
<Snark>
yes
<Smerdyakov>
vincenz, why is it "the compiler's job" when it takes the exact same amount of code and is just as easy to understand?
<Smerdyakov>
(While also being more general)
<vincenz>
objects are more natural for this
<mflux_>
smerdyakov, if you builds record so that you embed the parent record into it, your methods will look different than they do forthe parent record, because of one extra field to access parent's data through
<Snark>
vincenz: yes, he does
<Snark>
there's one case where I was using a module
<Smerdyakov>
The code that uses records is _isomorphic_ to the code that uses objects.
<Snark>
and converted to a class to save typing
<Smerdyakov>
mflux_, closures handle keeping pointers to parent methods that aren't exported.
<mflux_>
smerdyakov, also if you don't want to import the other modules, you end up writing self.Other.baz.Bother.bar ()
<vincenz>
Smerdyakov: and it's typically seen as OO, which typically is implemented with clasess. You just implement them with records because you have this inate hatred for objects. So you do oo, but can claim "I don't use objects"
<mflux_>
well, with data then
<Snark>
I got fed up writing "JabberMessageNode.name message"
<Smerdyakov>
Snark, that's an OCaml problem. Record types are anonymous in SML.
<Snark>
and found "message#name" more handy
<mflux_>
smerdyakov, that's module name, not record name?
<mflux_>
or is record field name parsing context dependant in sml?
<mflux_>
hm, I wonder if I'm talking about the same thing :)
<Smerdyakov>
mflux_, I don't quite follow. Record field names are not declared anywhere in SML.
* Snark
goes bathing with a pretty girl
<Smerdyakov>
#somefieldname is valid anywhere.
<Smerdyakov>
And it is a function from a record with that field to the field's value.
<mflux_>
smerdyakov, so what about if two records have fields with the same names?
<Smerdyakov>
What about it?
<mflux_>
how does the compiler know which one of them is referred?
<vincenz>
you'll need modulenames for fieldnames
<Smerdyakov>
Type inference.
<Nutssh>
ocaml and sml differ in this. AFAIK, SML has record subsumption, but ocaml doesn't.
<Smerdyakov>
vincenz, not in SML.
<Smerdyakov>
Nutssh, no.
<vincenz>
fieldnames are not forcibly unique?
<mflux_>
hmm
<Smerdyakov>
vincenz, right.
* vincenz
nods
<mflux_>
let's say I have type foo = { a: int} and bar = { a : int } let func a = a.bar - how does this translate into sml?
<mflux_>
uh
<mflux_>
a.bar -> a.a
<Nutssh>
In sml or ocaml?
<mflux_>
I believe that is ocaml, how is it written in sml?
<mflux_>
that doesn't infact compile in ocaml :-)
<mflux_>
I meant.. put foo and bar into their own modules
<mflux_>
so the function would become let func a = A.a.bar, for nasdfinstance
<mflux_>
a.A.bar
<Nutssh>
No, a.(A.bar) the name of the field is A.bar
<Nutssh>
Or a.A.bar
<mflux_>
and then irssi's paste-preventation hits, I'm lagging..
<Smerdyakov>
mflux_, that's easy.
<Smerdyakov>
mflux_, foo = bar.
<Smerdyakov>
mflux_, so you can compile them identically.
<mflux_>
what if the types would differ?
<Smerdyakov>
mflux_, you will need a type annotation like fun f (a : foo) = #a a
<Nutssh>
Wait, ignore everything I just said.
<Smerdyakov>
mflux_, then you can use f with both foo and bar.
<mflux_>
that's ninice
<vincenz>
Smerdyakov: how does it know which type the functio naccepts?
<mflux_>
nice even
<vincenz>
I mean what type does the function accept?
<Smerdyakov>
vincenz, type inference, which doesn't always work, so you need annotations sometimes.
<Smerdyakov>
You could also write: fun f {a} = a
<Smerdyakov>
To get the same effect.
<Smerdyakov>
Except this would have type: { a : 'a } -> 'a
<vincenz>
Smerdyakov: it's not a unique type however
<Smerdyakov>
vincenz, it is if type inference succeeds.
<vincenz>
foo = { a : int; b : char }
<vincenz>
bar = { a : int; b : float }
<vincenz>
let f a = a.a
<Smerdyakov>
The type system only allows fully specified record types.
<Smerdyakov>
Inference must resolve the list of fields to succeed.
<Smerdyakov>
Though the types of the fields may be polymorphic, as my example showed.
<vincenz>
so anything with that minimum list is fine?
<mflux_>
I think the foo.Modulename.bar-notation is at the top of my list of ocaml griefs, it can't figure out the Modulename (can it?) even if you've annotated the type of foo
<Smerdyakov>
vincenz, another typing for f is: { a : 'a, b : 'b} -> 'a
<vincenz>
mflux_: there are some others... like :: being the only infix data constructor
<vincenz>
Smerdyakov: kind of limits record uses, no?
<Smerdyakov>
vincenz, there are infinitely many valid typings, but type inference resolves it to the most general one that works.
<Smerdyakov>
vincenz, I don't agree... and I must go! Tata!
<vincenz>
nm, I misread that
<vincenz>
later
<vincenz>
mflux_: no operator having higher precedence than function application
<mflux_>
:-)
<mflux_>
that must really bug you
<mflux_>
what cool were you trying to write?-)
cognominal has quit [Read error: 60 (Operation timed out)]
<mflux_>
as this is the third time you mention it ;)
<vincenz>
oh
<vincenz>
well if you look at
<Nutssh>
mflux_: It can't do that without reversing the order of type elaboration. Aka, lex, look up in the symbol table, then elaborate. To do that, it would have to do elaboration before the symbol table was built.
<vincenz>
let ( ** ) f g = fun x -> f (g x)
<vincenz>
you can do
<vincenz>
(f ** g) a
<vincenz>
however if you ahd one with higher precedence than function application
<vincenz>
f $ g a
<vincenz>
removes the need for ()
<vincenz>
(yes I took haskell notation tehre)
<vincenz>
only requires a slight syntax change to ocaml
<mflux_>
well that's a good point for having some new operator..
<vincenz>
like ...Change the spec to
<mflux_>
I wonder if there are going to be changes (of this size) to the ocaml language in the future
<vincenz>
$... (as in $ followed by anything)
<vincenz>
is higher prec than function application
<mflux_>
you know $ is depreciated and doesn't work if you compile with -pp
<vincenz>
it's purely a lexer/parser issue
<vincenz>
mflux_: $ is an example
<mflux_>
in any case, they cannot change the precedency of an existing operator
<mflux_>
because that could potentially break code
<vincenz>
add a new one
<mflux_>
so what would be the new operator?
<vincenz>
lemme check hte list
<vincenz>
something starting with a .
<vincenz>
they have a few already
<vincenz>
that are hardcoded
<vincenz>
. for records
<vincenz>
.[
<vincenz>
and .(
<mflux_>
that would be ok
<mflux_>
are there any other free (sane) characters?
<mflux_>
it would be a shame if . was the last one and if someone comes up with cool something, there would be no operators left :-)
* vincenz
grins
<vincenz>
we could go to utf-8
<mauke>
TENGWAR LONG SECTION MARK
<vincenz>
we still have the euro sign
<vincenz>
or the pound
<vincenz>
what did the dollar use?
<mflux_>
oh oh, I have one new usage! haskell's `infix_operator`
<mflux_>
the -pp-stuff
<mflux_>
yeah, and ` is already used so that's out
<mflux_>
.infix_operator. would infact be quite nice looking too, but could become ambigious without surrounding spaces
<vincenz>
true
<mauke>
I want different characters for that, like [.infix_op.]
<mflux_>
wouldn't the best solution be a capability to define the precedency of operators
<mauke>
then you can nest infix operators!
<mflux_>
yeah, that's a good point, assuming it would actually mean an expression insteaead of an identifier like in haskell
<mflux_>
so you could do 2 [.fun a b -> a * b * 7.] 2 \o/
<mflux_>
hmm, is \ legal outside string/character literals?
<mflux_>
too bad you can't also define your own '['-like stuff
<mflux_>
although I'm not sure if that would be useful
<mauke>
we should go all the way to perl6 and make the grammar user-modifiable
<mflux_>
well.. there is the caml preprocessor
<mauke>
AT RUNTIME!
<mflux_>
I bet perl doesn't check the validity of those constructs at compile time then ;)
<mflux_>
running programs is overrated!
<mflux_>
fortunately ocaml is blindingly fast compiling them
<mflux_>
I suppose [. .] is something that could be implemented with a preprocessor
<mflux_>
(hint, hint)
_JusSx_ has quit ["leaving"]
cognominal has joined #ocaml
<Nutssh>
Syntax matters, but IMO, its not the most important thing, as long as it is 'good enough'.
<nlv11757_>
cu im off
nlv11757_ has left #ocaml []
pango has quit ["Leaving"]
pango has joined #ocaml
senko has quit [Read error: 145 (Connection timed out)]
senko has joined #ocaml
__DL__ has quit [Read error: 145 (Connection timed out)]
Submarine has quit ["Leaving"]
__DL__ has joined #ocaml
_JusSx_ has joined #ocaml
Submarine has joined #ocaml
araujo has joined #ocaml
haakonn has quit [Read error: 113 (No route to host)]
Gueben has joined #ocaml
haakonn_ has joined #ocaml
monochrom has joined #ocaml
Snark has quit ["Leaving"]
Submarine has quit [Read error: 54 (Connection reset by peer)]
Gueben has quit ["Leaving"]
Banana has quit [Read error: 110 (Connection timed out)]
vodka-goo has quit []
_JusSx_ has quit ["leaving"]
<araujo>
Hello
<araujo>
bit quiet here
<araujo>
i program in Haskell, Does O'Caml have monads?
<ulfdoz>
cya
<araujo>
ulfdoz, i didn't want to offend with my question :-)
<mauke>
araujo: AFAIK no
<mauke>
but O'Caml has side effects, so you can just print_string whatever, change variables, throw exceptions, or whatever
<araujo>
Cool.
<araujo>
I see O'Caml is sort of a mixture between several paradigms
<araujo>
i like that
monochrom has quit ["me!"]
vezenchio has quit [""Under democracy one party always devotes its chief energies to trying to prove that the other party is unfit to rule—and bot]