Skip to content

Instantly share code, notes, and snippets.

@michaelt michaelt/Sink.hs
Created Oct 5, 2016

Embed
What would you like to do?
oneShot + Sink
module Main (main) where
import System.IO.Error
import GHC.Magic
data Sink = Await (Maybe Char -> Sink) | Done Int
countFrom :: Int -> Sink
countFrom n = let k = countFrom $! n + 1
-- in Await $ \mi -> case mi of
in Await $ oneShot $ \mi -> case mi of
Nothing -> Done n
Just _ -> k
feedFrom :: Int -> Sink -> IO ()
feedFrom _ (Done n) = print n
feedFrom 0 (Await f) = feedFrom 0 (case f $ Nothing of a -> a)
feedFrom n (Await f) = feedFrom (n - 1) (case f $ Just 'A' of a -> a)
main :: IO ()
main = let a = feedFrom 10000000 (countFrom 0) in a >> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.