
Hi guys, What I understanding `deriving` is Haskell automatically make a type to be a instance of a particular typeclass. If that's the case, the question is How does Haskell do that underline? Take code below as sample, the type Day is now an instance of Bounded. data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Bounded, Enum) Therefore, *minBound :: Day* will produce *Monday*. Just be curious how it is being implemented. Thanks. Simon

On Tue, Jun 14, 2011 at 3:07 PM, Haisheng Wu
Hi guys, What I understanding `deriving` is Haskell automatically make a type to be a instance of a particular typeclass. If that's the case, the question is How does Haskell do that underline?
Take code below as sample, the type Day is now an instance of Bounded.
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Bounded, Enum)
Therefore, minBound :: Day will produce Monday.
Just be curious how it is being implemented.
It takes into account the order of the constructors. Don't know exactly right now, but I think that behind the scenes each of them is tagged appropriately and minBound simply takes the minimum tag or something like that. I'd look into the sources but I am unable to do so right now.

Hi, Simon. You should look at the Data.Derive module to see how to create your own instances.
Cheers, David ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com On Jun 14, 2011, at 8:07 AM, Haisheng Wu wrote:
Hi guys, What I understanding `deriving` is Haskell automatically make a type to be a instance of a particular typeclass. If that's the case, the question is How does Haskell do that underline?
Take code below as sample, the type Day is now an instance of Bounded.
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Bounded, Enum)
Therefore, minBound :: Day will produce Monday.
Just be curious how it is being implemented.
Thanks. Simon _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Not sure exactly what you want to know, but in the language report it
says "For an enumeration, the first and last constructors listed in
the data declaration are the bounds".
http://www.haskell.org/onlinereport/haskell2010/haskellch11.html#x18-1850001...
On 14 June 2011 14:07, Haisheng Wu
Hi guys, What I understanding `deriving` is Haskell automatically make a type to be a instance of a particular typeclass. If that's the case, the question is How does Haskell do that underline?
Take code below as sample, the type Day is now an instance of Bounded.
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Bounded, Enum)
Therefore, minBound :: Day will produce Monday.
Just be curious how it is being implemented.
Thanks. Simon
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
David Place
-
Haisheng Wu
-
Jonas Almström Duregård
-
Mihai Maruseac