caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stephane Legrand <stephane@freebsd-fr.org>
To: "Seth J. Fogarty" <sfogarty@students.uiuc.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] '_a out of nowhere? (list.reverse)
Date: Wed, 14 Apr 2004 21:37:05 +0200	[thread overview]
Message-ID: <20040414193705.GL75847@sequoia.mondomaineamoi.megalo> (raw)
In-Reply-To: <20040414190532.GQ10439@students.uiuc.edu>

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


      parent reply	other threads:[~2004-04-14 19:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-14 19:05 Seth J. Fogarty
2004-04-14 19:22 ` Daniel Bünzli
2004-04-14 19:37 ` Stephane Legrand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040414193705.GL75847@sequoia.mondomaineamoi.megalo \
    --to=stephane@freebsd-fr.org \
    --cc=caml-list@inria.fr \
    --cc=sfogarty@students.uiuc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).