I have some typeclass C
with a function that is supposed to give me the next bigger number, if there is one.
That means for integral types it just does +1
, for types that represent a superset of the whole numbers it is supposed to return Nothing
because there is no definite next number.
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
module Main where
class C a where
cIncr :: a -> Maybe a
instance Integral a => C a where
cIncr x = Just $ x + 1
instance Fractional a => C a where
cIncr _ = Nothing
This gives me following error:
Duplicate instance declarations:
instance Integral a => C a
-- Defined at src/File.hs:7
instance Fractional a => C a
-- Defined at src/File.hs:10
I don't understand why I get this error - why/where do they define the same instances?