[Haskell-cafe] Question on rank-N polymorphism

Wouter Swierstra wss at Cs.Nott.AC.UK
Sun Jun 7 12:20:04 EDT 2009

> The idea is that fs accepts a polymorphic function as its argument.
> What type signature can I specify for f in order to compile this code?

As you said yourself, you need to add a type signature to fs:

> {-# LANGUAGE RankNTypes #-}

> fs :: ((forall a . ((a, a) -> a)) -> t) -> (t, t)
> fs g = (g fst, g snd)
> examples = (fs id, fs repeat, fs (\x -> [x]), fs ((,)id))

Hope this helps,


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

More information about the Haskell-Cafe mailing list