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] ocaml killer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-01-29 (19:19)
From: William Lovas <wlovas@s...>
Subject: Re: fancy types (was Re: [Caml-list] ocaml killer)
On Thu, Jan 29, 2004 at 06:41:47PM +0100, Andreas Rossberg wrote:
> Also note that you can encode most of these examples without -rectypes, 
> using variant types.

In case it's nonobvious, have a gander at this:

    # type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b);;
    type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b)
    # let fac n =
        let do_rec (S specialist) n =
          if n = 0 then
            n * specialist (S specialist) n
        do_rec (S do_rec) n;;
    val fac : int -> int = <fun>

It's also instructive to look at the new, improved type of do_rec:

    val do_rec : (int, int) specialist -> int -> int = <fun>

In my experience, type errors have never indicated a lack of flexibility in
the typechecker, but rather a lack of understanding on my own part of the
code i'm trying to write or the problem i'm trying to solve.  And it nearly
always pays off in the end to pause for a moment and attempt to assign
appropriate types to my functions -- then, when i'm finished, i actually
*understand* why the code should work.

This is probably why it so often seems to be the case that in typeful
programming, "once it typechecks, it works!"


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: