Here’s an example where I want to create a map with integer values only
within a certain range. Is this a crazy thing to do? I’m also not sure if
this is something best left to ATS2.
Firstly, it appears I’m not sure how to create a “new” dependent type
(highlighted in yellow):
absviewtype gIdxMap
typedef gIdxMap (n:int) = gIdxMap n
extern
fun gIdxMap_find {n:nat} (mp: &gIdxMap n, k: string): intBtw(0,n) i
extern
fun gIdxMap_free(mp: gIdxMap):<> void
extern
fun gIdxMap_insert {i,n:nat | i < n} (mp: &gIdxMap n, gene: string, ival:
intBtw(0,n) i
):<> bool
extern
fun gIdxMap_make_nil(): gIdxMap
local
staload LM = "libats/SATS/linmap_avltree.sats"
staload _ = "libats/DATS/linmap_avltree.dats"
assume gIdxMap = {n:nat} $LM.map(string, intBtw(0,n))
in // in of [local]
implement
gIdxMap_make_nil() = $LM.linmap_make_nil {string, int} ()
implement
gIdxMap_find {n:nat} (mp n, k): intBtw(0,n) i = let
var res: int?
val b = $LM.linmap_search (mp, k, lam(x,y)
=> compare_string_string(x,y), res)
in
if b then let
prval () = opt_unsome {int} (res)
in res end
else let
prval () = opt_unnone {int} (res)
in ( (* print(k + “not found\n”); $raise MapKeyNotFound;*) ~1.0) end
end // end of [gIdxMap_find]
implement
gIdxMap_free(mp) = $LM.linmap_free(mp)
implement
gIdxMap_insert (mp n,gene, ival i) = let
var rdval: int?
val b = $LM.linmap_insert<string,int>
(mp, gene, dval, lam(x,y) => compare_string_string(x,y),rdval)
//How does this work?:
prval () = opt_clear (rdval)
in b end
end // end of [local]