Consider the type of a function from a
's to pairs of b
's and c
's, a -> (b, c)
. (I'll use Haskell notation for types and functions, but this isn't a question about Haskell per se.) There are many such functions, including those where both, one, or none of the (b, c)
outputs depends on a
.
Suppose, in particular, that the first output depends on a
, but the second doesn't (for example as in \a -> (a, ())
). Is it possible to write a type in polymorphic lambda calculus or Hindley-Milner characterizing all and only such functions -- in other words, the subspace of a -> (b, c)
which is isomorphic to (a -> b, c)
? In other words, can we define an f :: d
(for some type d
) such that f (\a -> (a, ()))
, f (\a -> (a, 1))
, ..., are all well typed, but f (\a -> (a, a))
, f (\a -> (a, snd a))
, ..., all aren't?
Alternatively, is there any way of statically ensuring that an element of a -> (b, c)
has this property?