[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-07-12 (16:44) |
From: | Wolfgang Lux <wlux@u...> |
Subject: | Re: [Caml-list] Troublesome nodes |
Dario Teixeira wrote: > module rec Node: > sig > type nonlink_node_t = [ `Text of string | `Bold of > Node.super_node_t list ] > type link_node_t = [ `See of string | `Mref of string * > nonlink_node_t list ] > type super_node_t = [ nonlink_node_t | link_node_t ] > > val text: string -> nonlink_node_t > val bold: super_node_t list -> nonlink_node_t > val see: string -> link_node_t > val mref: string -> nonlink_node_t list -> link_node_t > end = > struct > type nonlink_node_t = [ `Text of string | `Bold of > Node.super_node_t list ] > type link_node_t = [ `See of string | `Mref of string * > nonlink_node_t list ] > type super_node_t = [ nonlink_node_t | link_node_t ] > > let text txt = `Text txt > let bold seq = `Bold seq > let see ref = `See ref > let mref ref seq = `Mref (ref, seq) > end > > open Node > let foo = text "foo" > let bar = bold [text "bar"] > > > Error: This expression has type Node.nonlink_node_t > but is here used with type Node.super_node_t > The first variant type does not allow tag(s) `Mref, `See This problem is apparently easy to solve. Just don't expect an exact super_node_t list argument for the bold function. Instead use val bold : [< super_node_t] list -> nonlink_node_t in the signature and let bold seq = `Bold (seq :> super_node_t list) in the body of the Node module's definition. Wolfgang