Version française
Home     About     Download     Resources     Contact us    
Browse thread
Problem specializing types in signatures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus.mottl@g...>
Subject: Problem specializing types in signatures
Hi,

I have just recently run into a slightly annoying problem specializing
types in signatures, e.g.:

  module type A = sig type t end
  module type B = sig include A with type t = X end

The above will lead to a syntax error, because sum types, as well as
record types, cannot be used in the definition of t in the "with t =
..." part.  But there does not seem to be an obvious reason why this
shouldn't be allowed, because one can always just manually replace
"include A" with "A" and add the corresponding right hand side of the
type.

We cannot specify that e.g. a function returns a record by just
placing the type definition of the record in the signature of the
function.  We first have to bind the record definition to a type name,
otherwise type errors would be much harder to understand.  But this is
not the case here: we already have a type name to refer to, namely "t"
so this explanation for this behavior doesn't seem to apply.

Shouldn't it be possible to relax the language rules here to allow
direct definitions of types?  Or am I missing potential pitfalls here?

Btw., a clumsy workaround requiring the introduction of a dummy type
is the following:

  module type B = sig
    type x = X
    include A with type t = x
  end

Regards,
Markus

P.S.: A commentator on one of our blog articles also ran into a
similar issue: http://ocaml.janestcapital.com/?q=node/26

-- 
Markus Mottl http://www.ocaml.info markus.mottl@gmail.com