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: 6219 Reporter:@yallop Assigned to:@yallop Status: closed (set by @xavierleroy on 2015-12-11T18:26:48Z) Resolution: fixed Priority: normal Severity: feature Fixed in version: 4.02.0+dev Category: typing Related to:#5584 Monitored by:@gasche@diml@hcarty@alainfrisch
Bug description
It would be useful for exceptions to support existential types via GADT-style declarations:
exception E : 'a t -> exn
The text was updated successfully, but these errors were encountered:
This has been resolved by PR5584. Here's an example use, which now works in trunk:
module type INT =
sig
type t
val to_string : t -> string
val div : t -> t -> t
val zero : t
end
type 'i intmod = (module INT with type t = 'i)
exception Division_by_zero : 'a intmod * 'a -> exn
let div : type i. i intmod -> i -> i -> i =
fun ((module I) as i) n d ->
if d = I.zero then raise (Division_by_zero (i, n))
else I.div n d
let f (type i) ((module I : INT with type t = i) as i) x y =
match div i x y with
z ->
Printf.printf "%s / %s => %s\n"
(I.to_string x) (I.to_string y) (I.to_string z)
| exception Division_by_zero ((module I), n) ->
Printf.printf "%s / 0 => ERROR\n" (I.to_string n)
(* prints "12 / 4 => 3" *)
let _ = f (module Int32) 12l 4l
(* prints "12 / 0 => ERROR" *)
let _ = f (module Int64) 12L 0L
Original bug ID: 6219
Reporter: @yallop
Assigned to: @yallop
Status: closed (set by @xavierleroy on 2015-12-11T18:26:48Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 4.02.0+dev
Category: typing
Related to: #5584
Monitored by: @gasche @diml @hcarty @alainfrisch
Bug description
It would be useful for exceptions to support existential types via GADT-style declarations:
exception E : 'a t -> exn
The text was updated successfully, but these errors were encountered: