Statically typed (hash)maps/dicts?

hi,

Might anybody have thoughts on how to have maps in ATS that can be
nailed down in terms of what keys they can have, and what the type of
the key’s values are? So I can still do map, filter, reduce, etc.,
over them but also use the compiler to make sure e.g. args passed are
statically checked to be of the correct form?

thank you.

thank you for your time & thoughts on this! i’m trying to percolate it
into my thick brain.

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 );

I am not sure if I understand your question.

Could you put out an example to show what kind of static checking is
expected?On Tuesday, September 1, 2015 at 5:14:43 PM UTC-4, Raoul Duke wrote:

hi,

Might anybody have thoughts on how to have maps in ATS that can be
nailed down in terms of what keys they can have, and what the type of
the key’s values are? So I can still do map, filter, reduce, etc.,
over them but also use the compiler to make sure e.g. args passed are
statically checked to be of the correct form?

thank you.

(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};
}

© 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 );