sponge45 changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
triple_ has joined #ocaml
<love-pingoo>
I just started playing with polymorphic variants...
<love-pingoo>
I'm sure the following is a simple question but: why do I get a "x has type b but is used with type a" in the following ?
<love-pingoo>
type a = [ `A ]
<love-pingoo>
type b = [ a | `B ]
<love-pingoo>
let f1 (x:a) = x
<love-pingoo>
let f2 (x:b) = f1 (x)
<love-pingoo>
if I specify (x:>a) it passes, but I'd like to avoid such obvious annotations
<love-pingoo>
do I need to hint OCaml about the variance ?
<pango>
I haven't used polymorphic variants yet, but I guess that since b is not fully included in a, OCaml won't let you do "unsafe things"
<pango>
like using a value of type b where a value of type a is expected
<malc_>
love-pingoo: huh? what passes?
<pango>
what would happen if you evaluated f2 `B ?
<love-pingoo>
oops sorry, I minimized my example in the wrong way
<love-pingoo>
must be too late..
Demitar has left #ocaml []
<love-pingoo>
let f1 (x:b) = x
<malc_>
and the problem...?
<love-pingoo>
let f2 (x:b) = f1 x << type error
<love-pingoo>
let f2 (x:a) = f1 x << type error
<love-pingoo>
(sorry)
<love-pingoo>
let f2 (x:a) = f1 (x:b) << ok
<love-pingoo>
let f2 (x:a) = f1 (x:>b) << ok
<love-pingoo>
(sorry again...)
<love-pingoo>
it'd be nice to have the cast from a to b infered (any a can be seen as a b)
<malc_>
those are distinct types still.. and supposedly might (though does not currently) incur run-time conversion
<malc_>
hence mandatory cast.. at least that would have been my rationale
<love-pingoo>
in some complex cases the variance isn't obvious, I agree
<love-pingoo>
but I was looking for a way to force/check the variance of a type once for all, and use it conveniently later
<malc_>
i guess, asking on the mailing list is a way to go
<pango>
what about let f1 x = (x :> b) ?
<pango>
I'm not sure of the semantic differences
<love-pingoo>
malc_: I'm sure that it's a known issue, I'd like to try to find by myself before asking the list
<malc_>
you can use: let f2 = function (#a as x) -> f1 x;; though
<love-pingoo>
pango: that could do the trick (just as forcing f1 : [<b] -> [>b]) but I'd like to completely get rid of coercions, since I'm actually working on much larger code
<pango>
my guess is that coercions are always explicit, much like with objects
<pango>
so you won't be able to totally get rid of them
Mr_Awesome has quit ["and the Awesome Level drops"]
<love-pingoo>
pango_: I used [<..] type annotations in my declarations and it does most of the job
<love-pingoo>
there are only very few coercions remaining
<love-pingoo>
but one is really bothering me, especially since I cannot manage to minimize the example
buluca has joined #ocaml
buluca has left #ocaml []
cmeme has quit ["Client terminated by server"]
cmeme has joined #ocaml
host46 has quit [Remote closed the connection]
nonpop has quit ["Leaving."]
slowriot has joined #ocaml
<love-pingoo>
got it... weird but kind of making sense
sponge45 has joined #ocaml
<love-pingoo>
if you have a recursive function taking x:[<a] with a recursive call using an x of type a, then the type of your function will require an a (and will thus require explicit coercions)
bluestorm has quit ["Konversation terminated!"]
<tsuyoshi>
variants scare me
<pango_>
variants, or polymorphic variants ?
johnnowak has joined #ocaml
<tsuyoshi>
uh.. what's the difference?
sanvargasg has joined #ocaml
<pango_>
with polymorphic variants, constructors don't have a single, specific type
triple_ has quit [Remote closed the connection]
sanvargasg has left #ocaml []
<tsuyoshi>
oh that's what I meant
<Smerdyakov>
tsuyoshi, have you noticed that including "uh" in a line on IRC usually has only negative effects?
<tsuyoshi>
what sort of negative effects
<tsuyoshi>
am I not terse enough for you
<Smerdyakov>
Often it means "you, the person I am addressing, are an idiot."
<Smerdyakov>
I don't necessarily get that connotation from your last usage, but at least it added no information.
<tsuyoshi>
oh that depends on my tone of voice
<tsuyoshi>
that "uh" was my attempt to convey my confusion
<pango_>
that's how I interpreted it, too ;)
triple_ has joined #ocaml
<love-pingoo>
so who "added no information" here ? ;)
<love-pingoo>
having said that, I now really need to sleep (and I'm not adding any info either)
<johnnowak>
tsuyoshi: try "ermm" instead of "uh"... :)
<tsuyoshi>
maybe next time I will try /me is confused...
<tsuyoshi>
I was looking at the assembly output from ocamlopt yesterday
<tsuyoshi>
it was terribly confusing but very impressive
<tsuyoshi>
I wrote this function to scan through utf8 without branching
<tsuyoshi>
doing a bunch of bit-shifting and bit-anding
<tsuyoshi>
somehow the compiler managed to removed all but one of the shifts
<tsuyoshi>
ack
<tsuyoshi>
manged to remove
<tsuyoshi>
managed to remove
<tsuyoshi>
I forgot to copy it to my flash key though before I came here..
pstickne has quit [Read error: 104 (Connection reset by peer)]
pstickne has joined #ocaml
Smerdyakov has quit ["Leaving"]
sponge45 has quit ["zzzzzzzzzz"]
_velco has joined #ocaml
_velco is now known as velco
love-pingoo has quit ["Connection reset by pear"]
love-pingoo has joined #ocaml
smimou has joined #ocaml
bluestorm has joined #ocaml
_JusSx_ has joined #ocaml
twobitsp1ite has joined #ocaml
twobitsprite has quit [Read error: 145 (Connection timed out)]
nonpop has joined #ocaml
Submarine has joined #ocaml
ulfdoz has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
love-pingoo has joined #ocaml
ikaros has quit ["Leaving"]
mellum_ is now known as mellum
ikaros has joined #ocaml
cratuki__ has joined #ocaml
rillig has joined #ocaml
cratuki has quit [Read error: 110 (Connection timed out)]
swater has joined #ocaml
mc__ has quit [Remote closed the connection]
johnnowak has quit []
johnnowak has joined #ocaml
bluestorm is now known as bluestorm_aw
Smerdyakov has joined #ocaml
piggybox has quit [Connection timed out]
ikaros has quit [Read error: 60 (Operation timed out)]
ikaros has joined #ocaml
johnnowak has quit []
rillig has quit ["exit(EXIT_SUCCESS)"]
levi_home has quit [Read error: 104 (Connection reset by peer)]
levi_home has joined #ocaml
levi_home has quit [Read error: 110 (Connection timed out)]
klapmuetz has joined #ocaml
slowriot has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
_JusSx_ has quit [Client Quit]
smimou has quit ["bli"]
slowriot has quit [Read error: 104 (Connection reset by peer)]
<tsuyoshi>
how hard would it be to port ocaml to an embedded device?
<tsuyoshi>
does the runtime need anything special besides malloc()?
basis has joined #ocaml
swater has quit [Read error: 110 (Connection timed out)]
pantsd has quit [Read error: 54 (Connection reset by peer)]
swater has joined #ocaml
slowriot has joined #ocaml
<flux__>
I doubt its very difficult, if you don't want to implement a few modules, such as Unix and Thread (although I guess the green threads are portable)