Version française
Home     About     Download     Resources     Contact us    
Browse thread
Void type?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Re: Void type?
On Sun, Jul 29, 2007 at 01:36:24PM +0200, Arnaud Spiwack wrote:
> Jon Harrop a écrit :
> >On Sunday 29 July 2007 12:05:47 Arnaud Spiwack wrote:
> >  
> >>It is the good solution if you work with the original syntax (and it's
> >>absolutely equivalent to the dual definition in term of empty variant
> >>which you can write in the revised syntax).
> >>    
> >
> >I don't quite understand this "empty variant from the revised syntax 
> >thing". How is:
> >
> >  type void
> >
> >not an empty variant?
> >
> >  
> Well, not technically I believe. It's a type with no definition. I 
> wouldn't be adamant about that but I reckon it's not considered as a sum 
> type by OCaml type system.
> Plus you cannot write the empty matching :
>       match x with []
> in the original syntax, preventing you from writing a function of type 
> void -> 'a  without using exceptions or Obj.magic or an obviously 
> looping function or such.
> 
> Thus it does not really have the logical behavior of an empty variant.

Can you explain what you mean a bit more?

type void1 = { v: 'a. 'a };;
let f (_ : void1) = 1;;
--> val f : void1 -> int = <fun>
let f () : void1 = failwith "error";;
--> val f : unit -> void1 = <fun>

type void2;;
let f (_ : void2) = 1;;
--> val f : void2 -> int = <fun>
let f () : void2 = failwith "error";;
--> val f : unit -> void2 = <fun>

They seem to be fairly similar to me.

Rich.

-- 
Richard Jones
Red Hat