We have already used a number of extensions available in GHC, such as MultiParamTypeClasses, TypeFamilies, FlexibleInstances, and so on. The nice thing about most extensions in GHC is that, if you accidentally try to use a language feature that is behind an extension, GHC gives you a hint about which extension you forgot.
In this last section, we'll look at some more useful extensions available in reasonably modern GHC. There are other extensions, of course, and this is just a glimpse. For an exhaustive list of currently supported extensions, see the Language.Haskell.Extension
module from the Cabal
library.
Some of the most confusing type errors originate from the monomorphism restriction (MR). Consider this program:
-- file: mr.hs main = do let f = (1 +) print $ f (6 :: Int) print $ f (0.1 :: Double)
The most general type for f
would be Num a => a → a
. But due to MR, the inferred type is monomorphic in a
. The error message we...