haskell - Defining TH Lift instances for algebraic data types -


Suppose I have an algebraic data type with several constructors, such as

  data Animal a = mouse a | Beaver one | Rabbit   

How do I create a lift example effectively? The easiest way to do this would be

  example (lift A) => Lift (animal A) where lift (mouse x) = [| Mouse X |] Lift (Beaver X) = [| Beaver X |] Lift (Rabbit X) = [| Rabbit x |]   

However this is very redundant. Of course I can not remove different animals directly, such as lifts x = [| X |] , although it has been guessed what I want to achieve. Is there a way to do this in TH that I do not have to rewrite the same line for every data constructor?

This is the purpose of the th-lift package, which actually provides this functionality:

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -