
On 28 December 2010 19:23, Edward Amsden
Hello all:
I'd like to right a function that could take a structure with type (random example):
(Int, (String, (Int, Int)))
and another where each individual value is a Maybe of the corresponding type, for example: (Maybe Int, (Maybe String, (Maybe Int, Maybe Int)))
and perform a fromMaybe using the values to produce a new value with the original types. The catch is, I'd like to be able to do that for an n-deep structure with any type, without having to write a separate function for them. I'm not even sure that this is possible, but perhaps someone could explain how it is or isn't?
Maybe this is possible with Strafunski or one of the generics libraries that lean in that direction (SYB, KURE, or Oleg Kiselyov's typecase), though I've never looked at descending into two terms at the same time even if they have the same "type shape". http://okmij.org/ftp/Haskell/typecast.html At a meta-level do you have a need for this, or is it just a curiosity? If it is for some real world situation, I suspect there are simpler ways of achieving the functionality you seem to want.