Created
March 31, 2015 07:36
-
-
Save jroesch/53db23122aaa446ff0de to your computer and use it in GitHub Desktop.
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 MultiParamTypeClasses, FlexibleContexts, UndecidableInstances, FlexibleInstances, OverlappingInstances, FunctionalDependencies #-} | |
class Cast a b | a -> b where | |
to :: a -> b | |
data Point2 = Point2 Int Int | |
deriving (Show) | |
data Point3 = Point3 Int Int Int | |
instance Cast Point3 Point2 where | |
to (Point3 x y _) = Point2 x y | |
class ToString a where | |
toString :: a -> String | |
instance ToString Point2 where | |
toString = show | |
instance (Cast a Point2) => ToString a where | |
toString x = toString $ to x | |
instance ToString (Point3) where | |
toString x = "yolo" | |
foo :: (ToString a) => a -> String | |
foo x = (toString x) ++ "X"1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment