Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. newtype Trace a = Trace ([String], a)
  2.  
  3. instance Monad Trace where
  4. (Trace (traces, x)) >>= f = (Trace (traces ++ t, y))
  5. where
  6. (Trace (t, y)) = f x
  7. return x = Trace ([], x )
  8.  
  9. put :: Show a => String -> a -> Trace ()
  10. put msg v = Trace ([msg ++ " " ++ show v], ())
  11.  
  12. fact :: Integer -> Trace Integer
  13. fact n = do
  14. put "fact" n >> if n == 0
  15. then return 1
  16. else do
  17. m <- fact (n - 1)
  18. return (n * m)
  19.  
  20. main = let Trace (lst, m) = fact 3
  21. in do
  22. print lst
  23. print m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement