caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus@oefai.at>
To: Francois Pottier <francois.pottier@inria.fr>,
	eijiro_sumii@anet.ne.jp, Alain Frisch <frisch@clipper.ens.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Turning off type-checking
Date: Tue, 14 May 2002 14:51:33 +0200	[thread overview]
Message-ID: <20020514125133.GC15675@kiefer.ai.univie.ac.at> (raw)
In-Reply-To: <Pine.SOL.4.44.0205141001400.3093-100000@clipper.ens.fr> <20020514165632J.sumii@tuba.is.s.u-tokyo.ac.jp> <20020514091053.A8883@pauillac.inria.fr>

On Tue, 14 May 2002, Francois Pottier wrote:
> The worst-case complexity is obtained by nesting `let' bindings
> on the left side, i.e.
> 
>   let x1 = let x2 = let x3 = ...
> 
> Do you generate such code, Markus?

There may indeed be many cases of nested "let"s and also pattern-matches.

Just to give an example of how this works, given this data specification
(usual algebraic datatypes) + data samples (mappings from one domain
to another):

---------------------------------------------------------------------------
SPEC MySpec = BEGIN
  satisfaction = Low | High | Very satisfaction.
  diameter = Large | Small.
  sort = Mozzarella | Gorgonzola.
  topping = Cheese sort | Tomatoes | Mushrooms.
  spiced = False | True.
  meal =
    | WienerSchnitzel diameter
    | Pizza (diameter * spiced * topping)
    | TapirSoup spiced.
END

DATA MyData : (meal : MySpec) -> (satisfaction : MySpec) = BEGIN
  Pizza (Large, True, Cheese Mozzarella) -> Very (Very High).
  Pizza (Large, True, Cheese Gorgonzola) -> Very (Very Low).
  Pizza (Large, False, Tomatoes) -> Very (Very Low).
  WienerSchnitzel Small -> Very Low.
  TapirSoup True -> Very Low.
  TapirSoup False -> Very High.
END
---------------------------------------------------------------------------

The generated code (induced function) would look like this:

---------------------------------------------------------------------------
let model meal_d1 =
  let satisfaction_c1 =
    (match meal_d1 with
    | TapirSoup spiced_d1 ->
        (match spiced_d1 with
        | True -> Low
        | False -> High)
    | Pizza (_, spiced_d1, topping_d1) ->
        let satisfaction_c1 =
          (match spiced_d1 with
          | True ->
              (match topping_d1 with
              | Cheese sort_d1 ->
                  (match sort_d1 with
                  | Gorgonzola -> Low
                  | Mozzarella -> High)
              | _ -> High)
          | False -> Low) in
        Very satisfaction_c1
    | WienerSchnitzel _ -> Low) in
  Very satisfaction_c1
---------------------------------------------------------------------------

If there are, say, mappings from 100 to 100 variables and thousands of
deeply structured sample values (a "real-world" problem), the models
can look quite terrifying.

In another still comparatively small test case with 1000 random samples
the generated code requires about 1.6MB. What concerns me here is that
the OCaml-interpreter requires more than 60MB to check it!

> Markus, do the sub-expressions in your programs have huge types?

Well, depends on the notion of "huge". It can happen that the model
factors out redundant data constructors from large structures. Then it
has to pack and unpack somewhat large tuples, e.g.:

  let (v7_c1, (* snip 13 bindings *) v7_c15) =
    (match v6_d1 with
    ...) in
  (v7_c1, V7S (V6A, v6_c2), ...)

But the size of the types is probably not the real issue, because it is
still strongly tied to the data. The structure of the data surely plays
a role, but its size puts a limit on the size of the types.

On Tue, 14 May 2002, Alain Frisch wrote:
> It seems that what takes time is occurence checking (disabled with
> -rectypes) and pretty-printing of types (because internally, there are
> many sharings), not type inference itself. For this (unatural) example,
> bad behaviour of occurence checking is visible (less than 0.04 seconds
> with -rectypes, and more than 10 minutes [I'm not patient enough to
> wait more] without -rectypes).

I am afraid, but this does not change much, the timing difference is
lower than 10%. Maybe I am just asking for too much, and it is the sheer
size of the code that doesn't allow more efficiency?

Anyway, as it seems, parsing medium-sized test cases takes about an
order of magnitude less time than the subsequent type checking so there
may be points for improvement...

Regards,
Markus

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
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


  reply	other threads:[~2002-05-14 12:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-14  3:10 Gregory Morrisett
2002-05-14  7:10 ` Francois Pottier
2002-05-14  7:56   ` eijiro_sumii
2002-05-14 12:51     ` Markus Mottl [this message]
2002-05-15 19:42       ` John Max Skaller
2002-05-15 21:02         ` Markus Mottl
2002-05-14  8:20   ` Alain Frisch
2002-05-14 10:33     ` Christophe Raffalli
2002-05-14 13:39   ` Oliver Bandel
2002-05-15  6:00     ` malc
  -- strict thread matches above, loose matches on Subject: below --
2002-05-13 13:31 Markus Mottl
2002-05-13 14:33 ` Lauri Alanko
2002-05-13 21:47 ` Berke Durak
2002-05-14 13:33 ` Oliver Bandel
2002-05-14 14:33 ` Jacques Garrigue
2002-05-14 23:17   ` Markus Mottl
2002-05-14 23:34     ` John Prevost
2002-05-15  8:51       ` Jacques Garrigue
2002-05-15 22:22   ` John Max Skaller

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=20020514125133.GC15675@kiefer.ai.univie.ac.at \
    --to=markus@oefai.at \
    --cc=caml-list@inria.fr \
    --cc=eijiro_sumii@anet.ne.jp \
    --cc=francois.pottier@inria.fr \
    --cc=frisch@clipper.ens.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).