caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] '_a out of nowhere? (list.reverse)
@ 2004-04-14 19:05 Seth J. Fogarty
  2004-04-14 19:22 ` Daniel Bünzli
  2004-04-14 19:37 ` Stephane Legrand
  0 siblings, 2 replies; 3+ messages in thread
From: Seth J. Fogarty @ 2004-04-14 19:05 UTC (permalink / raw)
  To: caml-list

# 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.


-- 
Arav			bipsum

Aim: Sorrath		ICQ: 47462500

The same person. No difference at all. Just a different sex. -Orlando
							(Orlando, 1992)

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] '_a out of nowhere? (list.reverse)
  2004-04-14 19:05 [Caml-list] '_a out of nowhere? (list.reverse) Seth J. Fogarty
@ 2004-04-14 19:22 ` Daniel Bünzli
  2004-04-14 19:37 ` Stephane Legrand
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Bünzli @ 2004-04-14 19:22 UTC (permalink / raw)
  To: Seth J. Fogarty; +Cc: caml-list

         Objective Caml version 3.07+2

# let cons x y = x::y
   and flip f x = f y x;;
Unbound value y
# 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 = fun l -> List.fold_left (flip cons) [] l;;
val reverse : 'a list -> 'a list = <fun>
# reverse [1;2;3];;
- : int list = [3; 2; 1]
# reverse ['a';'b';'c'];;
- : char list = ['c'; 'b'; 'a']


It's a faq,

<http://caml.inria.fr/FAQ/FAQ_EXPERT- 
eng.html#variables_de_types_faibles>

Daniel

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] '_a out of nowhere? (list.reverse)
  2004-04-14 19:05 [Caml-list] '_a out of nowhere? (list.reverse) Seth J. Fogarty
  2004-04-14 19:22 ` Daniel Bünzli
@ 2004-04-14 19:37 ` Stephane Legrand
  1 sibling, 0 replies; 3+ messages in thread
From: Stephane Legrand @ 2004-04-14 19:37 UTC (permalink / raw)
  To: Seth J. Fogarty; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-14 19:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-14 19:05 [Caml-list] '_a out of nowhere? (list.reverse) Seth J. Fogarty
2004-04-14 19:22 ` Daniel Bünzli
2004-04-14 19:37 ` Stephane Legrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).