module - Surprising behavior of transparent signature ascription -
i want define own abstract type 'a foo
, that, 'a ref
, eqtype
if 'a
isn't. example:
lolcathost% poly poly/ml 5.5.2 release > signature foo = # sig # eqtype 'a foo # val bar : real foo # val qux : real foo # end; signature foo = sig val bar : real foo type 'a foo val qux : real foo end > structure foo : foo = # struct # datatype 'a wat = wat of 'a # type 'a foo = 'a wat ref # val bar = ref (wat 0.0) # val qux = ref (wat 0.0) # end; structure foo : foo > foo.bar = foo.qux; val = false: bool
so far, good! now:
> !foo.bar; val = wat 0.0: real wat > !foo.qux; val = wat 0.0: real wat
wait. isn't wat
supposed hidden? why seeing values of type real wat
?
isn't
wat
supposed hidden?
it's "hidden" in sense code cannot refer it; since human aware of it, there's no reason repl evasive it.
why seeing values of type
real wat
?
why not? identifier wat
not in scope, type-name still exists. there's no reason there can't values of types involve it.
(the same thing possible without signatures; like
local datatype 'a wat = wat of 'a in val = wat 0.0 end
is valid, , has similar effect.)
since don't want outside code know
'a foo
internally'a wat ref
, means!foo.bar
,!foo.qux
should not typecheck in first place.
if don't want outside code know 'a foo
internally 'a wat ref
, shouldn't use transparent ascription; whole point of transparent ascription outside code still knows type if signature doesn't specify (as opposed opaque ascription, outside code has what's specified in signature).
i want define own abstract type
'a foo
, that,'a ref
,eqtype
if'a
isn't.
unfortunately, not possible. the definition of standard ml (revised) (which defines standard ml '97, part) lays out exact set of equality types in §4.4 "types , type functions", on page 17. constructed type admits equality if (1) type name , of type arguments admit equality or (2) type name 1 denoted ref
. in case, since 'a
isn't equality type, , foo
not ref
, 'a foo
doesn't admit equality.
(note: should mention definition little bit wrong here, in the standard ml basis library specifies few additional type names have same special property ref
, , compilers implement these well. extension adds more hardcoding; doesn't add way programmers create additional such type names.)
Comments
Post a Comment