SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top