When I uncomment the definition of test and try to compile your code, I get an "ambiguous type variable". Nothing about rigor. To understand why this is ambiguous, consider this:
module Main where data FooT = One | Two deriving (Show, Read) data BarT = Three | Four deriving Show class Footable a where foo2 :: a instance Footable FooT where foo2 = One instance Footable BarT where foo2 = Three main = print foo2
Of course, there is only one instance of Footable in your code, so haskell could theoretically suggest that you want to use foo2 defined for FooT because it is the only instance in the scope. However, if this happens, the code will break as soon as you import a module that will define another instance of Footable, so haskell does not.
To fix your problem, you need to annotate foo2 with your type:
module Main where data FooT = One | Two deriving (Show, Read) class Footable a where foo2 :: a instance Footable FooT where foo2 = One main = print (foo2 :: FooT)
To require all Footables to be instances of Show and Read, simply do:
class (Show a, Read a) => Footable a where foo2 :: a
As in your comments, but without specifying a restriction again in the signature foo2.
source share