From: Goswin von Brederlow <goswin-v-b@web.de>
To: OCaml List <caml-list@inria.fr>
Subject: [Caml-list] Error: In this definition, a type variable cannot be deduced from the type parameters
Date: Sat, 22 Feb 2014 18:54:35 +0100 [thread overview]
Message-ID: <20140222175435.GA21007@frosties> (raw)
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
*)
next reply other threads:[~2014-02-22 17:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-22 17:54 Goswin von Brederlow [this message]
2014-02-23 9:18 ` Jacques Garrigue
2016-03-06 1:33 Goswin von Brederlow
2016-03-06 15:30 ` Jacques Garrigue
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=20140222175435.GA21007@frosties \
--to=goswin-v-b@web.de \
--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