Skip to content

Instantly share code, notes, and snippets.

@snoble
Created November 24, 2023 04:16
Show Gist options
  • Save snoble/7f3b759705f21804f8c73fba7ba74d3e to your computer and use it in GitHub Desktop.
Save snoble/7f3b759705f21804f8c73fba7ba74d3e to your computer and use it in GitHub Desktop.
package ExistTest/FList
enum FList[a, b]:
Pure(fn: a -> b)
Cons(pair: exists c. ((a -> c), FList[c, b]))
def cons[a, b, c](fn: a -> c, tail: FList[c, b]) -> FList[a, b]:
Cons((fn, tail))
def apply[a, b](fn: FList[a, b], a: a) -> b:
recur fn:
Pure(f): f(a)
Cons((f, tail)): apply(tail, f(a))
def length_String(s: String) -> Int:
def loop(s, acc):
recur s:
case "": acc
case "$.{_}${tail}": loop(tail, acc.add(1))
loop(s, 0)
flist = cons(int_to_String, Pure(length_String))
res = flist.apply(523)
test = Assertion(res matches 3, "523 is length 3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment