Re: where type referring to other parameter in functor parameters

[email protected] Fri, 5 Oct 2012 11:48:05 +0200
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <[email protected]>
On 10/05/2012 11:30 AM, Bernard Berthomieu wrote:
>
> With no structure named A bound at top-level,
> mlton accepts the following functor declaration:
>
>      signature S = sig type s end;
>      signature T = sig type t end;
>      functor Fun1 (structure A : S and B : T where type t = A.s) =
> struct val x = 1 end;
>
> Note that the "where type" constraint in the sig of parameter B refers
> to parameter A.
>
> I was wondering if such a constraint is legal by "The Definition".

Your exact example is not legal, because of your use of 'and', which has the
effect that both structures are declared "simultaneously" (not
recursively!), i.e., the specifications cannot see each other. But if you
change it to:

  functor Fun1 (structure A : S structure B : T where type t = A.s) = ...

then it is perfectly legal, and a common pattern in ML.

Rule of thumb: never use 'and' except for recursive bindings, i.e., 'fun' or
'datatype'.

> Also, if Fun1 is legal, why is Fun2 below rejected ? I would expect and
> to be
> commutative here:
>
>      functor Fun2 (structure B : T where type t = A.s and A : S) =
> struct val x = 1 end;

Same story: structure specifications are not recursive.

> Polyml rejects Fun1, by the way.

And rightly so. Is it accepted by MLton? If so that is a bug.

/Andreas


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev