From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id E6F257F860 for ; Sat, 22 Feb 2014 18:54:38 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.14; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.14; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.14; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlECABnjCFPU4w8Om2dsb2JhbABavw+GXRYOAQEBAQEGCwsJFCiCUxN7NAUoIYgDARQEmTCoFx+HaheSD4EUBJgzhjISjVOBPw X-IPAS-Result: AlECABnjCFPU4w8Om2dsb2JhbABavw+GXRYOAQEBAQEGCwsJFCiCUxN7NAUoIYgDARQEmTCoFx+HaheSD4EUBJgzhjISjVOBPw X-IronPort-AV: E=Sophos;i="4.97,523,1389740400"; d="scan'208";a="59739550" Received: from mout.web.de ([212.227.15.14]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 22 Feb 2014 18:54:38 +0100 Received: from frosties.localnet ([149.172.224.32]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MgO9u-1Werda2jZu-00Nirb for ; Sat, 22 Feb 2014 18:54:36 +0100 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1WHGmZ-0005U0-EG for caml-list@inria.fr; Sat, 22 Feb 2014 18:54:35 +0100 Date: Sat, 22 Feb 2014 18:54:35 +0100 From: Goswin von Brederlow To: OCaml List Message-ID: <20140222175435.GA21007@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V03:K0:D8Vj70ykWxOYEVhaItffxKjIifMheywt41ohfCA3xT8bFNx4q1C 9DzgtXpUVBc4cG9LYIBxseWo+TJ84Ek7ruh6dJojdr7qJ8pshUZVUtKrFeocjrJLW9UpvSK AxVizVF9QatmvQkLRXZMXhIJ6CuS0QAerfoXvP+2Hik4bKcm6E6BzgvEQnCfBg//33nmgF6 QBiRUgz8wk43iNE0oNNbA== Subject: [Caml-list] Error: In this definition, a type variable cannot be deduced from the type parameters Hi, I'm stuck trying to solve this error: Error: In this definition, a type variable cannot be deduced from the type parameters. The error happens when I use the "type 'a node = InnerNode.t" from the comment and disapears when I box it in a constructor as shown below. Can anyone explain what is missing that makes the extra constructor necessary? MfG Goswin PS: needs and must work with ocaml 4.01. ---------------------------------------------------------------------- type inode = int let size_inode = 8 type offset = int let size_offset = 8 type hash = int let size_hash = 8 type block = int let size_block = 8 type cksum = string let size_cksum = 8 module BTree = struct module type KEY_VALUE = sig type key val size_key : int type value val size_value : value -> int end module type NodeType = sig type key type value type t = { size : int; entries : (key * value) list } val create : unit -> t val insert : t -> key -> value -> t val iter : ((key * value) -> unit) -> t -> unit end module Node = functor (KV : KEY_VALUE) -> (struct type key = KV.key let size_key = KV.size_key type value = KV.value let size_value v = KV.size_value v type t = { size : int; entries : (key * value) list } let create () = {size = 0; entries = [];} let insert t k v = let kv = (k, v) in let rec loop = function | [] -> [kv] | ((x,_) as t)::ts when x < k -> t::(loop ts) | t -> kv::t in {size = t.size + size_key + size_value v; entries = loop t.entries;} let iter fn t = List.iter fn t.entries end : NodeType with type key = KV.key and type value = KV.value) module Tree = struct module Leaf = struct type key = string let size_key = 16 type value = string let size_value (v : value) = 2 + String.length v end module LeafNode = Node(Leaf) module Inner = struct type key = Leaf.key let size_key = Leaf.size_key type value = block let size_value v = size_block end module InnerNode = Node(Inner) type leaf = LeafNode.t (* type 'a node = InnerNode.t *) (* Why does this fail in _ tree below? *) (* Error: In this definition, a type variable cannot be deduced *) (* from the type parameters. *) type 'a node = Node of InnerNode.t type _ tree = | LeafNode : leaf tree | InnerNode : 'a tree -> 'a node tree type t = Tree : 'a tree * 'a -> t end end (* type inode = int val size_inode : int type offset = int val size_offset : int type hash = int val size_hash : int type block = int val size_block : int type cksum = string val size_cksum : int module BTree : sig module type KEY_VALUE = sig type key val size_key : int type value val size_value : value -> int end module type NodeType = sig type key type value type t = { size : int; entries : (key * value) list; } val create : unit -> t val insert : t -> key -> value -> t val iter : (key * value -> unit) -> t -> unit end module Node : functor (KV : KEY_VALUE) -> sig type key = KV.key type value = KV.value type t = { size : int; entries : (key * value) list; } val create : unit -> t val insert : t -> key -> value -> t val iter : (key * value -> unit) -> t -> unit end module Tree : sig module Leaf : sig type key = string val size_key : int type value = string val size_value : value -> int end module LeafNode : sig type key = Leaf.key type value = Leaf.value type t = Node(Leaf).t = { size : int; entries : (key * value) list; } val create : unit -> t val insert : t -> key -> value -> t val iter : (key * value -> unit) -> t -> unit end module Inner : sig type key = Leaf.key val size_key : int type value = block val size_value : 'a -> int end module InnerNode : sig type key = Inner.key type value = Inner.value type t = Node(Inner).t = { size : int; entries : (key * value) list; } val create : unit -> t val insert : t -> key -> value -> t val iter : (key * value -> unit) -> t -> unit end type leaf = LeafNode.t type 'a node = Node of InnerNode.t type _ tree = LeafNode : leaf tree | InnerNode : 'a tree -> 'a node tree type t = Tree : 'a tree * 'a -> t end end *)