Using Template Haskell to derive classes -


so, found myself doing this:

newtype t x = t x deriving (eq, ord, ...)  

and thought annoying, i'm thinking making package, using template haskell, adds instances in base.

perhaps more flexible dealing what's above.

firstly, seems template haskell can spit out declarations, think want use standalone deriving. in general, think want produce declarations this:

deriving instance (f x1, f x2, ... , f xn) => t x1 x2 x3 

where f replaced eq, ord, etc.

but right hand side bit more complex, example:

deriving instance (f x1, f x2, ... , f xn) => t x1 (maybe x2) x3 

or maybe even

deriving instance (f x1, f x2, ... , f xn) => t x1 (t2 x2 x3) 

you have repeats:

deriving instance f x => t x x 

lets simplify things moment here, , assume there 1 parameter on left. we're looking @ instances this:

deriving instance f x => t (some stuff involving x) 

i figure need function following:

(name -> type) -> q [dec] 

then keep each class in base in list (i.e. eq, ord etc). each class of list, create dummy variable, apply class on left hand side of =>, , pass name -> type argument passed right hand side of =>. can spit out splice.

i think can template haskell above function, problem is, how user use template haskell function?

i think \x -> [| usert x x |] won't work, it?

i want user able like:

data t = t (maybe t)  deriveclasses (\x -> x)  

how can make sort of thing nice end user? hope question makes sort of sense, thing i'm focused on form that's easy user use. when comes actual writing of template haskell think should able handle that.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -