caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Christophe TROESTLER <Christophe.Troestler@umh.ac.be>
Cc: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: '_a
Date: 29 Jan 2005 01:50:34 +1100	[thread overview]
Message-ID: <1106923834.23562.148.camel@pelican.wigram> (raw)
In-Reply-To: <20050128.144218.80110994.Christophe.Troestler@umh.ac.be>

On Sat, 2005-01-29 at 00:42, Christophe TROESTLER wrote:
> On 28 Jan 2005, skaller <skaller@users.sourceforge.net> wrote:
> > 
> > let x = 
> > 	let rec f l -> | [] -> raise Not_found 
> > 	| h :: t -> if h == v then (raise Found; 0) else f t
> > 	in try f l with Found -> 1 | Not_found -> 2
> > in print_endline (string_of_int x)
> > 
> > where the compiler doesn't know f l cannot return, so it needs a
> > useless '0' after the Found case to get the typing correct.
> 
> Not quite,

[]

> Maybe you mean something like
> 
> let cl file =
>   let fh = open_in file in
>   let nl = ref 0 in
>   try
>     while true do
>       let _ = input_line fh in
>       incr nl
>     done
>   with End_of_file -> !nl

Thanks for a better example (well a right one has to better :)

> where the [while] has type [unit] while [!nl] has type [int] and the
> two cannot be unified.  But this is because there is no way for the
> compiler to know that a loop indeed never ends, so one has to tell:
> 
> let cl file =
>   let fh = open_in file in
>   let nl = ref 0 in
>   try
>     while true do
>       let _ = input_line fh in
>       incr nl
>     done;
>     assert false
>   with End_of_file -> !nl
> 
> With that everything is fine.

Yes, that's a better solution too.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




  reply	other threads:[~2005-01-28 14:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-27  0:19 '_a Mike Hamburg
2005-01-27  0:51 ` [Caml-list] '_a Jacques Garrigue
2005-01-27  9:34   ` skaller
2005-01-27 10:02     ` Alex Baretta
2005-01-27 14:13     ` '_a Vincenzo Ciancia
2005-01-27 19:39       ` [Caml-list] '_a Jacques Carette
2005-01-28  0:57       ` skaller
2005-01-28 13:25         ` '_a Stefan Monnier
2005-01-28 14:46           ` [Caml-list] '_a skaller
2005-01-28 14:46           ` Keith Wansbrough
2005-01-28 15:48             ` skaller
2005-01-29  1:37               ` Michael Walter
2005-01-28 13:42         ` Christophe TROESTLER
2005-01-28 14:50           ` skaller [this message]
2005-01-28 12:54       ` Richard Jones
2005-01-28 14:39         ` Alex Baretta
2005-01-29  0:33   ` [Caml-list] '_a Dave Berry
2005-02-02  9:17     ` Jacques Garrigue
2005-02-03  7:41   ` Florian Hars

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=1106923834.23562.148.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=Christophe.Troestler@umh.ac.be \
    --cc=caml-list@inria.fr \
    /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).