Skip to content

Commit d8fe280

Browse files
authored
Merge pull request #29 from phadej/unzip
Add unzip example
2 parents 74c8855 + 737d94f commit d8fe280

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

examples/unzip.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- example that unzip does some work before returning the result pair
2+
3+
-- some generator which does some work before producing the elements of a list
4+
generate = (\x -> \y ->
5+
if le y 0 then Nil else
6+
if le x 0 then Nil else
7+
Cons (Pair x y) (@generate (sub x 1) (sub y 1))
8+
)
9+
10+
unzip = (\xs -> case xs of {
11+
Nil -> Pair Nil Nil;
12+
Cons xy xys -> case xy of {
13+
Pair x y -> let r = @unzip xys in Pair (Cons x (fst r)) (Cons y (snd r))
14+
}
15+
})
16+
17+
main = @unzip (@generate 1 2)

0 commit comments

Comments
 (0)