Advertisement
Guest User

Hashable instance with random numbers

a guest
May 25th, 2011
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. instance Hashable LeafExpr where
  2. hash (Var name) = hash "Leaf-Var" + 418871 * hash name
  3. hash Star = hash "Leaf-Star"
  4. hash (Const n) = hash "Leaf-Const" + 284551 * n
  5.  
  6. instance Hashable UnaryOp where
  7. hash (Neg) = hash "Unary-Neg"
  8. hash (BinNot) = hash "Unary-BinNot"
  9.  
  10. instance Hashable BinaryOp where
  11. hash (Plus) = hash "Binary-Plus"
  12. hash (Minus) = hash "Binary-Minus"
  13. hash (Times) = hash "Binary-Times"
  14. hash (Div) = hash "Binary-Div"
  15. hash (Mod) = hash "Binary-Mod"
  16.  
  17. instance Hashable NodeExpr where
  18. hash (Leaf node) = hash "Leaf" + 770291 * hash node
  19. hash (Unary op node) = hash "Unary" +
  20. 246509 * hash op +
  21. 845723 * hash node
  22. hash (Binary op node node') = hash "Binary" +
  23. 1265233 * hash op +
  24. 511013 * hash node +
  25. 1296781 * hash node'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement