Instances for BaudRate from System.Posix.Terminal

Heka Treep zena.treep at gmail.com
Tue Apr 26 10:19:35 CEST 2011


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
    B110    -> 110
    B134    -> 134
    B150    -> 150
    B200    -> 200
    B300    -> 300
    B600    -> 600
    B1200   -> 1200
    B1800   -> 1800
    B2400   -> 2400
    B4800   -> 4800
    B9600   -> 9600
    B19200  -> 19200
    B38400  -> 38400
    B57600  -> 57600
    B115200 -> 115200
  toEnum i = case i of
    0       -> B0
    50      -> B50
    75      -> B75
    110     -> B110
    134     -> B134
    150     -> B150
    200     -> B200
    300     -> B300
    600     -> B600
    1200    -> B1200
    1800    -> B1800
    2400    -> B2400
    4800    -> B4800
    9600    -> B9600
    19200   -> B19200
    38400   -> B38400
    57600   -> B57600
    115200  -> B115200
    _       -> error $ "unsupported baudrate " ++ show i



More information about the Libraries mailing list