Search code examples
haskelltypessignatureghci

Is is possible to instruct ghci to use a concrete type for a constraint when evaluating the type of an expression?


I can use ghci to evaluate the type of fmap:

Prelude> :t fmap
fmap :: Functor f => (a -> b) -> f a -> f b

Is there a way I can instruct ghci to bind f to a particular instance of Functor and print out the resulting type signature. I.e for [] it would print

(a -> b) -> [a] -> [b]

If not, are there any tricks or roundabout ways to achieve the same? This would be particularly handy for deriving type signatures of more complicated expressions and functors (e.g. (->) a).


Solution

  • The easiest way is

    Prelude> :set -XTypeApplications 
    Prelude> :t fmap @[]
    fmap @[] :: (a -> b) -> [a] -> [b]