Skip to content

Commit 6feaccd

Browse files
committed
feat: update with foldable AE
1 parent 9d2b7b6 commit 6feaccd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Parser.flix

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ mod Parser {
175175
///
176176
/// This is generalization of `literal`.
177177
///
178-
pub def literalSequence(lit: m[a]): Parser[DelayList[a], a] with Eq[a], Foldable[m] =
178+
pub def literalSequence(lit: m[a]): Parser[DelayList[a], a] \ Foldable.Aef[m] with Eq[a], Foldable[m] =
179+
literalSequenceHelper(Foldable.toList(lit))
180+
181+
///
182+
/// Helper for `literalSequence` which does not have the foldable associated effect.
183+
///
184+
def literalSequenceHelper(lit: List[a]): Parser[DelayList[a], a] with Eq[a] =
179185
inp -> inp // Wrap in lambda so the recursive call does not immediately happen
180-
|> match Foldable.toList(lit) {
186+
|> match lit {
181187
case Nil => succeed(ENil)
182-
case x :: xs => (literal(x) `then` (literalSequence(xs))) `using` cons
188+
case x :: xs => (literal(x) `then` (literalSequenceHelper(xs))) `using` cons
183189
}
184190

185191
///
@@ -211,7 +217,7 @@ mod Parser {
211217
///
212218
/// Returns a parser that recognizes any of the elements in `syms`.
213219
///
214-
pub def any(f: a -> Parser[b, c], syms: m[a]): Parser[b, c] with Foldable[m] =
220+
pub def any(f: a -> Parser[b, c], syms: m[a]): Parser[b, c] \ Foldable.Aef[m] with Foldable[m] =
215221
Foldable.foldRight(f >> otherwise, fail, syms)
216222

217223
///
@@ -223,7 +229,7 @@ mod Parser {
223229
///
224230
/// Returns `chars` as a string.
225231
///
226-
pub def stringify(chars: m[Char]): String with Foldable[m] = region r {
232+
pub def stringify(chars: m[Char]): String \ Foldable.Aef[m] with Foldable[m] = region r {
227233
let sb = StringBuilder.empty(r);
228234
let ap = sb |> flip(StringBuilder.append!);
229235
Foldable.forEach(ap, chars);

test/TestParser.flix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod TestParser {
2929

3030
def noInput(): Input[Char] = ENil
3131

32-
def l2d(l: m[a]): DelayList[a] with Foldable[m] = Foldable.toDelayList(l)
32+
def l2d(l: m[a]): DelayList[a] \Foldable.Aef[m] with Foldable[m] = Foldable.toDelayList(l)
3333

3434
def d2l(l: DelayList[a]): List[a] = DelayList.toList(l)
3535

0 commit comments

Comments
 (0)