{-# LANGUAGE NoMonomorphismRestriction #-} module Main where import Data.Monoid import Control.Applicative import Control.Monad.Writer.Strict import Control.Monad import System data Tree = Node [Tree] inc = tell (Sum 1) node x = inc >> return (Node x) make 0 = node [] make depth = replicateM 2 (make (depth -1)) >>= node main = do depth <- depthArgs <$> getArgs let counter = getSum . execWriter . make $ depth print counter where depthArgs :: [String] -> Int depthArgs [] = 10 depthArgs [x] = read x