testing - Debugging infinite Sum in Haskell -


say have function (it doesn't have practical application, academic interest, weird way write it, monoids, applicative functors , fixpoint combinators)

f :: num => -> sum f = fix ((<>) <$> sum <*>) 

it typechecks, can't sure expected before can test it.

how 1 go testing and/or debugging it? mean seeing result after several iterations possible take 10 [1..].

i know little simple debugging facilities of ghci :break , :step, steps non-terminating calculation can't inspect (it's problematic ^c it). , can't figure how use trace debug module in function either.

any pointers appreciated.

package chasingbottoms approxshow can explore partially evaluated 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, here can’t use directly: summation on integers strict, unlike (:) used build list. therefore type should used.

first, imports (we need able derive data, approxshow used show our custom type):

{-# language derivedatatypeable #-}  import data.data import data.monoid import data.function import control.applicative import test.chasingbottoms.approxshow 

the type (very basic), , num instance:

data s = n integer | s :+ s   deriving (typeable, data)  instance num s   (+) = (:+)   frominteger = n   --other operations not need implemented 

finally, function:

f :: s -> sum s f = fix ((<>) <$> sum <*>) 

and here how can see f doing with, say, common number such 1:

*main> approxshow 5 (getsum (f 1)) "(n 1) :+ ((n 1) :+ ((n 1) :+ ((n _) :+ (_ :+ _))))" 

of course, may more interesting watch evolution:

*main> control.monad.form_ [0..7] $ \i -> putstrln $ approxshow (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 _) :+ (_ :+ _)))))) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -