Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] two unrelated questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-04-25 (21:08)
From: Chris Hecker <checker@d...>
Subject: [Caml-list] two unrelated questions

1.  What is the right "functional pattern" for early-outing on success
    while using an iter/map/fold type function?  Say I'm using iter to
    search for something in an opaque datastructure.  Should I throw
    an exception to get out, or is that bad style?  I guess this
    question only makes sense for iter, since map/fold produce results
    that you theoretically want to preserve.  So, the question is
    really, given an iter-style interface to a datastructure (one that
    takes an ('a -> unit)), how do you tell it to stop iterating?  I
    guess if the function was ('a -> bool) you could do it that way,
    but most iters aren't ((List|Array|Hashtbl).iter, for example).
    Is throwing an exception the best bet?

2.  I'm confused as to when the compiler decides to inline and when it
    doesn't.  None of the calls in the following program get inlined,
    regardless of the value of -inline in ocamlopt.  It seems so
    trivial, and in fact, I wrote it to show a friend how the compiler
    is really good (and after running dumpobj on the bytecode and
    looking at the asm from ocamlopt, we went and saw with dismay how
    Pervasives.fst and .snd are builtins and not inlined functions):

let a = 1,2

let myfst (a,b) = a
let mysnd (a,b) = b

let myfsti ((a,b):int*int) = a
let mysndi ((a,b):int*int) = b
let _ =
  myfst a + 1;
  1 + mysnd a;
  myfsti a;
  mysndi a


To unsubscribe, mail  Archives: