Skip to content

Instantly share code, notes, and snippets.

@kseo
Created February 13, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kseo/099b679b6c9ae76acd7c to your computer and use it in GitHub Desktop.
Save kseo/099b679b6c9ae76acd7c to your computer and use it in GitHub Desktop.
An example of type family
{-# 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