1 module Behaviour(Trace(..),(+++),approx,cut) where
    2 
    3 infixr 2 :>
    4 
    5 data Trace a
    6   = Step (Trace a)
    7   | a :> Trace a
    8   | End
    9   | Crash
   10   | Cut
   11   deriving (Eq, Show)
   12 
   13 (+++) :: Trace a -> Trace a -> Trace a
   14 Step s   +++ t = Step (s +++ t)
   15 (x :> s) +++ t = x :> (s +++ t)
   16 End      +++ t = t
   17 Crash    +++ t = Crash
   18 Cut      +++ _ = Cut
   19 
   20 cut :: Integer -> Trace a -> Trace a
   21 cut 0 _ = Cut
   22 cut n (a :> s) = a :> cut (n - 1) s
   23 cut n (Step s) = Step $ cut (n - 1) s
   24 cut n Crash    = Crash
   25 cut n End      = End
   26 cut n Cut      = Cut
   27 
   28 approx :: Eq a => Integer -> Trace a -> Trace a -> Bool
   29 approx n s t = cut n s == cut n t
   30