CosmicRay has quit [Read error: 60 (Operation timed out)]
CosmicRay has joined #ocaml
z|away has joined #ocaml
GreyLensman has quit ["Leaving"]
CosmicRay has quit ["Client exiting"]
Walnutssh has joined #ocaml
Walnutssh is now known as Nutssh
<z|away>
Where can I learn about the difference between "=" and "==" when comparing strings?
<Nutssh>
I believe those functions are described in Pervasives.(=|==)
<z|away>
Ok, thanks. I think == used to work when comparing strings, but now it seems to only work with =.
<Nutssh>
== compares if the two references are the same. IE, "foo" == "foo" is false but let x = "foo" in x == x would be true.
<z|away>
s.[5] = 'x' or s.[5] == 'x' ?
<Nutssh>
= and == are the same for anything that is a primitive type. Chatacters or ints or bools, and maybe, in some cases, variant types.
<z|away>
Ok, thanks.
<Nutssh>
= does a recursive comparison and can deal with non-primitive types like records, objects, etc. == just compares the pointers.
kinners has joined #ocaml
Bols has left #ocaml []
Bols has joined #ocaml
cjohnson has quit [Read error: 104 (Connection reset by peer)]
kinners has quit [Read error: 110 (Connection timed out)]
<palomer>
does ocaml have a member function? like member a somelist would return true if a is in somelist?
<Nutssh>
You can get them from the oo system, generally though you want to use modules.
<palomer>
hmm?
<palomer>
does a generic member function exist?
<Nutssh>
ocaml classes do support member functions. But, unless you want the semantic meaning of member functions. module functions are just as good, if with a bit less syntatic sugar.
<Nutssh>
RTFM. :)
<palomer>
Nutssh: I mean, is it possible to write a generic function called member where member a somelist returns true iff a is in somelist
<Nutssh>
I"ll say yes, but I"m unaware of what you're exactly requesting.
<Nutssh>
Yes.
<Nutssh>
see the section on polymorphic classes.
<palomer>
it's impossible in sml
<palomer>
a might not be an object though
<palomer>
it could be an int or a float ...
<Nutssh>
find: 'a -> 'a list -> bool can be written, As can 'a -> 'a class -> bool.
<palomer>
Nutssh: you can't do that, since you need to use an operation specific to the type (namely, equality)
<Nutssh>
Ocaml has a few functions that break the type system Pervasives.= and Pervasives.==
<jourdechance>
can you give an example ?
<Nutssh>
Well, they don't break it, but they can see behind the hidden mask of an opaque types.
<palomer>
whoa
<palomer>
you can't do that in sml
<palomer>
so = and == are generic
<Nutssh>
Its useful.. ocaml also has a couple of serialization functions that can break the type system.
<Nutssh>
Yes.
<palomer>
so now you see why generic functions are useful?
<Nutssh>
And without them, you could write 'val member : ('a -> 'a -> bool) -> 'a list -> bool'
<Nutssh>
Yes and no. THey're useful, but they're also really ugly. An engineering tradeoff.
<palomer>
show me an example where they aren't desirable
<Nutssh>
In a sense, you can't add a new one to a language. They can break safety. They're a sledgehammer when you might be better served with something more refined.
<palomer>
don't you mean ('a -> 'a -> bool) -> 'a -> 'a list -> bool ?
<palomer>
Nutssh: I want examples!
<Nutssh>
That can work.
<Nutssh>
:) I don't want this debate. Ocaml is good because it is restrictive and can catch mistakes at compile time and do inference at compile time. Violating that elegance should be odne only for a good reason.
<Nutssh>
IMHO, of course. :)
<palomer>
polymorphism is a special case of generics
<palomer>
it's pretty much generics restricted to very few operations
<palomer>
(such as equality)
<palomer>
if you argue that generics are ugly, then polymorphism is ugly
<Nutssh>
dynamic-dispatch polymorphism, universally quantified types (aka, 'a types in sml/ocaml called polymorphism).
<palomer>
I mean the latter
<Riastradh>
Type _dispatch_ is inherently much more complicated than being type-_agnostic_.
<Nutssh>
I am not getting into a language war.
<Nutssh>
Does a generics-based type system have the same compile-time safety guarentees as ocaml's type system?
<palomer>
Nutssh: sure, check out gcaml
<Nutssh>
I am vaguely familiar with Corky Cartwright's java generics work as of a couple of years ago.
<Nutssh>
My mistake. I was just noticing the gcaml readme. generics != generics.
<Nutssh>
Heh. :)
<Nutssh>
How does gcaml type inference work?
<palomer>
I don't see what's so hard about picking the right function based on type matching
<Riastradh>
palomer, then define a rigorous mathematical semantics for doing so.
<palomer>
Riastradh: gcaml does that!
<palomer>
so do type classes:O
<Riastradh>
Type classes beyond single-parameter ones require dynamic type information.
<palomer>
Riastradh: an example?
<Nutssh>
If you know the types that are the arguments, picking the right function shouldn't be too hard. But how does one infer types, say, in the cases of gcaml dyn types?
<Nutssh>
Depending on the semantics of dyn types, I think it can may be reducable to NP-complete.
<palomer>
with regards to the number of arguments?
<palomer>
is it possible to do pattern matching with records?
<Nutssh>
in ocaml, yes.
<z|away>
3 ^ 2 = 9 (in C). I can't find the ^ for ints in ocaml; is there one?
<palomer>
z|away: 3 ^ 2 is not 9 in C, it's 7
<palomer>
(I kid you not)
<palomer>
and 2 ^ 2 is 2
vezenchio has quit ["I thought what I'd do was, I'd pretend I was one of those deaf-mutes ^_^"]