[MLton-user] Mutual recursion?

Andreas Rossberg rossberg at mpi-sws.mpg.de
Mon Jun 29 13:49:10 PDT 2009


"Wesley W. Terpstra" <wesley at terpstra.ca> wrote:
>I have a program where the follow compiles
> fun a z = aggregate tuple2 word32 word32 $ z
> fun b z = aggregate tuple3 a word32 word32 $ z
> fun c z = aggregate tuple2 a b $ z
>
> but the following gives a sequence of gigantic type errors, starting
> at line 'and c z =':
> fun a z = aggregate tuple2 word32 word32 $ z
> and b z = aggregate tuple3 a word32 word32 $ z
> and c z = aggregate tuple2 a b $ z
>
> Could someone perhaps explain to me why switching 'fun' for 'and' can
> lead to problems? I always thought that ML would treat it more-or-less
> the same if I wasn't using mutual recursion.

No, a recursive reference is not polymorphic -- because type inference is 
generally undecidable for polymorphic recursion. So in the second version, 
each function can only use the others monomorphically.

- Andreas




More information about the MLton-user mailing list