basic data types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

basic data types

Stanisław Findeisen
Hi

What are those basic data type instances? For example here:
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool
we have:

Instances

Bounded Bool
Enum Bool
Eq Bool
Data Bool
Ord Bool
Read Bool
Show Bool
Ix Bool
Typeable Bool
Generic Bool
Storable Bool

What is the difference between, e.g., Bounded Bool and Enum Bool?

--
This e-mail address is invalid, see:
http://people.eisenbits.com/~stf/public-email-note.html .

OpenPGP: E3D9 C030 88F5 D254 434C  6683 17DD 22A0 8A3B 5CC0


Reply | Threaded
Open this post in threaded view
|

basic data types

Brandon Allbery
2011/12/30 Stanis?aw Findeisen <stf-list at eisenbits.com>

> What is the difference between, e.g., Bounded Bool and Enum Bool?


There is only one Bool type; it is an instance of multiple typeclasses.
 So, for example, it is a Bounded (meaning that there are "minBound" and
"maxBound" values associated with it) and an Enum (meaning that there are
"predecessor" and "successor" functions associated with it).

Look at the definitions of the indicated classes to see what they mean.

--
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111230/34adc8c9/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

basic data types

Peter Hall
In reply to this post by Stanisław Findeisen
A reasonable analogy (though it's not nearly the same thing) for
Haskell classes is Java interfaces. e.g. in Java, Boolean is a class
that implements Serializable and Comparable, while Haskell's Bool type
is an instance of all those classes you listed. In Haskell, the
equivalent of Java's 'class Boolean implements Comparable<Boolean>
...' is 'instance Eq Bool where ... '. In Java you declare the
interfaces that a class implements when the class is declared. In
Haskell, you can add class instances to any type later, not just in
the module that declared the type.

Peter


2011/12/30 Stanis?aw Findeisen <stf-list at eisenbits.com>:

> Hi
>
> What are those basic data type instances? For example here:
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool
> we have:
>
> Instances
>
> Bounded Bool
> Enum Bool
> Eq Bool
> Data Bool
> Ord Bool
> Read Bool
> Show Bool
> Ix Bool
> Typeable Bool
> Generic Bool
> Storable Bool
>
> What is the difference between, e.g., Bounded Bool and Enum Bool?
>
> --
> This e-mail address is invalid, see:
> http://people.eisenbits.com/~stf/public-email-note.html .
>
> OpenPGP: E3D9 C030 88F5 D254 434C ?6683 17DD 22A0 8A3B 5CC0
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners