Fungi-1.0: Data/IntegralLike.hs
module Data.IntegralLike (
IntegralLike (..)
) where
import Data.Char (ord)
-----------------------------------------------------------
class IntegralLike a where
asIntegral :: (Integral i) => a -> i
instance IntegralLike Bool where
asIntegral False = 0
asIntegral True = 1
instance IntegralLike Char where
asIntegral = fromIntegral . ord
instance IntegralLike Int where
asIntegral = fromIntegral
instance IntegralLike Integer where
asIntegral = fromInteger