Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Nick Betteridge <lists.nick.betteridge@gmail.com>
To: Nicolas Ojeda Bar <nicolas.ojeda.bar@lexifi.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Referencing a functor type
Date: Mon, 18 Jan 2016 07:49:41 +0000	[thread overview]
Message-ID: <569C9915.4060707@gmail.com> (raw)
In-Reply-To: <CADK7aFPXbQdYZd6aniEvmTD5onQLksOABHU-nvpojAiLOWB6Rg@mail.gmail.com>

Hi Nicolas, everyone,

I'm having problems in reconstituting the variables - I'm pretty sure I
need to do some form of 'casting'. As a recap, I've re-written
everything below with a simple use-case - forming the GADTs works perfectly:


module type Cipher = sig

  type local_t
  type remote_t

  val local_create : unit -> local_t
  val local_sign : local_t -> Cstruct.t -> Cstruct.t
  val remote_create : Cstruct.t -> remote_t
  val remote_validate : remote_t -> Cstruct.t -> bool

end

module Make_cipher :

  functor (Cipher_impl : Cipher) ->
    sig
      type local_t = Cipher_impl.local_t
      type remote_t = Cipher_impl.remote_t
      val local_create : unit -> local_t
      val local_sign : local_t -> Cstruct.t -> Cstruct.t
      val remote_create : Cstruct.t -> remote_t
      val remote_validate : remote_t -> Cstruct.t -> bool
    end

type local_key = LK : 'a * (module Cipher with type local_t = 'a) ->
local_key
type cipher_module = CM : (module Cipher with type local_t = 'a) ->
cipher_module

type self_t =
  {
    mutable modules : cipher_module list;
    mutable locals : local_key list
  }



module C1x = Make_cipher (Cipher1)
module C2x = Make_cipher (Cipher2)

let () =
  let cs1 = ( module C1x : Cipher with type local_t = Cipher1.local_t) in
  let cs2 = ( module C2x : Cipher with type local_t = Cipher2.local_t) in
  let module C1 = (val cs1 : Cipher with type local_t = Cipher1.local_t) in
  let module C2 = (val cs2 : Cipher with type local_t = Cipher2.local_t) in
  let local1 = C1.local_create () in
  let local2 = C2.local_create () in
  let l_k1 = LK (local1, cs1) in
  let l_k2 = LK (local2, cs2) in
  let cm1 = CM (cs1) in
  let cm2 = CM (cs2) in
  let cslist = [cm1;cm2] in
  ignore (C1.local_sign local1 (Cstruct.create 23));
  let self = {
    modules = [cm1;cm2];
    locals = [l_k1;l_k2];
  } in
  let CM cs1' = cm1 in
  let module C1' = (val cs1' : Cipher with type local_t = 'a) in
  let LK (local1', cs1') = l_k1 in
  let signature = C1'.local_sign local1' (Cstruct.create 23) in
  Printf.printf "OK"


An error is given for 'let signature = ....'
Error: This expression has type a#1 but an expression was expected of type
         C1'.local_t = a#0

I've spent quite a while trying to figure this out and playing around
with various permutations and am simply getting nowhere!

Cheers
Nick

  reply	other threads:[~2016-01-18  7:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 11:14 Nick Betteridge
2016-01-14 11:24 ` Nicolas Ojeda Bar
2016-01-18  7:49   ` Nick Betteridge [this message]
2016-01-18 14:45     ` Runhang Li
2016-01-18 16:02       ` Nick Betteridge

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=569C9915.4060707@gmail.com \
    --to=lists.nick.betteridge@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=nicolas.ojeda.bar@lexifi.com \
    /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