Created
May 10, 2017 03:10
-
-
Save as-capabl/386235886d286a86f1f6f6012bd14810 to your computer and use it in GitHub Desktop.
Writerっぽくリスト作れて、遅延評価とかfoldr/buildとか効くヤツ
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
module Main where | |
import Control.Monad.Free.Church | |
import GHC.Exts (build) | |
import Control.Monad (forever) | |
type Builder b = F ((,) b) | |
putB :: b -> Builder b () | |
putB x = liftF (x, ()) | |
bToList :: Builder b a -> [b] | |
bToList x = build $ \cons nil -> runF x (const nil) (uncurry cons) | |
main :: IO () | |
main = print $ take 10 $ bToList $ forever (putB "a") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment