Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Andrej.Bauer@andrej.com
Cc: Caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] Coinductive semantics
Date: Sun, 22 Jan 2006 14:16:55 +1100	[thread overview]
Message-ID: <1137899816.885.45.camel@rosella> (raw)
In-Reply-To: <43D27F18.9030102@andrej.com>

On Sat, 2006-01-21 at 19:36 +0100, Andrej Bauer wrote:
> skaller wrote:
> > How would you decode an Andrej sum without a conditional 
> > control transfer? 
> 
> The control is a consequence of the fact that natural numbers are an
> inital algebra

Hmm ..

>   rec x f 0 = x
>   rec x f (n+1) = f (rec x f n)

Yeah. Of course, natural numbers subsume bool: the switch
is right there already. Thanks!

FYI in Felix 0,1,2 .. etc are types given by n = 1 + 1 + .. + 1.
Not quite natural numbers (since + isn't strictly associative).
For any sum t a variant has notation like

	case 5 of t

in particular the components of bool = 2 are names
false = case 1 of 2 and true = case 2 of 2. The underlying
representation is a tagged pointer, with the pointer optimised
away if no variant has a (non-unit) argument. Since the
tag is an int, the run time representation of a unit sum
is just an int.

I also have arrays t ^ n = t * t * t * .. * t.

In principle, the j'th component is found by indexing
function:

	prj: t ^ n * n -> t

Unlike 'normal' array indexing .. this is entirely safe.
BTW I learned this trick from Pascal, which never needs
array bounds checks -- you have to check conversion 
int ==> n of the index instead.

What I don't know how to do is extend the collection of
fixed length array types, kind of like

	(lim n-> inf) Sum (t ^ n)

Of course I know how to *implement* this infinite sum.
(Which in practice isn't infinite of course)

The problem is that I have to somehow convert from
a run time dynamic type (the array bound is a type!)
to an integer with a 'super switch'. Rougly the
projection for the above limit is 

	typematch .. with ..
	...
	| 5 => let j = check 5 i in a.[j]
	...

in other words its an infinite switch over all the fixed
length array types. Clearly for this particular case
the implementation is just to do an dynamic array bounds
check the way Ocaml does.

But this is very unsatisfying, and in particular provides
no way to optimise away gratuitous checks at compile time.
In other words, you can't compose these things.

I'm not sure my rant really explains what I'm looking for:
basically I don't know enough theory to turn the purely
algebraic finite array types -- fairly useless in practice --
into variable length arrays required in practice.
[By variable I mean the length is an immutable dynamic type,
not that you can change the length of the array]

It would be really nice -- in BOTH Felix and Ocaml --
to have safe arrays. Unlike lists, functions like
combine and split then make sense.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2006-01-22  3:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-05 18:23 Alessandro Baretta
2006-01-05 19:48 ` [Caml-list] " David Baelde
2006-01-06 13:12 ` Andrej Bauer
2006-01-10 11:10   ` Francisco J. Valverde Albacete
2006-01-11  8:34     ` Hendrik Tews
2006-01-11 12:19       ` skaller
2006-01-11 14:54         ` Andrej Bauer
2006-01-12  2:10           ` skaller
2006-01-12 14:03             ` Andrej Bauer
2006-01-12 21:54               ` skaller
2006-01-13 10:23                 ` Hendrik Tews
2006-01-13 14:42                   ` skaller
2006-01-18 12:58                     ` Hendrik Tews
2006-01-18 14:22                       ` skaller
2006-01-20  0:49                         ` William Lovas
2006-01-20  9:57                           ` Andrej Bauer
2006-01-20 18:59                             ` William Lovas
2006-01-20 20:59                               ` skaller
2006-01-21 18:36                                 ` Andrej Bauer
2006-01-22  3:16                                   ` skaller [this message]
2006-01-22 12:23                                     ` Andrej Bauer
2006-01-22 15:35                                       ` skaller
2006-01-22 17:26                                       ` Kenn Knowles
2006-01-22 21:52                                         ` Andrej Bauer
2006-01-21 19:06                               ` Andrej Bauer
2006-01-13 10:40                 ` Andrej Bauer
     [not found]                   ` <43C7B17A.1070503@barettadeit.com>
2006-01-14 16:53                     ` Andrej Bauer
2006-01-05 20:38 Don Syme
2006-01-06 15:33 ` Alessandro Baretta
2006-01-08 10:02   ` Andrej Bauer

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=1137899816.885.45.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=Andrej.Bauer@andrej.com \
    --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