caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Problem specializing types in signatures
@ 2008-05-16 18:26 Markus Mottl
  0 siblings, 0 replies; only message in thread
From: Markus Mottl @ 2008-05-16 18:26 UTC (permalink / raw)
  To: ocaml

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-16 18:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-16 18:26 Problem specializing types in signatures Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).