[Haskell-cafe] Polymorphic function over pairs of maybes.
Stephen Tetley
stephen.tetley at gmail.com
Tue Dec 28 21:26:08 CET 2010
On 28 December 2010 19:23, Edward Amsden <eca7215 at cs.rit.edu> wrote:
> 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.
More information about the Haskell-Cafe
mailing list