Created
March 15, 2016 22:38
-
-
Save ChristopherKing42/bb61e60c488b22b119ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Rank2Types, GADTs, LambdaCase #-} | |
data Stream a res where | |
Head :: Stream a a | |
Tail :: Stream a (CoData (Stream a)) | |
newtype CoData con = CoD {unCoD :: forall r. con r -> r} | |
appendList :: [a] -> CoData (Stream a) -> CoData (Stream a) | |
appendList [] s = s | |
appendList (x:xs) s = CoD $ \case | |
Head -> x | |
Tail -> appendList xs s | |
cycle :: [a] -> CoData (Stream a) | |
cycle xs = let r = appendList xs r in r | |
toList :: CoData (Stream a) -> [a] | |
toList (CoD f) = f Head : toList (f Tail) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment