The ChasingBottoms package with approxShow can help you learn partially estimated values:
$ cabal install ChasingBottoms $ ghci > import Test.ChasingBottoms.ApproxShow > import Data.Function > approxShow 10 (fix (1:)) "[1, 1, 1, 1, 1, 1, 1, 1, 1, _"
However, we cannot use it directly here: the summation over Integer is strict, unlike (:) , which is used to build the list. Therefore, a different type should be used.
Firstly, some import operations (we also need to be able to output Data , so approxShow can be used to display our custom type):
{-# LANGUAGE DeriveDataTypeable #-} import Data.Data import Data.Monoid import Data.Function import Control.Applicative import Test.ChasingBottoms.ApproxShow
The type itself (very simple) and its Num instance:
data S = N Integer | S :+ S deriving (Typeable, Data) instance Num S where (+) = (:+) fromInteger = N --other operations do not need to be implemented
Finally, the function:
f :: S -> Sum S f = fix ((<>) <$> Sum <*>)
And here is how we can see what f does, for example, with a total number such as 1:
*Main> approxShow 5 (getSum (f 1)) "(N 1) :+ ((N 1) :+ ((N 1) :+ ((N _) :+ (_ :+ _))))"
Of course, it may be more interesting to observe evolution:
*Main> Control.Monad.forM_ [0..7] $ \i -> putStrLn $ approxShow i (getSum (f 1)) _ _ :+ _ (N _) :+ (_ :+ _) (N 1) :+ ((N _) :+ (_ :+ _)) (N 1) :+ ((N 1) :+ ((N _) :+ (_ :+ _))) (N 1) :+ ((N 1) :+ ((N 1) :+ ((N _) :+ (_ :+ _)))) (N 1) :+ ((N 1) :+ ((N 1) :+ ((N 1) :+ ((N _) :+ (_ :+ _))))) (N 1) :+ ((N 1) :+ ((N 1) :+ ((N 1) :+ ((N 1) :+ ((N _) :+ (_ :+ _))))))