Polished and tested the code.

The new version uses a slightly more sophisticated algorithm to select the
preferred attribute path among several alternatives. Given several alternatives by
"nix-env -qa *", the latest version is generally preferred. If that version has
more than one attribute path, the one with the shortest initial segment is
preferred, i.e. "haskellPackages" is more desirable than "haskellPackages_ghc742".
If the package has more than one entry in of the same attribute set, then the
shortest path is preferred. If that criteria is still ambiguous, then the
path that is lexicographically smaller is chosen.

For example, the alternatives

  haskellPackages_ghc762.QuickCheck_1_2_0_0  haskell-QuickCheck-ghc7.6.2-1.2.0.0
  haskellPackages_ghc762.QuickCheck1         haskell-QuickCheck-ghc7.6.2-1.2.0.1
  haskellPackages_ghc762.QuickCheck_2_1_1_1  haskell-QuickCheck-ghc7.6.2-2.1.1.1
  haskellPackages_ghc762.QuickCheck_2_4_0_1  haskell-QuickCheck-ghc7.6.2-2.4.0.1
  haskellPackages_ghc762.QuickCheck_2_4_1_1  haskell-QuickCheck-ghc7.6.2-2.4.1.1
  haskellPackages_ghc762.QuickCheck_2_4_2    haskell-QuickCheck-ghc7.6.2-2.4.2
  haskellPackages_ghc762.QuickCheck_2_5_1_1  haskell-QuickCheck-ghc7.6.2-2.5.1.1
  haskellPackages_ghc762.QuickCheck          haskell-QuickCheck-ghc7.6.2-2.6
  haskellPackages.QuickCheck_1_2_0_0         haskell-QuickCheck-ghc7.4.2-1.2.0.0
  haskellPackages.QuickCheck1                haskell-QuickCheck-ghc7.4.2-1.2.0.1
  haskellPackages.QuickCheck_2_1_1_1         haskell-QuickCheck-ghc7.4.2-2.1.1.1
  haskellPackages.QuickCheck_2_4_0_1         haskell-QuickCheck-ghc7.4.2-2.4.0.1
  haskellPackages.QuickCheck_2_4_1_1         haskell-QuickCheck-ghc7.4.2-2.4.1.1
  haskellPackages.QuickCheck_2_4_2           haskell-QuickCheck-ghc7.4.2-2.4.2
  haskellPackages.QuickCheck2                haskell-QuickCheck-ghc7.4.2-2.6
  haskellPackages.QuickCheck                 haskell-QuickCheck-ghc7.4.2-2.5.1.1

are narrowed down to the latest version:

  haskellPackages_ghc762.QuickCheck          haskell-QuickCheck-ghc7.6.2-2.6
  haskellPackages.QuickCheck2                haskell-QuickCheck-ghc7.4.2-2.6

Now,

  haskellPackages.QuickCheck2                haskell-QuickCheck-ghc7.4.2-2.6

is chosen, because its path has the shortest initial segment.