Search code examples
haskellquickcheckpattern-synonyms

How to explicitly import 'Fn' pattern from Test.QuickCheck?


Haskell's Test.QuickCheck module exports pattern Fn, which I have been using.

When I import it with:

import Test.QuickCheck

it works fine. However, when I import it with:

import Test.QuickCheck (Fn)

I get an error: Module ‘Test.QuickCheck’ does not export ‘Fn’. I have also tried import Test.QuickCheck (Fun(Fn)), but get a similar error doing that.

As mentioned, the blanket import works, but here my preference is to use explicit imports so that I can easily see where each imported term came from. Is it possible to import such 'patterns' explicitly?


Solution

  • You can't do import Test.QuickCheck (Fun(Fn)) because, although Fn does construct a Fun value, it is not actually one of the associated constructors of this type. Rather, it is a standalone pattern synonym. As such, you need the corresponding extension to explicitly import it:

    {-# LANGUAGE PatternSynonyms #-}
    import Test.QuickCheck (pattern Fn)