Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
- {-# LANGUAGE OverloadedStrings #-}
- {-# LANGUAGE TypeFamilies #-}
- module Main where
- import Control.Monad.Trans.Writer
- import Data.String (IsString (..))
- newtype ListBuilder e a = ListBuilder { runListBuilder :: Writer [e] a }
- deriving (Functor, Applicative, Monad)
- instance (IsString e, a ~ ()) => IsString (ListBuilder e a) where
- fromString s = ListBuilder $ tell [fromString s]
- el :: e -> ListBuilder e ()
- el x = ListBuilder $ tell [x]
- buildInfo :: Config -> String
- buildInfo config = unlines $ execWriter $ runListBuilder $ do
- "************** INFORMATION **************"
- "Welcome to the Hydraulic Press Channel."
- "Here is your configuration:"
- ""
- el $ " depth: " ++ show (depth config)
- el $ " width: " ++ show (width config)
- ""
- "*****************************************"
- data Config = Config { depth :: Int, width :: Int }
- main :: IO ()
- main = putStrLn $ buildInfo defaultConfig
- defaultConfig :: Config
- defaultConfig = Config { depth = 5, width = 10 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement