Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with small list class and method map

0 views
Skip to first unread message

tmp123

unread,
Nov 6, 2006, 5:41:11 AM11/6/06
to
Hello,

Thanks for your time.

The following small class definition causes an error in method "map":

class ['a] lst (pl:'a list) =
object(self:'o)

val l = pl

method cons (v:'a) = {< l = v::l >}

method hq () =
match l with
[] -> None
| h::q -> Some(h,{<l=q>})

method to_list () = l

method map : 'b. ('a->'b) -> ('b lst) =
fun f ->
match self#hq() with
None -> new lst []
| Some(h,q) -> (q#map f)#cons (f h)

end;;

This type 'a should be an instance of type 'b
The universal variable 'a would escape its scope

I've tried lots of different posibilities, but all they gives an error
or constraints "f" to a function " 'a->'a ".

There are only 3 references in this group to similar problems, but I
can not find anyone with a solution.

Any sugestion?

Thanks.

0 new messages