caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Peter Frey <pjfrey@sympatico.ca>
To: caml-list@inria.fr
Subject: [Caml-list] Unifying buildt-in types with polymorphic types
Date: Thu, 15 May 2014 15:24:20 -0400	[thread overview]
Message-ID: <BLU0-SMTP8A20169962ECB3568E690A3360@phx.gbl> (raw)

(* In the code below I have 3 fragments of streams, based on a cons
cell; another on an array and, finally, the third is based on a string.
  I need all streams to have the same signature 'StreamOps'.
  This works fine for a stream where 'a t is a true polymorphic
 value but fails for module StmStr at the bottom of the code   sample;
giving:
       ...
       Values do not match:
         val head : int * 'a cursor -> char
       is not included in
         val head : 'a t -> 'a

I don't know if I run afoul of a form of narrowing; or if this is some
sort of limitation with respect to unboxed types. 

Any help would be greatly appreciated.

Peter Frey
*)


module type StreamOps = sig
  type 'a t 
    val head : 'a t -> 'a
end

module LazyStream : StreamOps = struct 
type 'a t = Cons of 'a * 'a t Lazy.t
  let head (Cons (h, _)) = h
end

module StmLzy = (LazyStream:StreamOps with type 'a t = 'a LazyStream.t)

module MakeEltAry = functor(S:sig include module type of Array end) ->
struct
type 'a cursor = { ofs: int; lim: int; data: 'a array }
 and 'a t = int * 'a cursor 

  let get s i = S.get s.data i 
  let head   (i, s)    = get s i
end

module EltAry = MakeEltAry(Array)
module StmAry = (EltAry:StreamOps with type 'a t = 'a EltAry.t)

module MakeEltStr = functor(S:sig include module type of String end) ->
struct
type 'a cursor = { ofs: int; lim: int; data: string }
 and 'a t = int * 'a cursor 
 
  let get s i = S.get s.data i 
  let head   (i, s)    = get s i
end

module EltStr = MakeEltStr(String)
module StmStr = (EltStr:StreamOps with type 'a t = 'a EltStr.t)






             reply	other threads:[~2014-05-15 19:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-15 19:24 Peter Frey [this message]
2014-05-15 20:28 ` Jeremy Yallop
2014-05-16 21:41   ` Peter Frey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BLU0-SMTP8A20169962ECB3568E690A3360@phx.gbl \
    --to=pjfrey@sympatico.ca \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).