[Haskell-beginners] Automatically "deducing" of wrappers

Baa aquagnu at gmail.com
Fri Oct 6 07:51:49 UTC 2017

Hello, List! This is a little bit theoretical question but not only...
Let's suppose I have a lot of functions like:

  llfunc :: A -> B -> C -> D -> C

and I have types C and HLC and "constructor" of HLC from C:

  makeHLC :: C -> Maybe HLC    -- or Either String HLC

and I want to create "automatically" (i.e. with minimal coding!)
functions like:

  hlfunc :: A -> B -> HLC -> D -> HLC   -- see llfunc

i.e. for each ll* (low-level) to create hl* (high-level). For example,
I can have even HLC -> C function. I may have a lot of llfunc's. Idea
is to replace a coding of hlfunc's with some automatically or
semi-automatically deduce/creating of them. For example, C may be
`FilePath`, HLC may be some kind of `Path a` (wrapper for paths). And I
have a lot of FilePath-based legacy functions.

I suppose it's possible to solve such problem in D language (I made
somthing similar several years ago). And possible it's easy in Nim
(Nimrod) because of them: a) types exist b) meta-programming features.
IMHO should be a way to do similar in Haskell, but it does not look
easy. IMHO I can code arguments + return types with Generic, and next
step may be type class with custom methods C -> HLC/HLC -> C and default
method like `perform` which will get Generic and automatically makes
instance of this type class or... And how will it look like?

Is it even possible in Haskell?

Best regards, Paul

More information about the Beginners mailing list