Here is one plausible way to support this;
(* ****** ****** )
//
datasort map =
| map_nil of ()
| map_cons of (string, t@ype, map)
//
abstype map(map)
abstype key(string)
//
stacst ismember : (map, string, t@ype) → bool
//
extern
fun
{x:t@ype}
map_get{kxs:map}{k:string | ismember(kxs, k, x)} (map: map(kxs), key: key(k
)): x
extern
fun
{x:t@ype}
map_set{kxs:map}{k:string | ismember(kxs, k, x)} (map: map(kxs), key: key(k
), x: x): void
//
( ****** ****** *)
The built-in constraint-solver cannot handle a constraint involving
‘ismember’,
which needs to be exported so that it can be solved externally.On Tuesday, September 1, 2015 at 11:30:51 PM UTC-4, Raoul Duke wrote:
(A) horrible hacked pseudocode not meant to be seen as any existing
language:
typedef Player = Map{ 'hitPoints : int, 'maxHitPoints : int, ‘x :
float, y’ : float, … };
function move( p:Player, dx:float, dy:float ):Player {
return p.{x=p.x+dx, y=p.y+dy};
}
(B) If something like row types were involved:
function move( p:{x:float, y:float | r}, dx:float, dy:float ):Player {
return p.{x=p.x+dx, y=p.y+dy | r};
}
(C) It would be somehow magically statically illegal to try to do:
var p:Player = Player{x:10, z:20};
or
move( {x:10, z:20}, 10, 20 );