{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.List (foldl')
import qualified Data.Map.Strict as Map
data Person = Person
{ name :: String
, age :: Int
} deriving (Show, Eq)
data Tree a
= Leaf
| Node a (Tree a) (Tree a)
deriving (Show)
class Greet a where
greet :: a -> String
instance Greet Person where
greet p = "Hello, " ++ name p ++ "!"
classify :: Int -> String
classify n
| n < 0 = "negative"
| n == 0 = "zero"
| even n = "positive even"
| otherwise = "positive odd"
where
_ = "unused binding"
insert :: Ord a => a -> Tree a -> Tree a
insert x Leaf = Node x Leaf Leaf
insert x (Node y l r)
| x < y = Node y (insert x l) r
| x > y = Node y l (insert x r)
| otherwise = Node y l r
main :: IO ()
main = do
let alice = Person { name = "Alice", age = 30 }
nums = [1 .. 10]
tree = foldl' (flip insert) Leaf nums
table = Map.fromList [("one", 1), ("two", 2)]
putStrLn (greet alice)
mapM_ (\n -> putStrLn (show n ++ " is " ++ classify n)) nums
print tree
print table