Browse thread
scanning recursive variable type
- Julien.Soula
[
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: | -- (:) |
| From: | Julien.Soula <Julien.Soula@l...> |
| Subject: | scanning recursive variable type |
hello
I have defined a type that allow me to recurse on constructor (option
and list):
# type 'a t = N of 'a | L of ('a list) t | O of ('a option) t;;
type 'a t = | N of 'a | L of 'a list t | O of 'a option t
So I can do this:
# let lo = [ Some 1; None ];;
val lo : int option list = [Some 1; None]
# let lot = O (L (N lo));;
val lot : int t = O (L (N [Some 1; None]))
Assume that I know how to pass from a function ('a->int) to functions
('a list->int) and ('a option->int) :
val fun_of_list : ('a -> int) -> 'a list -> int = <fun>
val fun_of_option : ('a -> int) -> 'a option -> int = <fun>
Now I want to apply such a function on ('a t). So I think of a
recursive function with signature:
val int_of_t : ('a->int) -> 'a t -> int = <fun>
I try to define this recursive function like that but... :
# let rec int_of_t f = function
N x -> f x
| L lx -> int_of_t (fun_of_list f) lx
| O ox -> int_of_t (fun_of_option f) ox ;;
Characters 67-80:
This expression has type 'a list -> int but is here used with type 'a -> int
I don't know how to make it otherway with this type ?
-- Julien