Guest User

Untitled

a guest
Jan 18th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. module Unify where
  2.  
  3. newtype UVar
  4.  
  5. class Unifiable t where
  6. -- True if two things are considered structurally equal. i.e. toplevelEqual TyArr{} TyArr{} = True
  7. -- Must obey the law: forall t u, toplevelEqual t u ==> (lengthOf plate t == lengthOf plate u)
  8. -- In other words, structurally equal things must have the same number of subterms
  9. toplevelEqual :: t -> t -> Bool
  10.  
  11. class HasVar t a | t -> a where
  12. _Var :: Prism' t a
  13.  
  14. class AsUnificationError e t | e -> t where
  15. _OccursError :: Prism' e (UVar, t)
  16. _MismatchError :: Prism' e (t, t)
  17.  
  18. newtype Unify t m a
  19.  
  20. instance Functor m => Functor (Unify t m) where
  21. instance (Applicative m, Monad m) => Applicative (Unify t m) where -- artifact of equivalence :(
  22. instance Monad m => Monad (Unify t m) where
  23. instance MonadState s m => MonadState s (Unify t m) where
  24. instance MonadError e m => MonadError e (Unify t m) where
  25. instance MonadWriter w m => MonadWriter w (Unify t m) where
  26. instance MonadReader r m => MonadReader r (Unify t m) where
  27.  
  28. fresh :: Monad m => Unify t m UVar
  29.  
  30. occurs :: (HasVar t (Either UVar a), Plated t) => UVar -> t -> Bool
  31.  
  32. union :: (Monad m, Ord t) => t -> t -> Unify t m ()
  33.  
  34. find :: (Plated t, Ord t, Monad m) => t -> Unify t m t
  35.  
  36. unify
  37. :: ( HasVar t (Either UVar a)
  38. , Unifiable t
  39. , Plated t
  40. , Ord t
  41. , AsUnificationError e t
  42. , MonadError e m
  43. )
  44. => t
  45. -> t
  46. -> Unify t m ()
  47.  
  48. runUnify :: (HasVar t (Either UVar v), Monad m, Plated t) => Unify t m res -> m res
Add Comment
Please, Sign In to add comment