Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell DeriveGeneric pragma not being recognized

Tags:

haskell

pragma

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.

like image 360
Mittenchops Avatar asked Oct 26 '25 16:10

Mittenchops


1 Answers

You also need to import GHC.Generics:

-- other imports
import GHC.Generics
-- more imports
like image 116
Mark Seemann Avatar answered Oct 28 '25 07:10

Mark Seemann