Ah, I see. Had a look at this note:
http://users.cis.fiu.edu/~smithg/cop4555/valrestr.html

So, the point is the if I'm going to write somethink like "val x =
...", then (...) should not do any computation, so it can only consist
of constants, constructors, identifiers, or lamba-expressions. As the
author says, eta expansion fixes the second situation I described:

val f = g o h   ===>   val f = fn x => (g o h) x

However, this only works when the desired value has function type. For
the first situation (replacing a constructor with a function), this
could just be one of those "SML can't do that" situations. To use the
eta-expansion trick, there would need to be something like
parameter-less delayed evaluation (as in e.g. scala). Another thing I
tried was to have a constructor "masquerade" as a function:

signature FOO =
sig
  type 'a T
  val mk : 'a * int -> 'a T
end

structure Foo :> FOO =
struct
  datatype 'a T = mk of ('a * int)
end

but this doesn't work, because Foo.mk (to the outside world) is not a
constructor, but rather its associated function. Also, weird
constructor names are not so good for nice code and error messages.


a


On 15 April 2013 20:57, Tjark Weber <[email protected]> wrote:
> Aleks,
>
> On Mon, 2013-04-15 at 19:15 +0100, Aleks Kissinger wrote:
>> This is more of a standard ML question, but I figure folks here will
>> know. I've always found the situations in which poly/ML allows
>> polymorphic values (versus forcing a monotype) a bit puzzling. [...]
>
> Perhaps others will answer in more detail, but until then, you could
> try searching for "SML value restriction".
>
> Best,
> Tjark
>
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to