Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] '_a out of nowhere? (list.reverse)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stephane Legrand <stephane@f...>
Subject: Re: [Caml-list] '_a out of nowhere? (list.reverse)
On Wed, Apr 14, 2004 at 02:05:32PM -0500, Seth J. Fogarty wrote:
> # let cons x y = x::y
> # and flip f x y = f y x ;;
> val cons : 'a -> 'a list -> 'a list = <fun>
> val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c = <fun>
> # let reverse = List.fold_left (flip cons) [];;
> val reverse : '_a list -> '_a list = <fun>
> # reverse [1;2;3];;
> - : int list = [3; 2; 1]
> # reverse ['a';'b';'c'];;
> This expression has type char but is here used with type int
> 
> I've encountered similar things with references, but never with something as
> basic as a fold_left. Can someone tell me why this is happening? This, to me,
> is very wrong behavior. This is on Debian's OCaml 3.07.

Try this:

# let cons x y = x::y
# and flip f x y = f y x ;;
# let reverse = List.fold_left (flip cons) [];;
# reverse ['a';'b';'c'];;
# reverse [1;2;3];;

In your example, when you first use reverse with an integer list,
you definitely have a reverse with :
 
  val reverse : int list -> int list = <fun>


Regards,
Stephane.

-- 
Je recherche un emploi de développeur/admin. sys.
 (FreeBSD,Linux,PHP,Perl,MySQL,OCaml,Tcl/Tk...)
  ==> www.freebsd-fr.org/~stephane/cv.pdf <==

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners