Skip to content

Instantly share code, notes, and snippets.

@amosr
Created December 8, 2016 03:29
Show Gist options
  • Save amosr/724c68a9d4173b588b077f8f2361ea58 to your computer and use it in GitHub Desktop.
Save amosr/724c68a9d4173b588b077f8f2361ea58 to your computer and use it in GitHub Desktop.
Map combinator
module Map
export
map : [a b : Data]. (a -> b) -> Stream# a -> Stream# b
with letrec
unwrap [a : Data] (xx : Tuple1# a) : a = case xx of T1# a -> a
map [a b : Data] (f : a -> b) (as : Stream# a) : Stream# b
= unwrap (stream_1_1# (\inp out. letrec
p1 = pull# inp p2
p2 v = push# out (f v) p3
p3 = drop# inp p1
in p1) as)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment