Skip to content

Instantly share code, notes, and snippets.

@iyefrat

iyefrat/Build.hs Secret

Created November 27, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyefrat/dd1d6f124f298a053dad6824681a7795 to your computer and use it in GitHub Desktop.
Save iyefrat/dd1d6f124f298a053dad6824681a7795 to your computer and use it in GitHub Desktop.
a program that given an input, generates a more complex state from it, using both infromation from IO and known variables.
{-# LANGUAGE NamedFieldPuns #-}
module Build where
import System.IO
import Control.Monad
data State = State {word :: String
,word1 :: String
,word2 :: String
,word3 :: String}
deriving (Show)
state = State "hi" "one hi" "two hi" "bye"
main :: IO ()
main = forever $ do
contents <- readFile "state.txt"
let one:_ = lines contents
let two = "cached two"
_ <- putStr "Input a word: "
word <- getLine
let word1 = unwords [one,word]
let word2 = unwords [two,word]
print $ state {word,word1,word2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment