On 05/08/12 15:55, Phil Clayton wrote:
On 23/07/12 12:51, David Matthews wrote:
What this implies for the implementation is that it needs to actively
reduce any type abbreviations to their right hand sides before doing any
unification and also when applying the value restriction. This then
allows Phil's examples to work and also the simple example above. It
does have the unfortunate side-effect that expressions with type
abbreviations are not printed using the abbreviation in cases where it
used to.
Thanks for the update. I haven't noticed much difference in the printed
types. The only change worth mentioning is that
val it = (): unit
now prints as
val it = (): {}
...
I probably spoke a bit too soon here. After more interactive use, it
appears that records and tuples can be expanded one level in the types
printed back. This can make types much harder to read which may be an
issue for those using an interactive session to e.g. inspect expression
types by evaluating fragments of code. With the example at the end, 5.4
prints back
val nearest = fn: point -> point list1 -> real * point
which is fairly self-explanatory, whereas r1581 prints back
val nearest = fn:
real * real -> (real * real) * (real * real) list -> real * (real
* real)
This can be worked around using additional type annotations but that
doesn't help for inspecting already written code and some people may not
be happy to add so many annotations. (Also, it seems that for function
return types, the annotation must go on the rhs.)
Phil
(* Example *)
type 'a list1 = 'a * 'a list
fun foldl1 f ((x, xs) : 'a list1) = foldl f x xs
fun map1 f ((x, xs) : 'a list1) = (f x, map f xs)
type point = real * real
fun sq (x : real) = x * x
fun distance ((x1, y1) : point) ((x2, y2) : point) =
Math.sqrt (sq (y2 - y1) + sq (x2 - x1));
fun nearest p ps1 =
let
fun nearest2 (i as (di, _), a as (da, _)) =
if di < da
then i
else a
fun addDistance q = (distance p q, q)
in
foldl1 nearest2 (map1 addDistance ps1)
end
;
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml