{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

module Data.Castable where

import Data.Char (chr, ord)

class Castable a b where
    cast :: a -> b

instance Castable Int Char where
    cast = chr

instance Castable Char Int where
    cast = ord

instance Integral a => Castable a Integer where
    cast = toInteger

instance Fractional a => Castable Rational a where
    cast = fromRational

instance Num a => Castable Integer a where
    cast = fromInteger

instance (Real a, Fractional b) => Castable a b where
    cast = realToFrac
