Skip to content

Instantly share code, notes, and snippets.

@bryal
Created November 6, 2017 17:34
Show Gist options
  • Save bryal/545c4575a204790d964cb4fb67e19b48 to your computer and use it in GitHub Desktop.
Save bryal/545c4575a204790d964cb4fb67e19b48 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
class Add a b where
type Ret a b :: *
add :: a -> b -> Ret a b
instance Add Int Double where
type Ret Int Double = Double
add a b = (fromIntegral a) + b
instance Add Int Int where
type Ret Int Int = Integer
add a b = (toInteger a) + (toInteger b)
main = ((>>) (putStrLn (show (add (1 :: Int) (2 :: Int))))
(putStrLn (show (add (1 :: Int) (2 :: Double)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment