Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. datatype tree = L | N of tree * tree
  2.  
  3. datatype herp
  4. = H0
  5. | H1 of tree
  6. | H2 of tree * tree
  7. | H3 of tree * tree * tree
  8. | H4 of tree * tree * tree * tree
  9. | H5 of tree * tree * tree * tree * tree
  10. | H6 of tree * tree * tree * tree * tree * tree
  11. | H8 of tree * tree * tree * tree * tree * tree * tree * tree
  12.  
  13. datatype derp
  14. = D0
  15. | D2 of tree * tree
  16. | D3 of tree * tree * tree
  17. | D4 of tree * tree * tree * tree
  18. | D5 of tree * tree * tree * tree * tree
  19. | D6 of tree * tree * tree * tree * tree * tree
  20. | D7 of tree * tree * tree * tree * tree * tree * tree
  21. | D8 of tree * tree * tree * tree * tree * tree * tree * tree
  22.  
  23. fun foo L = H0
  24. | foo (N (a,L)) = H1 a
  25. | foo (N (a,N (b,L))) = H2 (a,b)
  26. | foo (N (a,N (b,N (c,L)))) = H3 (a,b,c)
  27. | foo (N (a,N (b,N (c,N (d,L))))) = H4 (a,b,c,d)
  28. | foo (N (a,N (b,N (c,N (d,N (e,L)))))) = H5 (a,b,c,d,e)
  29. | foo (N (a,N (b,N (c,N (d,N (e,N (f,L))))))) = H6 (a,b,c,d,e,f)
  30. | foo (N (a,N (b,N (c,N (d,N (e,N (f,N (g,h)))))))) = H8 (a,b,c,d,e,f,g,h)
  31.  
  32. fun foo' H0 = L
  33. | foo' (H1 a) = N (a,L)
  34. | foo' (H2 (a,b)) = N (a,N (b,L))
  35. | foo' (H3 (a,b,c)) = N (a,N (b,N (c,L)))
  36. | foo' (H4 (a,b,c,d)) = N (a,N (b,N (c,N (d,L))))
  37. | foo' (H5 (a,b,c,d,e)) = N (a,N (b,N (c,N (d,N (e,L)))))
  38. | foo' (H6 (a,b,c,d,e,f)) = N (a,N (b,N (c,N (d,N (e,N (f,L))))))
  39. | foo' (H8 (a,b,c,d,e,f,g,h)) = N (a,N (b,N (c,N (d,N (e,N (f,N (g,h)))))))
  40.  
  41. fun bar H0 = D0
  42. | bar (H1 a) = D2 (L,a)
  43. | bar (H2 (a,b)) = D2 (N (L,a),b)
  44. | bar (H3 xs) = D3 xs
  45. | bar (H4 xs) = D4 xs
  46. | bar (H5 xs) = D5 xs
  47. | bar (H6 (L,L,a,b,c,d)) = D2 (N (N (a,b),c),d)
  48. | bar (H6 (L,N(a,b),c,d,e,f)) = D6 (a,b,c,d,e,f)
  49. | bar (H6 (N(a,b),c,d,e,f,g)) = D7 (a,b,c,d,e,f,g)
  50. | bar (H8 xs) = D8 xs
  51.  
  52. fun bar' D0 = H0
  53. | bar' (D2 (L,a)) = H1 a
  54. | bar' (D2 (N (L,a),b)) = H2 (a,b)
  55. | bar' (D2 (N (N (a,b),c),d)) = H6 (L,L,a,b,c,d)
  56. | bar' (D3 xs) = H3 xs
  57. | bar' (D4 xs) = H4 xs
  58. | bar' (D5 xs) = H5 xs
  59. | bar' (D6 (a,b,c,d,e,f)) = H6 (L,N(a,b),c,d,e,f)
  60. | bar' (D7 (a,b,c,d,e,f,g)) = H6 (N(a,b),c,d,e,f,g)
  61. | bar' (D8 xs) = H8 xs
  62.  
  63. fun qux D0 = (L,L,L,L,L,L,L)
  64. | qux (D2 (a,b)) = (L,L,L,L,L,L,N(a,b))
  65. | qux (D3 (a,b,c)) = (L,L,L,L,L,N(a,b),c)
  66. | qux (D4 (a,b,c,d)) = (L,L,L,L,N(a,b),c,d)
  67. | qux (D5 (a,b,c,d,e)) = (L,L,L,N(a,b),c,d,e)
  68. | qux (D6 (a,b,c,d,e,f)) = (L,L,N(a,b),c,d,e,f)
  69. | qux (D7 (a,b,c,d,e,f,g)) = (L,N(a,b),c,d,e,f,g)
  70. | qux (D8 (a,b,c,d,e,f,g,h)) = (N(a,b),c,d,e,f,g,h)
  71.  
  72. fun qux' (L,L,L,L,L,L,L) = D0
  73. | qux' (L,L,L,L,L,L,N(a,b)) = D2 (a,b)
  74. | qux' (L,L,L,L,L,N(a,b),c) = D3 (a,b,c)
  75. | qux' (L,L,L,L,N(a,b),c,d) = D4 (a,b,c,d)
  76. | qux' (L,L,L,N(a,b),c,d,e) = D5 (a,b,c,d,e)
  77. | qux' (L,L,N(a,b),c,d,e,f) = D6 (a,b,c,d,e,f)
  78. | qux' (L,N(a,b),c,d,e,f,g) = D7 (a,b,c,d,e,f,g)
  79. | qux' (N(a,b),c,d,e,f,g,h) = D8 (a,b,c,d,e,f,g,h)
  80.  
  81. val fwd = qux o bar o foo
  82. val bwd = foo' o bar' o qux'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement