Ian, This requires dynamic typing using Data.Dynamic (for application) and Data.Typeable (to do the typing). Namely, you are asking for the "dynApply" function: ---- START CODE import Data.Dynamic import Data.Typeable import Control.Monad maybeApp :: (Typeable a, Typeable b, Typeable c) => a -> b -> Maybe c maybeApp a = join . fmap fromDynamic . dynApply (toDyn a) . toDyn ---- END CODE In the above we obtain representations of your types in the form of "Dynamic" data types using toDyn. Then, using dynApply, we get a value of type "Maybe Dynamic", which we convert back into a "c" type with fromDynamic. The "join" is just there to collapse the type from a "Maybe (Maybe c)" into the desired type of "Maybe c". Cheers, Thomas P.S. If I totally misunderstood, and you want static typing then you just need to realize you _don't_ want types "a" and "b" (fully polymorphic) but rather types (b -> c) and b: apply :: (b -> c) -> b -> c apply a b = a b But this seems rather silly, so I hope you were looking for my first answer. On Wed, Jul 6, 2011 at 2:12 AM, Ian Childs <ian.childs@hertford.ox.ac.uk> wrote:
Suppose I have two terms s and t of type "a" and "b" respectively, and I want to write a function that returns s applied to t if "a" is an arrow type of form "b -> c", and nothing otherwise. How do i convince the compiler to accept the functional application only in the correct instance?
Thanks, Ian
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe