Created
February 13, 2016 03:23
-
-
Save kseo/099b679b6c9ae76acd7c to your computer and use it in GitHub Desktop.
An example of type family
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE TypeFamilies #-} | |
class Add a b where | |
type SumTy a b | |
add :: a -> b -> SumTy a b | |
instance Add Integer Double where | |
type SumTy Integer Double = Double | |
add x y = fromIntegral x + y | |
instance Add Double Integer where | |
type SumTy Double Integer = Double | |
add x y = x + fromIntegral y | |
instance (Num a) => Add a a where | |
type SumTy a a = a | |
add x y = x + y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment