Cast a value of one type into a value of another. This is a configurable
function that allows you to define your own type-safe conversions for a
variety of types.
cast works with instances of Rep (Map i) o in which you choose the
input type i and the output type o and implement the function of type i
-> o.
Here are some examples of instances (and flags you will need or want):
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
instance Rep (Map Int) Char where
rep = Map chr
instance Rep (Map Float) Double where
rep = Map realToFrac
instance Rep (Map Integer) Integer where
rep = Map (+42)
There are no pre-defined instances, and a call to cast will not compile if
no instances for the input and output type pair is found, so you must define
instances in order to use cast.
|