Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. data W = Constr (A -> W) (B -> C -> W) D W
  2.  
  3. foldW :: ((A -> x) -> (B -> C -> x) -> D -> x -> x)
  4. -> W
  5. -> x
  6. foldW f (Constr aw bcw d w) =
  7. f (a -> foldW f (aw a))
  8. (b c -> foldW f (bcw b c))
  9. d
  10. (foldW f w)
  11.  
  12. recW :: ((A - W) -> (A -> x) -> (B -> C -> W) -> (B -> C -> x) -> D -> W -> x -> x)
  13. -> W
  14. -> x
  15. recW f (Constr aw bcw d w) =
  16. f aw
  17. (a -> recW f (aw a))
  18. bcw
  19. (b c -> recW f (bcw b c))
  20. d
  21. w
  22. (recW f w)
  23.  
  24. data N = Zero | Succ N
  25.  
  26. foldN :: x -> (x -> x) -> N -> x
  27. foldN z s Zero = z
  28. foldN z s (Succ n) = s (foldN z s n)
  29.  
  30. recN :: x -> (N -> x -> x) -> N -> x
  31. recN z s Zero = z
  32. recN z s (Succ n) = s n (recN z s n)
  33.  
  34. recN :: x -> (N -> x -> x) -> N -> x
  35. recN z s n = snd (foldN (Zero, z) ((m, x) -> (Succ m, s m x)) n)
  36.  
  37. recW :: ((A - W) -> (A -> x) -> (B -> C -> W) -> (B -> C -> x) -> D -> W -> x -> x)
  38. -> W
  39. -> x
  40. recW f w =
  41. snd (foldW
  42. (awx bcwx d (w', x) ->
  43. (Constr (a -> fst (awx a)) (b c -> fst (bcwx b c)) d w',
  44. f (a -> fst (awx a))
  45. (a -> snd (awx a))
  46. (b c -> fst (bcwx b c))
  47. (b c -> snd (bcwx b c))
  48. d
  49. w'
  50. x))
  51. w)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement