[Haskell-cafe] Declaring a tuple of instances of Enums as an instance of the Enum class

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sun May 23 09:59:41 EDT 2010


Daniel Fischer <daniel.is.fischer at web.de> writes:

> On Sunday 23 May 2010 15:33:58, Ivan Lazar Miljenovic wrote:
>> R J <rj248842 at hotmail.com> writes:
>> > Say I've got a type "Month" declared as an instance of the "Enum"
>> > class, and a type "MonthPair" declared as a pair of months:
>> > data Month = January | February | March | April | May | June | July |
>> > August | September | October | November | December deriving (Eq, Enum,
>> > Ord, Show)
>> > type MonthPair = (Month, Month) deriving (Enum)
>> > The "deriving" on "MonthPair" gives me the error "parse error on input
>> > deriving'".
>>
>> You can't derive instances for type aliases (as its mainly there for
>> documentation reasons, etc.).  However, pairs don't have Enum instances
>> by default so you still can't use its instance.
>>
>> If you define "data MonthPair = MonthPair Month Month" then you should
>> be able to derive Enum.
>
> No, per the report (http://haskell.org/onlinereport/derived.html)
>
> "Derived instance declarations for the class Enum are only possible for 
> enumerations (data types with only nullary constructors)."

Whoops, you're right.

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list