Guest User

Untitled

a guest
Dec 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. {-
  2.  
  3. Compiled code for:
  4.  
  5. id x = x
  6. compose f g x = f (g x)
  7.  
  8. main = print_int (compose (\x -> x) (\x -> x) 999)
  9.  
  10.  
  11.  
  12. It doesn't eliminate the id functions.
  13.  
  14.  
  15. But if I compile:
  16.  
  17. ...
  18. main = print_int ((\x -> x) ((\x -> x) 999))
  19.  
  20. This program has the calls to id optimised away
  21.  
  22.  
  23. I could 'fix' this by writing my own inliner before going to grin, but
  24. it feels like grin might be able to do the optimistion for me.
  25.  
  26. -}
  27.  
  28. eval p.0 =
  29. v.0 <- fetch p.0
  30. case v.0 of
  31. #default ->
  32. pure v.0
  33. (Fap1 a.0 a.1) ->
  34. res.0 <- ap1 $ a.0 a.1
  35. update p.0 res.0
  36. pure res.0
  37. (Fv1 a.2 a.3 a.4) ->
  38. res.1 <- v1 $ a.2 a.3 a.4
  39. update p.0 res.1
  40. pure res.1
  41. (Fv2 a.5) ->
  42. res.2 <- v2 $ a.5
  43. update p.0 res.2
  44. pure res.2
  45. (Fv3 a.6) ->
  46. res.3 <- v3 $ a.6
  47. update p.0 res.3
  48. pure res.3
  49.  
  50. apply p.1 x.0 =
  51. case p.1 of
  52. (P1ap1 a.7) ->
  53. ap1 $ a.7 x.0
  54. (P2ap1) ->
  55. pure (P1ap1 x.0)
  56. (P1v1 a.8 a.9) ->
  57. v1 $ a.8 a.9 x.0
  58. (P2v1 a.10) ->
  59. pure (P1v1 a.10 x.0)
  60. (P3v1) ->
  61. pure (P2v1 x.0)
  62. (P1v2) ->
  63. v2 $ x.0
  64. (P1v3) ->
  65. v3 $ x.0
  66.  
  67. ap1 x0 x1 =
  68. b1 <- eval $ x0
  69. apply $ b1 x1
  70.  
  71. v1 v4 v5 v6 =
  72. v7 <- store (Fap1 v5 v6)
  73. v8 <- ap1 $ v4 v7
  74. pure v8
  75.  
  76. v2 v9 =
  77. v10 <- eval $ v9
  78. pure v10
  79.  
  80. v3 v11 =
  81. v12 <- eval $ v11
  82. pure v12
  83.  
  84. grinMain =
  85. v13 <- store (P1v2)
  86. v14 <- store (P1v3)
  87. v15 <- store (CInt 999)
  88. v16 <- store (Fv1 v13 v14 v15)
  89. (CInt v17) <- eval $ v16
  90. v18 <- _prim_int_print $ v17
  91. pure v18
Add Comment
Please, Sign In to add comment