Goop has a first-class map[K] V type that lowers to a Go map[K]V. Use the
prelude Map.* helpers — no @[go] required for ordinary table lookups.
See STYLE.md and 29-maps.md.
let table : map[string] int = Map.make () in
let _ = Map.add table "foo" 1 in
let _ = Map.add table "bar" 2 in
()
Maps are Go reference types: Map.add / Map.remove mutate in place and
return unit.
match Map.get table "foo" with
| Some n -> println (int_to_string n)
| None -> println "missing"
| Binding | Type | Notes |
|---|---|---|
Map.make |
unit -> map['k] 'v |
Empty map |
Map.get |
map['k] 'v -> 'k -> 'v option |
Missing key → None |
Map.add |
map['k] 'v -> 'k -> 'v -> unit |
Insert / overwrite |
Map.remove |
map['k] 'v -> 'k -> unit |
Delete key |
Map.mem |
map['k] 'v -> 'k -> bool |
Membership |
Map.size |
map['k] 'v -> int |
Entry count |
- Write
map[K] V(Go-like brackets for the key; value follows). - Arrows bind outside:
map[string] int -> unitmeans(map[string] int) -> unit. - Function-valued maps need parentheses:
map[string] (int -> int).
import goop . "std.map"
let m = make () (* same as Map.make *)
See maps.goop:
./goop check docs/examples/maps.goop| Message | Cause | Fix |
|---|---|---|
type mismatch on Map.get |
Wrong key or value type | Annotate map[K] V or check call args |
Unexpected parse around -> |
Function-valued map without parens | Use map[string] (int -> int) |
Unbound Map |
Typo / shadowed name | Prelude Map is always in scope |
Full catalog: error reference.
- Go / C interop — maps also appear in Go stubs
- Writing tools — files + maps via
import go - Maps design