Created
April 12, 2019 00:44
-
-
Save mtolly/a077a6a0bb91f4f044ca0222fa8e0ce9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment