Search code examples
haskellpragma

Haskell DeriveGeneric pragma not being recognized


I have the following at the top of my Haskell file:

{-# LANGUAGE DeriveGeneric,  OverloadedStrings,  DefaultSignatures,  TypeOperators,  FlexibleContexts, RecordWildCards, FlexibleInstances, ExtendedDefaultRules #-}

module Main where

import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Text (Text)
import Data.DateTime
import Data.Aeson

newtype Price = Price Float deriving Generic

However, when I run:

$ stack ghci
...
Prelude> :l myfile.hs

[1 of 1] Compiling Main             ( myfile.hs, interpreted )

myfile.hs:13:38: error:
    Not in scope: type constructor or class ‘Generic’
   |
13 | newtype Price = Price Float deriving Generic
   |                                      ^^^^^^^
Failed, no modules loaded.

It seems to not accept my pragma for generics. What am I doing wrong? Looking at similar questions, this seems like it should work.


Solution

  • You also need to import GHC.Generics:

    -- other imports
    import GHC.Generics
    -- more imports