Skip to content

Instantly share code, notes, and snippets.

@as-capabl
Created May 10, 2017 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save as-capabl/386235886d286a86f1f6f6012bd14810 to your computer and use it in GitHub Desktop.
Save as-capabl/386235886d286a86f1f6f6012bd14810 to your computer and use it in GitHub Desktop.
Writerっぽくリスト作れて、遅延評価とかfoldr/buildとか効くヤツ
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