<Maelan>
Here it says « type-constraint::=constraint ' ident = typexpr »
<Maelan>
but it seems that the left side of = can be any typexpr
<Maelan>
not just 'ident
kushal has joined #ocaml
JuggleTux has joined #ocaml
sh0t has joined #ocaml
shinnya has joined #ocaml
<Maelan>
I’m just discovering that keyword by the way, has it been added to OCaml for long?
travisbrady has quit [Quit: travisbrady]
<flux>
"constraint"? yes, it's been in ocaml for a very long time.
slash^ has quit [Read error: Connection reset by peer]
<Maelan>
My bad then. :[
<Maelan>
Oh well, it should not be to hard to cope with, after all.
<Maelan>
I naïvely thought than it complicated subtyping or something.
<Maelan>
but no
<Maelan>
*too
<ely-se>
what is the difference between subtyping and subsumption and why isn't Int a subtype of forall a. a (in Haskell syntax)?
Denommus has joined #ocaml
<Maelan>
(I remember now having seen the keyword « constraint » in some advanced examples of objects, but I didn’t looked further)
darkf has quit [Quit: Leaving]
travisbrady has joined #ocaml
rand__ has joined #ocaml
ontologiae has joined #ocaml
<ggole>
ely-se: 'a . 'a can be used as a value of any type: Int obviously can't
<ely-se>
so can object vs string in C#
<ggole>
Hmm, lemme think this through.
<Maelan>
ely-se, but the type Object is not the equivalent of ∀a.a
<Maelan>
It corresponds to a type “Top” which is conveniently a super-type of any other.
<Maelan>
But it means that when you coerce a value to the type Object, you lose any information about it.
<ely-se>
ah right
<ely-se>
yeah
<ggole>
Seems to me it's the other way around
<ggole>
'a . 'a :> int
<ely-se>
∀a.a -> a is more useful than ⊤ -> ⊤ generally
<ggole>
The details of subtyping never seem to stick for me.
<Maelan>
And you can’t (or at least you should not be able to, if the language has correctly typing rules) coerce your value back to its initial type, or any other type.
<ggole>
Well, the two are different types
<Maelan>
That means that once converted to the type Object, you can’t give your value to a function taking anything but an Object.
<ggole>
Which one is more useful isn't the point: you use the one that you need
Kakadu has joined #ocaml
tane has quit [Quit: Verlassend]
travisbrady has quit [Quit: travisbrady]
<ely-se>
thank you very much
<Maelan>
ggole, to me it’s the opposite.
<Maelan>
∀a.a :< int
<Maelan>
and in fact, ∀a.a :< T for any type T
<Maelan>
because it is much harder for a value to be of all types at the same time, than to be just of type int.
<Maelan>
If you are of type ∀a.a, then *in particular* you are of type int.
<Maelan>
(substitution principle)
<ely-se>
∀a.a is like bottom
<Maelan>
But I’m not an expert, and I don’t know if it makes much sense to compare a quantified type with a non-quantified one.
travisbrady has joined #ocaml
<ely-se>
In Haskell, non-terminating expressions have type ∀a.a. In Scala they have type Nothing which is a subtype of all types.
<ely-se>
in that regard they're used for the same purpose
<Maelan>
Apparently the guy calls « subtyping » the relation between types, and « subsumption » the operation of widening the type of an expression.
<ely-se>
Maelan: introduce null, problem solved :P
<Maelan>
Assert False.
<ely-se>
Nontermination is bad :(
<ely-se>
Maelan: Oh I see.
<Maelan>
can’t say it’s the good answer though
<ely-se>
is subtyping used a lot in OCaml?
<Maelan>
While we are, I have another question on subtyping: what’s the point of the types of the form [< `a | `b] ?
<Maelan>
I mean, it covers exactly the values that can be either of the form `a or of the form `b.
<Maelan>
So why not simply use [ `a | `b ] ?
nullcatxxx_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<flux>
it refers to types, not values
<flux>
so type [ `open ] is ok, as is [ `closed ], or [ `open | `closed ]
<ggole>
Maelan: thinko, I meant 'a . 'a <: int
<ggole>
So we're in agreement
<Maelan>
But wouldn’t be [ `open ] and [ `closed ] accepted anyway where [ `open | `closed ] is expected, thanks to subtyping?
<Maelan>
k ggole
<mrvn>
Maelan: [ `a | `b ] is exactly `a or `b
<mrvn>
Maelan: The use case for this is "val f : [< `A | `B ] as 'a -> 'a"
<mrvn>
Maelan: If you call f with a value of type [ `A ] then you will get back a value of type [ `A ] and never `B
<Maelan>
oh I see, to keep the return type as narrow as possible
<mrvn>
Maelan: exactly
<mrvn>
Maelan: that way you can still pass the result to functions that take a narrower type.
<Maelan>
hmm, not so easy to get the compiler to produce that type.
<mrvn>
it never will. you have to annotate it
<Maelan>
# let g : 'a -> 'a = fun (x: [<`a | `b]) -> x;;
<Maelan>
val g : ([< `a | `b ] as 'a) -> 'a = <fun>
<Maelan>
That’s cool, but
<Maelan>
# let g : 'a -> 'a = function `a -> `a | `b -> `b;;
<Maelan>
val g : [ `a | `b ] -> [ `a | `b ] = <fun>
<mrvn>
it doesn't know what your intention is [] [<] or [>] are all possible. it defaults to []
<Maelan>
replacing « `a -> `a » with « `a as x -> x » does not help.
<mrvn>
# let g : ([< `a | `b ] as 'a) -> 'a = function `a -> `a | `b -> `b;;
<mrvn>
val g : [ `a | `b ] -> [ `a | `b ] = <fun>
<Maelan>
still not enough
<Maelan>
(this what I tried first)
<mrvn>
I think you can't [< ] that because it uses every type
malc_ has quit [Quit: leaving]
<Maelan>
but « function `a | `b -> 0 » gives a [< ].
<mrvn>
# let g (x : [< `a | `b ]) = ((match x with `a -> `a | `b -> `b) : [< `a | `b ]);;
<mrvn>
val g : [< `a | `b ] -> [ `a | `b ] = <fun>
<mrvn>
# let g (x : [< `a | `b ] as 'a) = ((match x with `a -> `a | _ -> raise Not_found) : 'a);;
<mrvn>
val g : ([< `a | `b > `a ] as 'a) -> 'a = <fun>
<Maelan>
Oh, you are right.
<mrvn>
To make it know that different cases in the match return different things and not all will be taken you have to use GADTs.
<Maelan>
I see
<Maelan>
.
<Maelan>
no fun
JuggleTux has quit [Ping timeout: 268 seconds]
<mrvn>
I think most of the time [> ] and [< ] will be used with phantom types
ggole has quit []
nullcatxxx_ has joined #ocaml
<ely-se>
how do you google [< ] and [> ]?
gperetin has quit [Ping timeout: 264 seconds]
rj-code has quit [Ping timeout: 256 seconds]
gperetin has joined #ocaml
jao has joined #ocaml
rj-code has joined #ocaml
rgrinberg has quit [Ping timeout: 255 seconds]
w0rp has left #ocaml ["Leaving"]
MercurialAlchemi has quit [Ping timeout: 244 seconds]
_andre has quit [Quit: :d]
ibor has joined #ocaml
orbitz_ has joined #ocaml
apache2_ has joined #ocaml
apache2 has quit [Ping timeout: 250 seconds]
jlouis has quit [Ping timeout: 264 seconds]
orbitz has quit [Ping timeout: 250 seconds]
travisbrady has quit [Quit: travisbrady]
jlouis has joined #ocaml
browncodes has quit [Ping timeout: 240 seconds]
browncodes has joined #ocaml
rgrinberg has joined #ocaml
travisbrady has joined #ocaml
jonludlam has joined #ocaml
kushal has quit [Quit: Leaving]
rgrinberg has quit [Ping timeout: 264 seconds]
ibor has quit [Quit: Leaving.]
obadz has quit [Ping timeout: 250 seconds]
<apache2_>
what are the easiest unit testing tools available for ocaml?
<companion_cube>
ounit?
<companion_cube>
easy in what sense?
<apache2_>
easy to manage and write tests
<apache2_>
do you use ounit?
<companion_cube>
well, ounit is the reference
<companion_cube>
I use qtest, which uses ounit
<apache2_>
would you recommend qtest over ounit_
<companion_cube>
I have no idea of your use case :-)
<companion_cube>
I use qtest because it allows me to write tests in comments, right next to the code, but if you don't need that then go with OUnit
<apache2_>
mildly experienced ocaml programmer, looking to develop some more methodology around the tools :)
sh0t has quit [Ping timeout: 264 seconds]
<apache2_>
I'm working on a project that has implementations in several languages, and I would like to be able to run the same test against other implementations too
<companion_cube>
oh.
<apache2_>
so I'm guessing I will have to write a wrapper of sort for each test, for each language
<companion_cube>
doesn't sound possible with unit testing, which is specific to each langauge
<companion_cube>
maybe with input files and expected outputs? like what ocamlc does?
obadz has joined #ocaml
<apache2_>
yep, I was thinking something along the lines of that
<apache2_>
inline test of smaller components sounds pretty nice too though
<apache2_>
ocamlc does that?
<companion_cube>
if you want to take a look, batteries uses qtest a lot
<companion_cube>
yes, the compiler's tests are small .ml files with their expected output, mostly
<apache2_>
thank you
BitPuffin|osx has joined #ocaml
mac10688 has joined #ocaml
ely-se has quit [Read error: Connection reset by peer]
ontologiae has quit [Ping timeout: 240 seconds]
travisbrady has quit [Quit: travisbrady]
toolslive has quit [Ping timeout: 256 seconds]
travisbrady has joined #ocaml
rgrinberg has joined #ocaml
Kakadu has quit [Remote host closed the connection]