code_junkie

How to infer coercions?

Nov 10th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. coerce :: a -> b
  2. coerce x = REDUCE (cast x) if a and b are incompatible
  3. x otherwise
  4.  
  5. class Cast a, b where {cast :: a -> b };
  6. -- ¬:: is an operator, literally meaning: don’t cast
  7. --(!) is the reduction operator. Perform one stage of reduction.
  8.  
  9. -- Reduce on demand
  10. instance Cast Exp c, c where { inline cast = ¬::(!)(x::(Exp c) -> ¬::(!)x) };
Add Comment
Please, Sign In to add comment