You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3113 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
Hi!
I posted to the mailing list about my attempts to learn how to use phantom
types. The only response I have received (from brogoff) seemed to confirm my
fears I had found a bug in the OCaml type checker. I was using 3.08.0 but
just upgraded to 3.08.1 and the problem still appears. This may well be my
misunderstanding, however. The following:
module PhantomInt : sig
type 'p t
val add : 'p t -> 'p t -> 'p t
val add_even_even : [< Even ] t -> [< Even ] t -> [< Even ] t val add_even_odd : [< Even ] t -> [< Odd ] t -> [< Odd ] t
val add_odd_even : [ Odd ] t -> [ Even ] t -> [ Odd ] t val add_odd_odd : [ Odd ] t -> [ Odd ] t -> [ Even ] t
val neg : 'a t -> 'a t
val make_even : int -> [ Even ] t val make_odd : int -> [ Odd ] t
end = struct
type 'p t = int
let add = (+)
let add_even_even = add
let add_even_odd = add
let add_odd_even = add
let add_odd_odd = add
let neg n = -n
let make_even n = if n mod 2 = 0 then n else failwith "not even"
let make_odd n = if n mod 2 <> 0 then n else failwith "not odd"
end;;
let i = PhantomInt.make_even 2;;
let j = PhantomInt.make_odd 3;;
let k = PhantomInt.add_even_odd i j;;
PhantomInt.add_even_even i k;;
PhantomInt.neg i;;
<<<<<
works as expected, but changing the type to be non-abstract (i.e. putting
"type 'p t = int" in the signature) changes the behaviour and the phantom
type checking ceases to work. Perhaps this is the intended behaviour though,
I'm not sure.
Cheers,
Jon.
The text was updated successfully, but these errors were encountered:
Original bug ID: 3113
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Hi!
I posted to the mailing list about my attempts to learn how to use phantom
types. The only response I have received (from brogoff) seemed to confirm my
fears I had found a bug in the OCaml type checker. I was using 3.08.0 but
just upgraded to 3.08.1 and the problem still appears. This may well be my
misunderstanding, however. The following:
module PhantomInt : sig
type 'p t
val add : 'p t -> 'p t -> 'p t
val add_even_even : [<
Even ] t -> [<
Even ] t -> [<Even ] t val add_even_odd : [<
Even ] t -> [<Odd ] t -> [<
Odd ] tval add_odd_even : [
Odd ] t -> [
Even ] t -> [Odd ] t val add_odd_odd : [
Odd ] t -> [Odd ] t -> [
Even ] tval neg : 'a t -> 'a t
val make_even : int -> [
Even ] t val make_odd : int -> [
Odd ] tend = struct
type 'p t = int
let add = (+)
let add_even_even = add
let add_even_odd = add
let add_odd_even = add
let add_odd_odd = add
let neg n = -n
let make_even n = if n mod 2 = 0 then n else failwith "not even"
let make_odd n = if n mod 2 <> 0 then n else failwith "not odd"
end;;
let i = PhantomInt.make_even 2;;
let j = PhantomInt.make_odd 3;;
let k = PhantomInt.add_even_odd i j;;
PhantomInt.add_even_even i k;;
PhantomInt.neg i;;
<<<<<
works as expected, but changing the type to be non-abstract (i.e. putting
"type 'p t = int" in the signature) changes the behaviour and the phantom
type checking ceases to work. Perhaps this is the intended behaviour though,
I'm not sure.
Cheers,
Jon.
The text was updated successfully, but these errors were encountered: