Files
Ian Denhardt f569041319 Add examples from the tutorial to the examples/ directory.
This will be more handy, and it also makes sure they actually build
(provided we remember to sync them -- it would be good to automate
that). This caught the regressions fixed in the previous two commits.
2019-01-13 19:25:16 -05:00

22 lines
716 B
Haskell

{-# LANGUAGE ScopedTypeVariables #-}
module Examples.Serialization.LowLevel.Read (main) where
import Prelude hiding (length)
import Capnp
(ConstMsg, defaultLimit, evalLimitT, getValue, index, length, textBytes)
import Capnp.Gen.Addressbook
import Control.Monad (forM_)
import Control.Monad.Trans (lift)
import qualified Data.ByteString.Char8 as BS8
main :: IO ()
main = do
addressbook :: AddressBook ConstMsg <- getValue defaultLimit
evalLimitT defaultLimit $ do
people <- get_AddressBook'people addressbook
forM_ [0..length people - 1] $ \i -> do
name <- index i people >>= get_Person'name >>= textBytes
lift $ BS8.putStrLn name