Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. {-# LANGUAGE GeneralizedNewtypeDeriving #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3. {-# LANGUAGE TypeFamilies #-}
  4. module Main where
  5.  
  6. import Control.Monad.Trans.Writer
  7. import Data.String (IsString (..))
  8.  
  9. newtype ListBuilder e a = ListBuilder { runListBuilder :: Writer [e] a }
  10. deriving (Functor, Applicative, Monad)
  11.  
  12. instance (IsString e, a ~ ()) => IsString (ListBuilder e a) where
  13. fromString s = ListBuilder $ tell [fromString s]
  14.  
  15. el :: e -> ListBuilder e ()
  16. el x = ListBuilder $ tell [x]
  17.  
  18. buildInfo :: Config -> String
  19. buildInfo config = unlines $ execWriter $ runListBuilder $ do
  20. "************** INFORMATION **************"
  21. "Welcome to the Hydraulic Press Channel."
  22. "Here is your configuration:"
  23. ""
  24. el $ " depth: " ++ show (depth config)
  25. el $ " width: " ++ show (width config)
  26. ""
  27. "*****************************************"
  28.  
  29. data Config = Config { depth :: Int, width :: Int }
  30.  
  31. main :: IO ()
  32. main = putStrLn $ buildInfo defaultConfig
  33.  
  34. defaultConfig :: Config
  35. defaultConfig = Config { depth = 5, width = 10 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement