Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Jul 31, 2024
1 parent 4979146 commit 0d2b9f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions std/core-extras.kk
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ pub fun maybe/(==)(m1: maybe<a>, m2: maybe<a>, ?(==): (a, a) -> e bool): e bool
(Nothing, Nothing) -> True
_ -> False

pub fun expect( m : maybe<a>, msg: string ="", ?kk-file-line: string ) : exn a
match m
Just(a) -> a
Nothing -> throw(kk-file-line ++ " expected Just " ++ msg)

pub fun expect-unjust( m : maybe<a>, msg: string ) : exn a
match m
Just(a) -> a
Expand Down
7 changes: 7 additions & 0 deletions std/data/word-set.kk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ inline fun member(s: string, t: word-set): bool

named effect string-intern
fun intern-string(x: string): istring
fun is-interned(x: string): bool

value struct istring
str: string
Expand All @@ -37,8 +38,14 @@ fun string-pool(): <> ev<string-intern>
Nothing ->
trie := add(trie, a)
Istring(a)
fun is-interned(a)
trie.lookup(a).is-just
r

inline fun add-all(s: ev<string-intern>, xs: list<string>): exn ev<string-intern>
xs.foreach(fn(x) {s.intern-string(x); ()})
s

inline fun intern(s: string): exn istring
words.intern-string(s)

Expand Down

0 comments on commit 0d2b9f2

Please sign in to comment.