forked from gluon-lang/gluon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a mutable string type to the ST monad
This can be used to efficiently construct strings
- Loading branch information
Showing
8 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
let { Eff, ? } = import! std.effect | ||
let { State, send_state, make_call } = import! std.effect.st | ||
let prim @ { StringBuf } = import! std.effect.st.string.prim | ||
|
||
let new : forall s . Eff [| st : State s | r | ] (StringBuf s) = | ||
send_state (make_call prim.new) | ||
|
||
let len buf : StringBuf s -> Eff [| st : State s | r | ] Int = | ||
send_state (make_call (\_ -> prim.len buf)) | ||
|
||
let push_str buf str : StringBuf s -> String -> Eff [| st : State s | r | ] () = | ||
send_state (make_call (\_ -> prim.push_str buf str)) | ||
|
||
let slice buf start end : StringBuf s -> Int -> Int -> Eff [| st : State s | r | ] String = | ||
send_state (make_call (\_ -> prim.slice buf start end)) | ||
|
||
/// ``` | ||
/// let { assert_eq, ? } = import! std.test | ||
/// let st = import! std.effect.st | ||
/// let string_buf = import! std.effect.st.string | ||
/// let { (*>) } = import! std.applicative | ||
/// let { Eff, run_pure, ? } = import! std.effect | ||
/// | ||
/// let action = | ||
/// do buf = string_buf.new | ||
/// seq string_buf.push_str buf "field:" | ||
/// seq string_buf.push_str buf " " | ||
/// seq string_buf.push_str buf "123" | ||
/// string_buf.read buf | ||
/// assert_eq (run_pure (st.run_state action)) "field: 123" | ||
/// ``` | ||
let read buf : StringBuf s -> Eff [| st : State s | r | ] String = | ||
do l = len buf | ||
slice buf 0 l | ||
|
||
{ | ||
StringBuf, | ||
|
||
new, | ||
len, | ||
push_str, | ||
slice, | ||
read, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters