notes/pl/hs/haskell-streams.txt
Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

15 строки
408 B
Plaintext
Исходник Ответственный История

Этот файл содержит неоднозначные символы Юникода

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

data Stream a = a :& Stream a
unfoldStream :: (b -> (a, b)) -> b -> Stream a
unfoldStream f = \b -> case f b of
(a, b) -> a :& unfoldStream f b
iterate :: (a -> a) -> a -> Stream a
iterate f = unfoldStream $ \a -> (a, f a)
repeat :: a -> Stream a
repeat = unfoldStream $ \a -> (a, a)
zip :: Stream a -> Stream b -> Stream (a, b)
zip = curry $ unfoldStream $ \(a :& as, b :& bs) -> ((a, b), (as, bs))