Read and print to console
main :: IO ()
main = do
putStrLn (" Hello! what is your name?" )
name <- getLine
putStrLn (" Hello " ++ name ++ " !" )
import System.IO
main :: IO ()
main = do
content <- readFile " hello.txt"
putStrLn (" Content of the file:" )
putStrLn (content)
Reverse content of a file and print it
import System.IO
main :: IO ()
main = do
content <- readFile " hello.txt"
putStrLn (" Reverse content of the file:" )
let rev = reverse content
putStrLn (rev)
Read, parse and print json from file
{-# LANGUAGE DeriveGeneric #-}
module Main where
import System.IO
import Data.Aeson
import qualified Data.ByteString.Lazy as L
import qualified Data.Text as T
import GHC.Generics
data Person = Person
{ name :: T. Text
, firstname :: T. Text
, age :: Int
} deriving (Show , Generic )
instance FromJSON Person
instance ToJSON Person
main :: IO ()
main = do
content <- L. readFile " persons.json"
let persons = decode content :: Maybe [ Person ]
putStrLn (" Content of the file:" )
putStrLn (show persons)