Instances for BaudRate from System.Posix.Terminal
Stephan Friedrichs
deduktionstheorem at googlemail.com
Tue Apr 26 11:44:57 CEST 2011
On 26/04/11 10:19, Heka Treep wrote:
> Hi, the c-libraries use BaudRate as integers, so how about to add Enum
> instance for BaudRate? It allow users to use fromEnum, toEnum methods.
>
> Like this:
>
> module System.Posix.Terminal (
> ...
>
> data BaudRate
> = B0
> ...
> | B115200
> deriving ( Eq, Ord )
>
> instance Enum BaudRate where
> fromEnum b = case b of
> B0 -> 0
> B50 -> 50
> B75 -> 75
> [...]
> toEnum i = case i of
> 0 -> B0
> 50 -> B50
> 75 -> B75
> [...]
This way, the default implementations of
- succ, pred
- enumFrom, enumFromTo, enumFromThen, enumFromThenTo
will fail, because, e.g. succ B0 ~> toEnum (0 + 1) ~> error ...
Do you want succ B0 to be B50? Does [B0,B75..] make sense?
//Stephan
More information about the Libraries
mailing list