functional programming - OCaml - Error while adding a parametrized function into a module -
i extend given definition:
module type statechart = sig type 'a t val : 'a t -> 'a val create : 'a -> 'a t end module concretestatechart : statechart = struct type 'a t = { state : 'a } (* internal configuration , current state expressed 'a parameter *) let m = m.state;; (* obtaining internal value *) let create x = { state = x };; end
into 2 modules kind of transaction of type k
performed. tried define following code, but:
module type statechart = sig type 'a t type k val : 'a t -> 'a val create : 'a -> 'a t val transaction : 'a t -> k -> 'a t end module concretestatechart : statechart = struct type 'a t = { state : 'a } (* internal configuration , current state expressed 'a parameter *) type k = 'a option let m = m.state;; (* obtaining internal value *) let create x = { state = x };; let transaction x y = (* stupid statechart changes state dependingly option parameter *) match y | z -> { state = z} | none -> x;; end
it seems k definition doesn't remember 'a binding performed in 'a t:
type k = 'a option;;
error: unbound type parameter 'a
how define such transaction laterly implemented in concretestatechart module?
the type variables appear in right hand side of data type definition must quantified: k
should defined type parameter:
type 'a k = 'a option
what want express, k
must option of content type of t
, cannot expressed in level of data type definitions, in uses of them @ transaction
:
val transaction : 'a t -> 'a k -> 'a t
, means content types of t
, k
must same.
Comments
Post a Comment